Skip to content

Commit

Permalink
upload test
Browse files Browse the repository at this point in the history
  • Loading branch information
vedina committed Feb 25, 2024
1 parent f144fa2 commit b9b205b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
33 changes: 32 additions & 1 deletion tests/test_api_template.py
Original file line number Diff line number Diff line change
@@ -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" : []}
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

0 comments on commit b9b205b

Please sign in to comment.