From 540b6857937c3bbaff26890e8ec449d177cc0618 Mon Sep 17 00:00:00 2001 From: ryansurf Date: Fri, 31 May 2024 14:53:02 -0700 Subject: [PATCH] Formatting --- src/cli.py | 4 +++- tests/test_api.py | 47 +++++++++++++++++++++++++++++++++++++++++++- tests/test_cli.py | 2 +- tests/test_server.py | 5 +++++ 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/cli.py b/src/cli.py index dc73748..191fb91 100644 --- a/src/cli.py +++ b/src/cli.py @@ -44,9 +44,11 @@ def run(lat=0, long=0): helper.print_outputs( city, ocean_data_dict, arguments, gpt_prompt, gpt_info ) + return ocean_data_dict else: # print the output in json format! - helper.json_output(ocean_data_dict) + json_output = helper.json_output(ocean_data_dict) + return json_output if __name__ == "__main__": diff --git a/tests/test_api.py b/tests/test_api.py index 466a30d..0c1524a 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -4,7 +4,15 @@ Run pytest: pytest """ -from src.api import get_coordinates, get_uv, ocean_information +from src.api import ( + forecast, + gather_data, + get_coordinates, + get_uv, + ocean_information, + seperate_args_and_get_location, +) +from src.helper import arguments_dictionary def test_get_coordinates(): @@ -25,3 +33,40 @@ def test_ocean_information(): assert isinstance(ocean[0], (int, float)) assert isinstance(ocean[1], (int, float)) assert isinstance(ocean[2], (int, float)) + + +def test_forecast(): + """ + Test forecast() at an arbitrary location(palm beach), + ensures it returns 7 days of heights/directions/periods + """ + len_of_forecast_list = 7 + fc = forecast(26.705, -80.036, 1, 7) + heights, directions, periods = fc[0], fc[1], fc[2] + assert len(heights) == len_of_forecast_list + assert len(directions) == len_of_forecast_list + assert len(periods) == len_of_forecast_list + + +def test_gather_data(): + """ + Gather data needs the arguments dictionary as input, + so we will get this by calling arguments_dictionary() + from helper.py with arbitrary arguments + """ + lat = 33.37 + long = -117.57 + arguments = arguments_dictionary(lat, long, "San Clemente", []) + ocean_data_dict = gather_data(lat, long, arguments) + assert ocean_data_dict["Location"] == "San Clemente" + assert ocean_data_dict["Lat"] == lat + assert ocean_data_dict["Long"] == long + + +def test_seperate_args_and_get_location(): + """ + Test with an abritrary location + """ + location = ["location=pleasure_point_california"] + location_data = seperate_args_and_get_location(location) + assert "Santa Cruz County" in location_data["city"][0] diff --git a/tests/test_cli.py b/tests/test_cli.py index 5cffd56..867d289 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -14,10 +14,10 @@ def test_cli_output(): Main() returns a dictionary of: location, height, period, etc. This functions checks if the dictionary is returned and is populated """ + expected = 5 # Hardcode lat and long for location. # If not, when test are ran in Github Actions # We get an error(because server probably isn't near ocean) - expected = 5 data_dict = cli.run(36.95, -121.97) time.sleep(5) assert len(data_dict) >= expected diff --git a/tests/test_server.py b/tests/test_server.py index e69de29..b61c3aa 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -0,0 +1,5 @@ +""" +QA tests for server.py +Make sure pytest is installed: pip install pytest +Run pytest: pytest +"""