Skip to content

Commit

Permalink
dl-v2 server test fix (#412)
Browse files Browse the repository at this point in the history
* fixed license tests

* fixed download tests

* fixed license tests

* updated name for missing config condition

* updated readme

* skipping dl-v2 tests in CI
  • Loading branch information
aniketsinghrawat authored Oct 27, 2023
1 parent 31b718d commit b809f86
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
run: python -m metview selfcheck
- name: Run unit tests
shell: bash -l {0}
run: pytest --memray
run: pytest --memray --ignore=weather_dl_v2 # Ignoring dl-v2 as it only supports py3.10
lint:
runs-on: ubuntu-latest
strategy:
Expand Down
2 changes: 2 additions & 0 deletions weather_dl_v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<!-- TODO: Create a setup script to ease deployment process. -->

> **_NOTE:_** weather-dl-v2 only supports python 3.10
### Sequence of steps:
1) Refer to downloader_kubernetes/README.md
2) Refer to license_deployment/README.md
Expand Down
10 changes: 6 additions & 4 deletions weather_dl_v2/fastapi-server/database/download_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,20 @@ async def _mark_partitioning_status(self, config_name: str, status: str) -> None
)

async def _check_download_exists(self, config_name: str) -> bool:
if config_name == "no_exist":
if config_name == "not_exist":
return False
elif config_name == "no_exist.cfg":
elif config_name == "not_exist.cfg":
return False
else:
return True

async def _get_downloads(self, client_name: str) -> list:
return [{"config_name": "example.cfg", "client_name": "client"}]
return [{"config_name": "example.cfg", "client_name": "client", "status": "partitioning completed."}]

async def _get_download_by_config_name(self, config_name: str):
return {"config_name": "example.cfg", "client_name": "client"}
if config_name == "not_exist":
return None
return {"config_name": "example.cfg", "client_name": "client", "status": "partitioning completed."}


class DownloadHandlerFirestore(DownloadHandler):
Expand Down
6 changes: 4 additions & 2 deletions weather_dl_v2/fastapi-server/database/license_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,15 @@ async def _update_license(self, license_id: str, license_dict: dict) -> None:
)

async def _check_license_exists(self, license_id: str) -> bool:
if license_id == "no_exists":
if license_id == "not_exist":
return False
elif license_id == "no-exists":
return False
else:
return True

