Skip to content

Commit

Permalink
test/client: simplify query handling
Browse files Browse the repository at this point in the history
Use requests `params` optional argument instead of encoding it
directly in the URL.
  • Loading branch information
msune committed Jun 14, 2024
1 parent 9376293 commit 74e77c6
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions test/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import json
import requests
import argparse
from urllib.parse import urlencode

DEFAULT_HOST = "127.0.0.1"
DEFAULT_PORT = 8080
Expand Down Expand Up @@ -34,18 +33,17 @@ def delete_dashboard(host, port, dashboard_id) -> requests.Response:


def get_dashboard(host, port, dashboard_id=None, shortName=None, dataCube=None) -> requests.Response:
params = None
url = f"http://{host}:{port}/{DEFAULT_PATH}"
if dashboard_id:
url = f"http://{host}:{port}/{DEFAULT_PATH}/{dashboard_id}"
url = f"{url}/{dashboard_id}"
else:
query = {}
params = {}
if shortName:
query["shortName"] = shortName
params["shortName"] = shortName
if dataCube:
query["dataCube"] = dataCube
query_str = urlencode(query)
query_str = "?" + query_str if query_str != "" else ""
url = f"http://{host}:{port}/{DEFAULT_PATH}{query_str}"
response = requests.get(url)
params["dataCube"] = dataCube
response = requests.get(url, params=params)
print_response(response)
return response

Expand Down

0 comments on commit 74e77c6

Please sign in to comment.