Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test_integration.py #351

Merged
merged 7 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
234 changes: 104 additions & 130 deletions etc/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,14 @@ def assert_datasets_should_not_exist(datasets):
If any of the dataset names is found, the assertion will fail.
"""
response = requests.get(
f"{ENV['CANDIG_URL']}/katsu/v2/discovery/donors/", headers=get_headers()
f"{ENV['CANDIG_URL']}/katsu/v2/discovery/programs/", headers=get_headers()
)
data = response.json()
dataset_names = list(data["discovery_donor"].keys())
dataset_names = data["cohort_list"]

assert all(
dataset_name not in dataset_names for dataset_name in datasets
), f"Expected none of {datasets} to exist, but at least one was found."
), f"Expected none of {datasets} to exist, but at least one was found. Attempt to clean up. Please run the test again"


def ingest_data(endpoint, data, is_admin=False):
Expand Down Expand Up @@ -297,7 +297,7 @@ def perform_ingest_and_assert_status(endpoint, data, is_admin=False):
Performs data ingest and asserts the response status code depend on permission
"""
response = ingest_data(endpoint, data, is_admin)
expected_status = HTTPStatus.CREATED if is_admin else HTTPStatus.FORBIDDEN
expected_status = HTTPStatus.CREATED if is_admin else HTTPStatus.UNAUTHORIZED
assert_ingest_response_status(response, expected_status, endpoint)


