From b9b205b8394fb6493a4d2a251db34e37fac5357e Mon Sep 17 00:00:00 2001 From: vedina Date: Sun, 25 Feb 2024 15:33:36 +0200 Subject: [PATCH] upload test --- pyproject.toml | 1 + tests/test_api_template.py | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f7a12b1..db65209 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,6 +39,7 @@ dev = "scripts.dev_server:main" pytest = "^8.0.1" httpx = "^0.27.0" uvicorn = "^0.27.1" +jupyter = "^1.0.0" [tool.pytest.ini_options] pythonpath = ["src"] diff --git a/tests/test_api_template.py b/tests/test_api_template.py index 76e031a..4b5cd01 100644 --- a/tests/test_api_template.py +++ b/tests/test_api_template.py @@ -1,10 +1,41 @@ from fastapi.testclient import TestClient import re from rcapi.main import app +from pathlib import Path +import json +import warnings + + +TEST_JSON_PATH = Path(__file__).parent / "resources/templates/dose_response.json" client = TestClient(app) +#warnings.warn("test") +#print("test") def test_template(): response = client.get("/template") assert response.status_code == 200 - assert response.json() == {"template" : []} \ No newline at end of file + assert response.json() == {"template" : []} + +def get_task_result(response_post): + assert response_post.status_code == 200, response_post.status_code + task_json = response_post.json() + result_uuid = task_json.get("result_uuid") + assert result_uuid is not None, task_json + return result_uuid + +def test_upload_and_retrieve_json(): + # Step 1: Upload JSON + json_content = {} + with open(TEST_JSON_PATH, "rb") as file: + json_content = json.load(file) + response_upload = client.post("/template", json=json_content) + result_uuid = get_task_result(response_upload) + # Step 2: Retrieve JSON using the result_uuid + response_retrieve = client.get(f"/template/{result_uuid}") + assert response_retrieve.status_code == 200, response_retrieve.status_code + retrieved_json = response_retrieve.json() + # Step 3: Compare uploaded and retrieved JSON + with open(TEST_JSON_PATH, "r") as file: + expected_json = json.load(file) + assert retrieved_json == expected_json \ No newline at end of file