diff --git a/src/backend/helper.py b/src/backend/helper.py index 2f49e47..10e0f2a 100644 --- a/src/backend/helper.py +++ b/src/backend/helper.py @@ -2,6 +2,12 @@ General helper functions """ +def query_to_args_list(query): + """ + Convert query string to a list of arguments. + """ + args = [query] if query else [] + return args def seperate_args(args): """ diff --git a/src/backend/server.py b/src/backend/server.py index 0357d70..0ad9605 100644 --- a/src/backend/server.py +++ b/src/backend/server.py @@ -7,6 +7,7 @@ import subprocess from urllib.parse import urlparse, parse_qs from dotenv import load_dotenv +from helper import query_to_args_list # Load environment variables from .env file load_dotenv(override=True) @@ -29,10 +30,9 @@ def do_GET(self): """ # Parse the query parameters parsed_url = urlparse(self.path) - query_params = parse_qs(parsed_url.query) # Extract the arguments from the query parameters - args = query_params.get("args", []) + args = query_to_args_list(parsed_url.query) if "help" in args: # If 'help' is in the args, read and return the content of help.txt diff --git a/src/tests/test_code.py b/src/tests/test_code.py index 074bc82..489400e 100644 --- a/src/tests/test_code.py +++ b/src/tests/test_code.py @@ -13,10 +13,26 @@ import io import time from main import main -from helper import extract_decimal +from helper import extract_decimal, query_to_args_list from api import get_coordinates, get_uv, ocean_information +def test_query_to_args_list_with_non_empty_params(): + """ + Test if query_to_args_list function correctly converts non-empty query parameters to a list. + """ + args = query_to_args_list("location=new_york,hide_height,show_large_wave") + assert args == ["location=new_york,hide_height,show_large_wave"] + + +def test_query_to_args_list_with_empty_params(): + """ + Test if query_to_args_list function correctly handles empty query parameters and returns an empty list. + """ + args = query_to_args_list("") + assert args == [] + + def test_invalid_input(): """ Test if decimal input prints proper invalid input message