From ef5161c2040fcd060da7d40bef83db8cf05da2f6 Mon Sep 17 00:00:00 2001 From: ryansurf Date: Sat, 25 May 2024 14:51:19 -0700 Subject: [PATCH] updated tests --- src/backend/main.py | 33 +++++++++++++++++++-------------- src/tests/test_code.py | 7 +------ 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/backend/main.py b/src/backend/main.py index e49f6f0..2b434c8 100644 --- a/src/backend/main.py +++ b/src/backend/main.py @@ -64,26 +64,32 @@ if "metric" in args or "m" in args: ocean["unit"] = "metric" -# Calls APIs though python files -ocean_data = api.ocean_information(lat, long, ocean["decimal"], ocean["unit"]) -uv_index = api.get_uv(lat, long, ocean["decimal"], ocean["unit"]) +def gather_data(lat=lat, long=long): + # Calls APIs though python files + ocean_data = api.ocean_information(lat, long, ocean["decimal"], ocean["unit"]) + uv_index = api.get_uv(lat, long, ocean["decimal"], ocean["unit"]) -ocean["ocean_data"] = ocean_data -ocean["uv_index"] = uv_index + ocean["ocean_data"] = ocean_data + ocean["uv_index"] = uv_index -data_dict = { - "Location : ": city, - "Height: ": ocean_data[0], - "Direction: ": ocean_data[1], - "Period: ": ocean_data[2], - "UV Index: ": uv_index, -} + data_dict = { + "Location : ": city, + "Height: ": ocean_data[0], + "Direction: ": ocean_data[1], + "Period: ": ocean_data[2], + "UV Index: ": uv_index, + } + return ocean_data, uv_index, data_dict -def main(): +def main(lat=lat, long=long): """ Main function """ + data = gather_data() + ocean_data = data[0] + uv_index = data[1] + data_dict = data[2] print("\n") if coordinates == "No data": print("No location found") @@ -99,5 +105,4 @@ def main(): helper.print_forecast(ocean, forecast) return data_dict - main() diff --git a/src/tests/test_code.py b/src/tests/test_code.py index 25fb650..ada990d 100644 --- a/src/tests/test_code.py +++ b/src/tests/test_code.py @@ -8,14 +8,9 @@ sys.path.append("../backend") -import unittest from unittest.mock import patch import io -import threading -import requests import time -import subprocess -import os from main import main from helper import extract_decimal from api import get_coordinates, get_uv, ocean_information @@ -61,6 +56,6 @@ def test_main(): Main() returns a dictionary of: location, height, period, etc. This functions checks if the dictionary is returned and is populated """ - data_dict = main() + data_dict = main(36.95, -122.02) time.sleep(5) assert len(data_dict) >= 5