async def _get_license_by_license_id(self, license_id: str) -> dict:
if license_id == "no_exists":
if license_id == "not_exist":
return None
return {
"license_id": license_id,
Expand Down
2 changes: 1 addition & 1 deletion weather_dl_v2/fastapi-server/database/queue_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async def _get_queues(self) -> list:
return [{"client_name": "dummy_client", "license_id": "L1", "queue": []}]

async def _get_queue_by_license_id(self, license_id: str) -> dict:
if license_id == "no_exists":
if license_id == "not_exist":
return None
return {"client_name": "dummy_client", "license_id": license_id, "queue": []}

Expand Down
4 changes: 2 additions & 2 deletions weather_dl_v2/fastapi-server/routers/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def get_fetch_config_stats():


def get_fetch_config_stats_mock():
def fetch_config_stats(
config_name: str, client_name: str, manifest_handler: ManifestHandler
async def fetch_config_stats(
config_name: str, client_name: str, status: str, manifest_handler: ManifestHandler
):
return {
"config_name": config_name,
Expand Down
4 changes: 2 additions & 2 deletions weather_dl_v2/fastapi-server/routers/license.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ async def create_deployment(license_id: str, license_handler: LicenseHandler):


def get_create_deployment_mock():
def create_deployment_mock(license_id: str, license_handler: LicenseHandler):
logger.info("create deployment mock.")
async def create_deployment_mock(license_id: str, license_handler: LicenseHandler):
logger.info("create deployment mock.")

return create_deployment_mock

Expand Down
13 changes: 6 additions & 7 deletions weather_dl_v2/fastapi-server/tests/integration/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ def test_submit_download_basic():
header = {
"accept": "application/json",
}
file_path = os.path.join(ROOT_DIR, "tests/test_data/no_exist.cfg")
file_path = os.path.join(ROOT_DIR, "tests/test_data/not_exist.cfg")
licenses = ["L1"]
code = 200
expected = {
"message": f"file 'no_exist.cfg' saved at '{os.getcwd()}/tests/test_data/no_exist.cfg' "
"message": f"file 'not_exist.cfg' saved at '{os.getcwd()}/tests/test_data/not_exist.cfg' "
"successfully."
}

Expand Down Expand Up @@ -141,16 +141,15 @@ def test_get_download_by_config_basic():

def test_get_download_by_config_wrong_config():
headers = {}
config_name = "no_exist"
config_name = "not_exist"
code = 404
expected = {"detail": "Download config not found in weather-dl v2."}
expected = {"detail": "Download config not_exist not found in weather-dl v2."}

_get_download_by_config(headers, config_name, code, expected)


def _delete_download_by_config(headers, config_name, code, expected):
response = client.delete(f"/download/{config_name}", headers=headers)

assert response.status_code == code
assert response.json() == expected

Expand All @@ -169,8 +168,8 @@ def test_delete_download_by_config_basic():

def test_delete_download_by_config_wrong_config():
headers = {}
config_name = "no_exist"
config_name = "not_exist"
code = 404
expected = {"detail": "No such download config to stop & remove."}
expected = {"detail": "No such download config not_exist to stop & remove."}

_delete_download_by_config(headers, config_name, code, expected)
23 changes: 13 additions & 10 deletions weather_dl_v2/fastapi-server/tests/integration/test_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,19 @@ def _add_license(headers, payload, code, expected):
params={"license_id": "L1"},
)

print(f"test add license {response.json()}")

assert response.status_code == code
assert response.json() == expected


def test_add_license_basic():
headers = {"accept": "application/json", "Content-Type": "application/json"}
license = {
"license_id": "no-exists",
"client_name": "dummy_client",
"number_of_requests": 0,
"secret_id": "xxxx",
"api_email": "email",
"k8s_deployment_id": "k1",
}
payload = license
code = 200
Expand Down Expand Up @@ -131,10 +132,10 @@ def test_get_license_by_license_id():

def test_get_license_wrong_license():
headers = {}
license_id = "no_exists"
license_id = "not_exist"
code = 404
expected = {
"detail": "License not found.",
"detail": "License not_exist not found.",
}

_get_license_by_license_id(headers, license_id, code, expected)
Expand All @@ -145,6 +146,8 @@ def _update_license(headers, license_id, license, code, expected):
f"/license/{license_id}", headers=headers, data=json.dumps(license)
)

print(f"_update license {response.json()}")

assert response.status_code == code
assert response.json() == expected

Expand All @@ -153,10 +156,10 @@ def test_update_license_basic():
headers = {}
license_id = "L1"
license = {
"license_id": "L1",
"client_name": "dummy_client",
"number_of_requests": 0,
"secret_id": "xxxx",
"api_email": "email",
}
code = 200
expected = {"license_id": license_id, "name": "License updated successfully."}
Expand All @@ -166,15 +169,15 @@ def test_update_license_basic():

def test_update_license_wrong_license_id():
headers = {}
license_id = "no_exists"
license_id = "no-exists"
license = {
"license_id": "no-exists",
"client_name": "dummy_client",
"number_of_requests": 0,
"secret_id": "xxxx",
"api_email": "email",
}
code = 404
expected = {"detail": "No such license to update."}
expected = {"detail": "No such license no-exists to update."}

_update_license(headers, license_id, license, code, expected)

Expand All @@ -197,8 +200,8 @@ def test_delete_license_basic():

def test_delete_license_wrong_license():
headers = {}
license_id = "no_exists"
license_id = "not_exist"
code = 404
expected = {"detail": "No such license to delete."}
expected = {"detail": "No such license not_exist to delete."}

_delete_license(headers, license_id, code, expected)
18 changes: 9 additions & 9 deletions weather_dl_v2/fastapi-server/tests/integration/test_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ def test_get_queue_by_license_basic():

def test_get_queue_by_license_wrong_license():
headers = {}
license_id = "no_exists"
license_id = "not_exist"
code = 404
expected = {"detail": "License's priority not found."}
expected = {"detail": 'License priority for not_exist not found.'}

_get_queue_by_license(headers, license_id, code, expected)

Expand All @@ -99,10 +99,10 @@ def test_modify_license_queue_basic():

def test_modify_license_queue_wrong_license_id():
headers = {}
license_id = "no_exists"
license_id = "not_exist"
priority_list = []
code = 404
expected = {"detail": "License's priority not found."}
expected = {"detail": 'License not_exist not found.'}

_modify_license_queue(headers, license_id, priority_list, code, expected)

Expand All @@ -122,27 +122,27 @@ def test_modify_config_priority_in_license_basic():
query = {"config_name": "example.cfg", "priority": 0}
code = 200
expected = {
"message": f"'{license_id}' license 'example.cfg' priority updated successfully."
"message": f"'{license_id}' license -- 'example.cfg' priority updated successfully."
}

_modify_config_priority_in_license(headers, license_id, query, code, expected)


def test_modify_config_priority_in_license_wrong_license():
headers = {}
license_id = "no_exists"
license_id = "not_exist"
query = {"config_name": "example.cfg", "priority": 0}
code = 404
expected = {"detail": "License's priority not found."}
expected = {"detail": 'License not_exist not found.'}

_modify_config_priority_in_license(headers, license_id, query, code, expected)


def test_modify_config_priority_in_license_wrong_config():
headers = {}
license_id = "no_exists"
license_id = "not_exist"
query = {"config_name": "wrong.cfg", "priority": 0}
code = 404
expected = {"detail": "License's priority not found."}
expected = {"detail": 'License not_exist not found.'}

_modify_config_priority_in_license(headers, license_id, query, code, expected)

0 comments on commit b809f86

Please sign in to comment.