-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from ssciwr/fix_20_store_job_info
Store job information
- Loading branch information
Showing
10 changed files
with
267 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ def add_test_users(app): | |
email = f"{name}@abc.xy" | ||
db.session.add( | ||
User( | ||
id=None, | ||
email=email, | ||
password_hash=ph.hash(name), | ||
activated=True, | ||
|
@@ -46,6 +47,7 @@ def add_test_samples(app, data_path: pathlib.Path): | |
with open(f"{ref_dir}/input.{input_file_type}", "w") as f: | ||
f.write(input_file_type) | ||
new_sample = Sample( | ||
id=None, | ||
email="[email protected]", | ||
name=name, | ||
tumor_type=f"tumor_type{sample_id}", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,12 +210,13 @@ def test_result_invalid(client): | |
assert "No results available" in response.json["message"] | ||
|
||
|
||
def _upload_result(client, result_zipfile: pathlib.Path, sample_id: int): | ||
def _upload_result(client, result_zipfile: pathlib.Path, job_id: int, sample_id: int): | ||
headers = _get_auth_headers(client, "[email protected]", "runner") | ||
with open(result_zipfile, "rb") as f: | ||
response = client.post( | ||
"/api/runner/result", | ||
data={ | ||
"job_id": job_id, | ||
"sample_id": sample_id, | ||
"success": True, | ||
"file": (io.BytesIO(f.read()), result_zipfile.name), | ||
|
@@ -225,19 +226,57 @@ def _upload_result(client, result_zipfile: pathlib.Path, sample_id: int): | |
return response | ||
|
||
|
||
def test_result_valid(client, result_zipfile): | ||
headers = _get_auth_headers(client, "[email protected]", "user") | ||
sample_id = 1 | ||
assert _upload_result(client, result_zipfile, sample_id).status_code == 200 | ||
def test_runner_valid_success(client, result_zipfile): | ||
headers = _get_auth_headers(client, "[email protected]", "runner") | ||
# request job | ||
request_job_response = client.post( | ||
"/api/runner/request_job", | ||
json={"runner_hostname": "me"}, | ||
headers=headers, | ||
) | ||
assert request_job_response.status_code == 200 | ||
assert request_job_response.json == {"sample_id": 1, "job_id": 1} | ||
# upload successful result | ||
assert _upload_result(client, result_zipfile, 1, 1).status_code == 200 | ||
response = client.post( | ||
"/api/result", | ||
json={"sample_id": sample_id}, | ||
headers=headers, | ||
json={"sample_id": 1}, | ||
headers=_get_auth_headers(client, "[email protected]", "user"), | ||
) | ||
assert response.status_code == 200 | ||
assert len(response.data) > 1 | ||
|
||
|
||
def test_runner_valid_failure(client, result_zipfile): | ||
headers = _get_auth_headers(client, "[email protected]", "runner") | ||
# request job | ||
request_job_response = client.post( | ||
"/api/runner/request_job", | ||
json={"runner_hostname": "me"}, | ||
headers=headers, | ||
) | ||
assert request_job_response.status_code == 200 | ||
assert request_job_response.json == {"sample_id": 1, "job_id": 1} | ||
# upload failure result | ||
result_response = client.post( | ||
"/api/runner/result", | ||
data={ | ||
"job_id": 1, | ||
"sample_id": 1, | ||
"success": False, | ||
"error_message": "Something went wrong", | ||
}, | ||
headers=headers, | ||
) | ||
assert result_response.status_code == 200 | ||
response = client.post( | ||
"/api/result", | ||
json={"sample_id": 1}, | ||
headers=_get_auth_headers(client, "[email protected]", "user"), | ||
) | ||
assert response.status_code == 400 | ||
|
||
|
||
def test_admin_samples_valid(client): | ||
headers = _get_auth_headers(client, "[email protected]", "admin") | ||
response = client.get("/api/admin/samples", headers=headers) | ||
|
@@ -288,12 +327,6 @@ def test_admin_users_valid(client): | |
assert "users" in response.json | ||
|
||
|
||
def test_runner_result_valid(client, result_zipfile): | ||
response = _upload_result(client, result_zipfile, 1) | ||
assert response.status_code == 200 | ||
assert "result processed" in response.json["message"].lower() | ||
|
||
|
||
def test_admin_update_user_valid(client): | ||
headers = _get_auth_headers(client, "[email protected]", "admin") | ||
user = client.get("/api/admin/users", headers=headers).json["users"][0] | ||
|
Oops, something went wrong.