Skip to content

Commit

Permalink
test case update
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansurf committed May 27, 2024
1 parent 9910f9c commit a80aa5b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
7 changes: 7 additions & 0 deletions src/backend/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,10 @@ def print_outputs(lat, long, coordinates, ocean_data, arguments):
forecast = api.forecast(lat, long, arguments["decimal"], arguments["forecast_days"])
print_forecast(arguments, forecast)

def set_location(location):
"""
Sets locations variables
"""
coordinates, city = location["coordinates"], location["city"]
lat, long = location["lat"], location["long"]
return coordinates, city, lat, long
37 changes: 21 additions & 16 deletions src/backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,29 @@
from dotenv import load_dotenv
from helper import arguments_dictionary

#Seperates the cli args into a list
args = helper.seperate_args(sys.argv)

# return coordinates, lat, long, city
location = api.seperate_args_and_get_location(args)
coordinates, city = location["coordinates"], location["city"]
lat, long = location["lat"], location["long"]

#Sets ocean = dictionary with
arguments = helper.arguments_dictionary(lat, long, city, args)
#Updates the ocean dict with the valeus from the arguments
arguements = helper.set_output_values(args, arguments)


def main(lat, long):
def main(lat=0, long=0):
"""
Main function
"""
#Seperates the cli args into a list
args = helper.seperate_args(sys.argv)

# return coordinates, lat, long, city
location = api.seperate_args_and_get_location(args)

set_location = helper.set_location(location)
coordinates, city = set_location[0], set_location[1]

# Check if lat and long are set to defaults(no argumentes passed in main())
if lat == 0 and long == 0:
lat, long = set_location[2], set_location[3]

#Sets ocean = dictionary with
arguments = helper.arguments_dictionary(lat, long, city, args)
#Updates the ocean dict with the valeus from the arguments
arguments = helper.set_output_values(args, arguments)

lat = float(lat)
long = float(long)
# Makes calls to the apis(ocean, UV) and returns the values
Expand All @@ -46,5 +51,5 @@ def main(lat, long):
json_output = helper.json_output(data_dict)
return json_output

main(lat, long)

if __name__ == "__main__":
main()
5 changes: 4 additions & 1 deletion src/tests/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ def test_main_output():
Main() returns a dictionary of: location, height, period, etc.
This functions checks if the dictionary is returned and is populated
"""
data_dict = main(36.95, -122.02)
#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)
data_dict = main(36.95, -121.97)
print(data_dict)
time.sleep(5)
assert len(data_dict) >= 5

0 comments on commit a80aa5b

Please sign in to comment.