Expand All @@ -306,7 +306,7 @@ def clean_up_program(test_id):
Deletes a dataset and all related objects. Expected 204
"""
delete_response = requests.delete(
f"{ENV['CANDIG_URL']}/katsu/v2/authorized/programs/{test_id}/",
f"{ENV['CANDIG_URL']}/katsu/v2/authorized/program/{test_id}/",
headers=get_headers(is_admin=True),
)
assert (
Expand All @@ -316,180 +316,152 @@ def clean_up_program(test_id):


def check_program_ingest(test_id, is_admin=False):
endpoint = "programs"
data = [{"program_id": test_id}]
endpoint = "program"
data = {"program_id": test_id}
perform_ingest_and_assert_status(endpoint, data, is_admin)


def check_donor_ingest(test_id, is_admin=False):
endpoint = "donors"
data = [
{
"submitter_donor_id": test_id,
"program_id": test_id,
},
]
endpoint = "donor"
data = {
"submitter_donor_id": test_id,
"program_id": test_id,
}
perform_ingest_and_assert_status(endpoint, data, is_admin)


def check_diagnosis_ingest(test_id, is_admin=False):
endpoint = "primary_diagnoses"
data = [
{
"submitter_donor_id": test_id,
"program_id": test_id,
"submitter_primary_diagnosis_id": test_id,
},
]
endpoint = "primary_diagnosis"
data = {
"submitter_donor_id": test_id,
"program_id": test_id,
"submitter_primary_diagnosis_id": test_id,
}
perform_ingest_and_assert_status(endpoint, data, is_admin)


def check_specimen_ingest(test_id, is_admin=False):
endpoint = "specimens"
data = [
{
"submitter_donor_id": test_id,
"program_id": test_id,
"submitter_primary_diagnosis_id": test_id,
"submitter_specimen_id": test_id,
},
]
endpoint = "specimen"
data = {
"submitter_donor_id": test_id,
"program_id": test_id,
"submitter_primary_diagnosis_id": test_id,
"submitter_specimen_id": test_id,
}
perform_ingest_and_assert_status(endpoint, data, is_admin)


def check_sample_ingest(test_id, is_admin=False):
endpoint = "sample_registrations"
data = [
{
"submitter_donor_id": test_id,
"program_id": test_id,
"submitter_specimen_id": test_id,
"submitter_sample_id": test_id,
},
]
endpoint = "sample_registration"
data = {
"submitter_donor_id": test_id,
"program_id": test_id,
"submitter_specimen_id": test_id,
"submitter_sample_id": test_id,
}
perform_ingest_and_assert_status(endpoint, data, is_admin)


def check_treatment_ingest(test_id, is_admin=False):
endpoint = "treatments"
data = [
{
"submitter_donor_id": test_id,
"program_id": test_id,
"submitter_primary_diagnosis_id": test_id,
"submitter_treatment_id": test_id,
},
]
endpoint = "treatment"
data = {
"submitter_donor_id": test_id,
"program_id": test_id,
"submitter_primary_diagnosis_id": test_id,
"submitter_treatment_id": test_id,
}
perform_ingest_and_assert_status(endpoint, data, is_admin)


def check_chemotherapy_ingest(test_id, is_admin=False):
endpoint = "chemotherapies"
data = [
{
"submitter_donor_id": test_id,
"program_id": test_id,
"submitter_treatment_id": test_id,
},
]
endpoint = "chemotherapy"
data = {
"submitter_donor_id": test_id,
"program_id": test_id,
"submitter_treatment_id": test_id,
}
perform_ingest_and_assert_status(endpoint, data, is_admin)


def check_radiation_ingest(test_id, is_admin=False):
endpoint = "radiations"
data = [
{
"submitter_donor_id": test_id,
"program_id": test_id,
"submitter_treatment_id": test_id,
},
]
endpoint = "radiation"
data = {
"submitter_donor_id": test_id,
"program_id": test_id,
"submitter_treatment_id": test_id,
}
perform_ingest_and_assert_status(endpoint, data, is_admin)


def check_hormonetherapy_ingest(test_id, is_admin=False):
endpoint = "hormone_therapies"
data = [
{
"submitter_donor_id": test_id,
"program_id": test_id,
"submitter_treatment_id": test_id,
},
]
endpoint = "hormone_therapy"
data = {
"submitter_donor_id": test_id,
"program_id": test_id,
"submitter_treatment_id": test_id,
}
perform_ingest_and_assert_status(endpoint, data, is_admin)


def check_immunotherapy_ingest(test_id, is_admin=False):
endpoint = "immunotherapies"
data = [
{
"submitter_donor_id": test_id,
"program_id": test_id,
"submitter_treatment_id": test_id,
},
]
endpoint = "immunotherapy"
data = {
"submitter_donor_id": test_id,
"program_id": test_id,
"submitter_treatment_id": test_id,
}
perform_ingest_and_assert_status(endpoint, data, is_admin)


def check_surgery_ingest(test_id, is_admin=False):
endpoint = "surgeries"
data = [
{
"submitter_donor_id": test_id,
"program_id": test_id,
"submitter_treatment_id": test_id,
"margin_types_involved": [],
"margin_types_not_involved": [],
"margin_types_not_assessed": [],
},
]
endpoint = "surgery"
data = {
"submitter_donor_id": test_id,
"program_id": test_id,
"submitter_treatment_id": test_id,
"margin_types_involved": [],
"margin_types_not_involved": [],
"margin_types_not_assessed": [],
}
perform_ingest_and_assert_status(endpoint, data, is_admin)


def check_follow_up_ingest(test_id, is_admin=False):
endpoint = "follow_ups"
data = [
{
"submitter_donor_id": test_id,
"program_id": test_id,
"submitter_primary_diagnosis_id": test_id,
"submitter_treatment_id": test_id,
"submitter_follow_up_id": test_id,
},
]
endpoint = "follow_up"
data = {
"submitter_donor_id": test_id,
"program_id": test_id,
"submitter_primary_diagnosis_id": test_id,
"submitter_treatment_id": test_id,
"submitter_follow_up_id": test_id,
}
perform_ingest_and_assert_status(endpoint, data, is_admin)


def check_biomarker_ingest(test_id, is_admin=False):
endpoint = "biomarkers"
data = [
{
"submitter_donor_id": test_id,
"program_id": test_id,
},
]
endpoint = "biomarker"
data = {
"submitter_donor_id": test_id,
"program_id": test_id,
}
perform_ingest_and_assert_status(endpoint, data, is_admin)


def check_comorbidity_ingest(test_id, is_admin=False):
endpoint = "comorbidities"
data = [
{
"submitter_donor_id": test_id,
"program_id": test_id,
},
]
endpoint = "comorbidity"
data = {
"submitter_donor_id": test_id,
"program_id": test_id,
}
perform_ingest_and_assert_status(endpoint, data, is_admin)


def check_exposure_ingest(test_id, is_admin=False):
endpoint = "exposures"
data = [
{
"submitter_donor_id": test_id,
"program_id": test_id,
},
]
endpoint = "exposure"
data = {
"submitter_donor_id": test_id,
"program_id": test_id,
}
perform_ingest_and_assert_status(endpoint, data, is_admin)


Expand All @@ -501,7 +473,7 @@ def check_datasets_access(is_admin, authorized_datasets, unauthorized_datasets):
f"{ENV['CANDIG_URL']}/katsu/v2/authorized/programs/",
headers=get_headers(is_admin=is_admin),
)
programs = list(map(lambda x: x["program_id"], response.json()["results"]))
programs = list(map(lambda x: x["program_id"], response.json()["items"]))

# Assert that all authorized datasets are present in programs
assert all(
Expand Down Expand Up @@ -579,7 +551,7 @@ def test_unauthorized_ingests():
- Attempt to clean up after in case any ingests go through but expected None

Expected result:
- HTTP 403 even with valid ingest data.
- HTTP 401 even with valid ingest data.
"""
# to simplify the test data, only 1 unique id is needed
test_id = "TEST-" + str(uuid.uuid4())
Expand Down Expand Up @@ -637,10 +609,12 @@ def test_katsu_users_data_access():
assert_datasets_should_not_exist(synthetic_datasets)

# create synthetic datasets that matches OPA access
endpoint = "programs"
program_data = [{"program_id": dataset_id} for dataset_id in synthetic_datasets]
response = ingest_data(endpoint, program_data, is_admin=True)
assert response.status_code == HTTPStatus.CREATED, "Failed to create programs."
endpoint = "program"
program_data_list = [{"program_id": dataset_id} for dataset_id in synthetic_datasets]
for program_data in program_data_list:
response = ingest_data(endpoint, program_data, is_admin=True)
assert response.status_code == HTTPStatus.CREATED, "Failed to create program."


