-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b3213c
commit 68b5099
Showing
8 changed files
with
899 additions
and
667 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pytest | ||
from playwright.sync_api import Page, expect | ||
from utils import logger | ||
from utils.test_execution import screenshot | ||
|
||
|
||
class DicomPage(object): | ||
def __init__(self): | ||
self.BASE_URL = f"{pytest.root_url_portal}" | ||
# Endpoints | ||
self.EXPLORER_ENDPOINT = f"{self.BASE_URL}/explorer" | ||
# Locators | ||
self.IMAGING_STUDIES_TAB = "//h3[normalize-space()='Imaging Studies']" | ||
self.CORNERSTONE_CANVAS = "//*[@class='cornerstone-canvas']" | ||
|
||
def goto_explorer_page(self, page: Page, study_id): | ||
page.goto(self.EXPLORER_ENDPOINT) | ||
screenshot(page, "ExplorerPage") | ||
imaging_studies_tab = page.locator(self.IMAGING_STUDIES_TAB) | ||
expect(imaging_studies_tab).to_be_visible(timeout=5000) | ||
imaging_studies_tab.click() | ||
screenshot(page, "ImagingStudiesPage") | ||
STUDY_ID_HREF_XPATH = f"//a[contains(@href, 'StudyInstanceUIDs={study_id}')][1]" | ||
study_id_href = page.locator(STUDY_ID_HREF_XPATH) | ||
expect(study_id_href).to_be_visible(timeout=5000) | ||
href_url = study_id_href.get_attribute("href") | ||
page.goto(href_url) | ||
logger.info(page.url) | ||
assert study_id in page.url, f"Expected {study_id} in {page.url}" | ||
cornerstone_canvas = page.locator(self.CORNERSTONE_CANVAS) | ||
expect(cornerstone_canvas).to_be_visible(timeout=5000) | ||
screenshot(page, "OHIFViewerPage") |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import pytest | ||
import requests | ||
from gen3.auth import Gen3Auth | ||
from gen3.submission import Gen3Submission | ||
from utils import TEST_DATA_PATH_OBJECT, logger | ||
|
||
|
||
class Dicom(object): | ||
def __init__(self): | ||
self.BASE_URL = f"{pytest.root_url}" | ||
self.DICOM_INSTANCES = "/dicom-server/instances" | ||
self.DICOM_STUDIES = "/dicom-server/studies" | ||
|
||
def submit_dicom_file(self, user="main_account", expected_status=200): | ||
auth = Gen3Auth(refresh_token=pytest.api_keys[user], endpoint=self.BASE_URL) | ||
access_token = auth.get_access_token() | ||
url = self.BASE_URL + self.DICOM_INSTANCES | ||
with (TEST_DATA_PATH_OBJECT / "dicom/test_file.dcm").open("rb") as file: | ||
content = file.read() | ||
headers = { | ||
"Content-Type": "application/dicom", | ||
"Authorization": f"bearer {access_token}", | ||
} | ||
response = requests.post(url=url, data=content, headers=headers) | ||
assert ( | ||
response.status_code == expected_status | ||
), f"Expected status {expected_status} but got {response.status_code}" | ||
if response.status_code == 200: | ||
logger.info(response.json()) | ||
return response.json() | ||
|
||
def get_studies(self, study_instance, user="main_account"): | ||
auth = Gen3Auth(refresh_token=pytest.api_keys[user], endpoint=self.BASE_URL) | ||
url = self.DICOM_STUDIES + "/" + study_instance | ||
response = auth.curl(path=url) | ||
assert ( | ||
response.status_code == 200 | ||
), f"Expected status 200 but got {response.status_code}" | ||
return response.json() | ||
|
||
def submit_dicom_data( | ||
self, | ||
case_submitted_id, | ||
program, | ||
project, | ||
study_id, | ||
dataset_submitter_id, | ||
case_linked_external_data, | ||
user="main_account", | ||
): | ||
auth = Gen3Auth(refresh_token=pytest.api_keys[user], endpoint=self.BASE_URL) | ||
submit_data = { | ||
"type": "imaging_study", | ||
"datasets": {"submitter_id": dataset_submitter_id}, | ||
"cases": [ | ||
{ | ||
"submitter_id": case_submitted_id, | ||
} | ||
], | ||
"image_data_modified": False, | ||
"submitter_id": study_id, | ||
} | ||
Gen3Submission(auth_provider=auth).submit_record(program, project, submit_data) | ||
|
||
def get_dicom_file(self, dicom_file_id, user="main_account", expected_status=200): | ||
auth = Gen3Auth(refresh_token=pytest.api_keys[user], endpoint=self.BASE_URL) | ||
url = self.DICOM_INSTANCES + "/" + dicom_file_id | ||
response = auth.curl(path=url) | ||
assert ( | ||
response.status_code == expected_status | ||
), f"Expected status {expected_status} but got {response.status_code}" |
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import pytest | ||
import utils.gen3_admin_tasks as gat | ||
from gen3.auth import Gen3Auth | ||
from pages.dicom import DicomPage | ||
from pages.login import LoginPage | ||
from playwright.sync_api import Page | ||
from services.dicom import Dicom | ||
from services.graph import GraphDataTools | ||
from utils import logger | ||
|
||
|
||
@pytest.mark.skipif( | ||
"midrc" not in pytest.namespace, reason="DICOM test is specific to MIDRC" | ||
) | ||
@pytest.mark.dicom_viewer | ||
@pytest.mark.sequential | ||
class TestDicomViewer(object): | ||
auth = Gen3Auth(refresh_token=pytest.api_keys["main_account"]) | ||
sd_tools = GraphDataTools(auth=auth, program_name="DEV", project_code="DICOM_test") | ||
dicom = Dicom() | ||
dicom_page = DicomPage() | ||
login_page = LoginPage() | ||
file_id = "" | ||
study_id = "" | ||
|
||
@classmethod | ||
def setup_class(cls): | ||
cls.sd_tools.delete_all_records() | ||
file_res = cls.dicom.submit_dicom_file() | ||
cls.file_id = file_res["ID"] | ||
study_instance = file_res["ParentStudy"] | ||
study_res = cls.dicom.get_studies(study_instance=study_instance) | ||
cls.study_id = study_res["MainDicomTags"]["StudyInstanceUID"] | ||
cls.sd_tools.submit_all_test_records() | ||
logger.info("Running first etl") | ||
gat.run_gen3_job("etl", test_env_namespace=pytest.namespace) | ||
for key, item in cls.sd_tools.test_records.items(): | ||
if key == "dataset": | ||
dataset_submitter_id = item.props["submitter_id"] | ||
if key == "case": | ||
case_linked_external_data = item.props["linked_external_data"] | ||
case_submitted_id = item.props["submitter_id"] | ||
cls.dicom.submit_dicom_data( | ||
program="DEV", | ||
project="DICOM_test", | ||
study_id=cls.study_id, | ||
dataset_submitter_id=dataset_submitter_id, | ||
case_submitted_id=case_submitted_id, | ||
case_linked_external_data=case_linked_external_data, | ||
) | ||
logger.info("Running second etl") | ||
gat.run_gen3_job("etl", test_env_namespace=pytest.namespace) | ||
|
||
@classmethod | ||
def teardown_class(cls): | ||
cls.sd_tools.delete_all_records() | ||
|
||
def test_check_uploaded_dicom_file(self, page: Page): | ||
""" | ||
Scenario: Verify Uploaded Dicom file | ||
Steps: | ||
1. Goto Exploration page and click on Imaging Studies tab | ||
2. Find the xref containing the study id | ||
3. Click on the button of the href | ||
4. Verify OHIF viewer page is launched for the study id | ||
""" | ||
# Login with main_account | ||
self.login_page.go_to(page) | ||
self.login_page.login(page, user="main_account") | ||
|
||
# Goto explorer page | ||
self.dicom_page.goto_explorer_page(page=page, study_id=self.study_id) | ||
|
||
def test_unauthorized_user_cannot_post_dicom_file(self): | ||
""" | ||
Scenario: Unauthorized user cannot submit dicom file | ||
Steps: | ||
1. Submit a dicom file using dummy_one user | ||
2. Expect 403 in response, since dummy_one user doesn't have permission to submit dicom file | ||
""" | ||
self.dicom.submit_dicom_file(user="dummy_one", expected_status=403) | ||
|
||
def test_unauthorized_user_cannot_get_dicom_file(self): | ||
""" | ||
Scenario: Unauthorized user cannot get dicom file | ||
Steps: | ||
1. Get dicom file deatils using dummy_one user | ||
2. Expect 403 in response, since dummy_one user doesn't have permission to get dicom file | ||
""" | ||
self.dicom.get_dicom_file( | ||
dicom_file_id=self.file_id, user="dummy_one", expected_status=403 | ||
) | ||
|
||
def test_unauthorized_user_cannot_get_non_exist_dicom_file(self): | ||
""" | ||
Scenario: Unauthorized user cannot get non-exist dicom file | ||
Steps: | ||
1. Get non-exist dicom file deatils using dummy_one user | ||
2. Expect 404 in response, since the dicom file doesn't exists | ||
""" | ||
non_exist_id = "538a3dfd-219a25e0-8443a0b7-d1f512a6-2348ff25" | ||
self.dicom.get_dicom_file(dicom_file_id=non_exist_id, expected_status=404) |