diff --git a/tests/unit/test_letter_one_day.py b/tests/unit/test_letter_one_day.py new file mode 100644 index 0000000..53ad395 --- /dev/null +++ b/tests/unit/test_letter_one_day.py @@ -0,0 +1,26 @@ +import unittest +import sys +import os + +# Add the src folder to the Python path +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../src'))) + +from my_package.fetch_current_data import fetch_current_data + +class TestCityNameCase(unittest.TestCase): + + def test_city_name_case_insensitive(self): + # Test city with big and small letter + city_name_upper = "Oslo" + city_name_lower = "oslo" + + # Test if they return the same, the underscore is for the folder that we dont use here + data_upper, _ = fetch_current_data(city_name_upper) + data_lower, _ = fetch_current_data(city_name_lower) + + # use temperature as an example to see if data is identical + self.assertEqual(data_upper["main"]["temp"], data_lower["main"]["temp"]) + +if __name__ == "__main__": + unittest.main() + diff --git a/tests/unit/test_one_day.py b/tests/unit/test_one_day.py new file mode 100644 index 0000000..ad6e05c --- /dev/null +++ b/tests/unit/test_one_day.py @@ -0,0 +1,39 @@ +import unittest +import sys +import os +from datetime import datetime +from src.my_package.date_to_unix import from_unix_timestamp + +# This will make the absolute path from the root of the project, and will therefor work every time +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../../src"))) + + +class TestGetUnixTimestamp(unittest.TestCase): + + def test_get_unix_timestamp(self): + # Example user input for start and end date + start_date_input = "2000, 03, 05, 11, 00" + end_date_input = "2000, 03, 05, 13, 00" + + # Convert input string to datetime object + start_date = datetime.strptime(start_date_input, "%Y, %m, %d, %H, %M") + end_date = datetime.strptime(end_date_input, "%Y, %m, %d, %H, %M") + + # Get the Unix timestamp by calling .timestamp() + expected_unix_start = int(start_date.timestamp()) + expected_unix_end = int(end_date.timestamp()) + + # Call the function directly with test data + function_unix_start, function_unix_end = from_unix_timestamp(expected_unix_start, expected_unix_end) + + # Assert that the returned timestamps are correct + self.assertEqual(function_unix_start, start_date) + self.assertEqual(function_unix_end, end_date) + + +if __name__ == "__main__": + unittest.main() + + +#this test is to test if the code date matches its timestamp +