# Assert access for admin user
check_datasets_access(
Expand Down Expand Up @@ -680,7 +654,7 @@ def test_ingest_permissions():

response = requests.post(f"{ENV['CANDIG_URL']}/ingest/clinical", headers=headers, json=test_data)
# when the user has no admin access, they should not be allowed
assert response.status_code == 403
assert response.status_code == 401

token = get_token(
username=ENV["CANDIG_SITE_ADMIN_USER"],
Expand Down
2 changes: 1 addition & 1 deletion lib/candig-ingest/candigv2-ingest
2 changes: 1 addition & 1 deletion lib/katsu/katsu_service
Submodule katsu_service updated 60 files
+42 −0 .github/commitFile.js
+2 −2 .github/workflows/lint.yml
+2 −2 .github/workflows/test.yml
+45 −75 .github/workflows/update-schema.yaml
+1 −1 README.md
+0 −321 chord_metadata_service/mohpackets/api_authorized.py
+0 −190 chord_metadata_service/mohpackets/api_base.py
+0 −512 chord_metadata_service/mohpackets/api_discovery.py
+0 −452 chord_metadata_service/mohpackets/api_ingest.py
+339 −0 chord_metadata_service/mohpackets/apis/clinical_data.py
+154 −0 chord_metadata_service/mohpackets/apis/core.py
+352 −0 chord_metadata_service/mohpackets/apis/discovery.py
+150 −0 chord_metadata_service/mohpackets/apis/ingestion.py
+3 −0 chord_metadata_service/mohpackets/apps.py
+0 −71 chord_metadata_service/mohpackets/authentication.py
+5 −19 chord_metadata_service/mohpackets/data/README.md
+0 −40 chord_metadata_service/mohpackets/data/data_converter.py
+119 −0 chord_metadata_service/mohpackets/data/data_loader.py
+9 −4 chord_metadata_service/mohpackets/docs/README.MD
+0 −11,529 chord_metadata_service/mohpackets/docs/openapi.md
+14,779 −0 chord_metadata_service/mohpackets/docs/schema.json
+18,510 −0 chord_metadata_service/mohpackets/docs/schema.md
+8,121 −6,733 chord_metadata_service/mohpackets/docs/schema.yml
+0 −249 chord_metadata_service/mohpackets/filters.py
+122 −82 chord_metadata_service/mohpackets/migrations/0001_initial.py
+151 −105 chord_metadata_service/mohpackets/models.py
+46 −9 chord_metadata_service/mohpackets/pagination.py
+106 −0 chord_metadata_service/mohpackets/permissible_values.py
+0 −56 chord_metadata_service/mohpackets/permissions.py
+17 −0 chord_metadata_service/mohpackets/schemas/discovery.py
+248 −0 chord_metadata_service/mohpackets/schemas/filter.py
+219 −0 chord_metadata_service/mohpackets/schemas/ingestion.py
+336 −0 chord_metadata_service/mohpackets/schemas/model.py
+218 −0 chord_metadata_service/mohpackets/schemas/nested_data.py
+0 −658 chord_metadata_service/mohpackets/serializers.py
+0 −319 chord_metadata_service/mohpackets/serializers_nested.py
+189 −0 chord_metadata_service/mohpackets/signals.py
+9 −12 chord_metadata_service/mohpackets/tests/endpoints/base.py
+138 −54 chord_metadata_service/mohpackets/tests/endpoints/factories.py
+31 −35 chord_metadata_service/mohpackets/tests/endpoints/test_chemotherapy.py
+24 −27 chord_metadata_service/mohpackets/tests/endpoints/test_donor.py
+23 −27 chord_metadata_service/mohpackets/tests/endpoints/test_follow_up.py
+24 −29 chord_metadata_service/mohpackets/tests/endpoints/test_primary_diagnoses.py
+29 −27 chord_metadata_service/mohpackets/tests/endpoints/test_program.py
+26 −28 chord_metadata_service/mohpackets/tests/endpoints/test_sample_registration.py
+25 −25 chord_metadata_service/mohpackets/tests/endpoints/test_specimen.py
+25 −25 chord_metadata_service/mohpackets/tests/endpoints/test_treatment.py
+839 −808 chord_metadata_service/mohpackets/tests/test_models.py
+0 −23 chord_metadata_service/mohpackets/throttling.py
+0 −141 chord_metadata_service/mohpackets/urls.py
+21 −6 chord_metadata_service/mohpackets/utils.py
+0 −12 config/hooks.py
+2 −94 config/settings/base.py
+3 −1 config/settings/dev.py
+25 −1 config/settings/local.py
+84 −11 config/settings/prod.py
+10 −12 config/urls.py
+5 −6 requirements/base.txt
+2 −2 requirements/dev.txt
+5 −6 requirements/local.txt