Skip to content

Commit

Permalink
Merge pull request #14 from K-dash/feature/remove-args-prefix
Browse files Browse the repository at this point in the history
Change: remove `args=` parameter
  • Loading branch information
ryansurf authored May 26, 2024
2 parents 5025633 + dc6075a commit f355e89
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/backend/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
4 changes: 2 additions & 2 deletions src/backend/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
18 changes: 17 additions & 1 deletion src/tests/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f355e89

Please sign in to comment.