Skip to content

Commit

Permalink
Dicom Viewer Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnaa05 committed Dec 16, 2024
1 parent 6b3213c commit 68b5099
Show file tree
Hide file tree
Showing 8 changed files with 899 additions and 667 deletions.
1 change: 1 addition & 0 deletions .github/workflows/shared_integration_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ jobs:
run: |
mkdir output
GEN3_INSTANCE_TYPE="ADMINVM_REMOTE" poetry run pytest -n auto -m "not wip" --alluredir allure-results --no-header --dist loadscope ${{ env.TEST_LABEL }}
GEN3_INSTANCE_TYPE="ADMINVM_REMOTE" poetry run pytest -m "not wip or sequential" --alluredir allure-results --no-header ${{ env.TEST_LABEL }}
- name: Debug logging
if: ${{ env.SKIP_TESTS != 'true' }}
Expand Down
32 changes: 32 additions & 0 deletions gen3-integration-tests/pages/dicom.py
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")
3 changes: 3 additions & 0 deletions gen3-integration-tests/pages/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ def login(
.get("topBar", {})
.get("useProfileDropdown", "")
):
accept_button = page.locator(self.POP_UP_ACCEPT_BUTTON)
if accept_button:
accept_button.click()
page.locator(self.USER_PROFILE_DROPDOWN).click()
expect(
page.get_by_role("link").filter(has_text=logged_in_user)
Expand Down
1,355 changes: 688 additions & 667 deletions gen3-integration-tests/poetry.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions gen3-integration-tests/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ markers = [
"wip: marks tests as `Work In Progress` and skips them in CI pipeline",
"requires_fence_client: tests for fence clients",
"requires_google_bucket: tests which require creation of google buckets",
"sequential: tests which needs to be run sequentially due to dependencies",
# services
"argo_wrapper: tests for argo_wrapper",
"audit: tests for audit-service",
"dicom_viewer: tests for dicom-viewer",
"fence: test for fence service",
"frontend_framework: tests for frontend-framework",
"gen3_client: tests for gen3-client / cdis-data-client",
Expand Down
71 changes: 71 additions & 0 deletions gen3-integration-tests/services/dicom.py
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.
102 changes: 102 additions & 0 deletions gen3-integration-tests/tests/test_dicom_viewer.py
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)

0 comments on commit 68b5099

Please sign in to comment.