Skip to content

Commit

Permalink
test(outputs): improve unit test test_outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent-laporte-pro committed Mar 25, 2024
1 parent 07cf7ca commit 70dc017
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions tests/integration/variant_blueprint/test_variant_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,65 +243,77 @@ def test_comments(client: TestClient, admin_access_token: str, variant_id: str)
assert res.json() == comment


def test_recursive_variant_tree(client: TestClient, admin_access_token: str):
def test_recursive_variant_tree(client: TestClient, admin_access_token: str, base_study_id: str) -> None:
admin_headers = {"Authorization": f"Bearer {admin_access_token}"}
base_study_res = client.post("/v1/studies?name=foo", headers=admin_headers)
base_study_id = base_study_res.json()
parent_id = base_study_res.json()
for k in range(150):
res = client.post(f"/v1/studies/{base_study_id}/variants?name=variant_{k}", headers=admin_headers)
parent_id = base_study_id
for k in range(200):
res = client.post(
f"/v1/studies/{base_study_id}/variants",
headers=admin_headers,
params={"name": f"variant_{k}"},
)
base_study_id = res.json()

# Asserts that we do not trigger a Recursive Exception
res = client.get(f"/v1/studies/{parent_id}/variants", headers=admin_headers)
assert res.status_code == 200
assert res.status_code == 200, res.json()


def test_outputs(client: TestClient, admin_access_token: str, tmp_path: str) -> None:
def test_outputs(client: TestClient, admin_access_token: str, variant_id: str, tmp_path: str) -> None:
# =======================
# SET UP
# =======================

admin_headers = {"Authorization": f"Bearer {admin_access_token}"}
res = client.post(f"/v1/studies?name=foo", headers=admin_headers)
parent_id = res.json()
res = client.post(f"/v1/studies/{parent_id}/variants?name=variant_foo", headers=admin_headers)
variant_id = res.json()

# Only done to generate the variant folder
res = client.post(f"/v1/launcher/run/{variant_id}", headers=admin_headers)
res.raise_for_status()
job_id = res.json()["job_id"]

status = client.get(f"/v1/launcher/jobs/{job_id}", headers=admin_headers).json()["status"]
while status != "failed":
time.sleep(0.2)
status = client.get(f"/v1/launcher/jobs/{job_id}", headers=admin_headers).json()["status"]

# Import an output to the study folder
output_path_zip = ASSETS_DIR / "output_adq.zip"
client.post(
res = client.post(
f"/v1/studies/{variant_id}/output",
headers=admin_headers,
files={"output": io.BytesIO(output_path_zip.read_bytes())},
)
res.raise_for_status()

# =======================
# ASSERTS GENERATING THE VARIANT DOES NOT `HIDE` OUTPUTS FROM THE ENDPOINT
# =======================

# Get output
res = client.get(f"/v1/studies/{variant_id}/outputs", headers=admin_headers).json()
assert len(res) == 1
res = client.get(f"/v1/studies/{variant_id}/outputs", headers=admin_headers)
assert res.status_code == 200, res.json()
outputs = res.json()
assert len(outputs) == 1

# Generates the study
res = client.put(f"/v1/studies/{variant_id}/generate?denormalize=false&from_scratch=true", headers=admin_headers)
res = client.put(
f"/v1/studies/{variant_id}/generate",
headers=admin_headers,
params={"denormalize": False, "from_scratch": True},
)
res.raise_for_status()
task_id = res.json()

# Wait for task completion
res = client.get(f"/v1/tasks/{task_id}", headers=admin_headers, params={"wait_for_completion": True})
assert res.status_code == 200
res.raise_for_status()
task_result = TaskDTO.parse_obj(res.json())
assert task_result.status == TaskStatus.COMPLETED
assert task_result.result is not None
assert task_result.result.success

# Get outputs again
res = client.get(f"/v1/studies/{variant_id}/outputs", headers=admin_headers).json()
assert len(res) == 1
res = client.get(f"/v1/studies/{variant_id}/outputs", headers=admin_headers)
assert res.status_code == 200, res.json()
outputs = res.json()
assert len(outputs) == 1

0 comments on commit 70dc017

Please sign in to comment.