Skip to content

Commit

Permalink
Use adit-radis-shared testing helpers instead of fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
medihack committed Dec 25, 2024
1 parent 1af64bd commit dd6b597
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 51 deletions.
30 changes: 14 additions & 16 deletions adit/batch_query/tests/integration/test_batch_query.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from typing import Callable

import pandas as pd
import pytest
from adit_radis_shared.accounts.models import User
from adit_radis_shared.common.utils.auth_utils import add_permission, add_user_to_group
from adit_radis_shared.common.utils.worker_utils import run_worker_once
from playwright.sync_api import Locator, Page, expect
from adit_radis_shared.common.utils.testing_helpers import (
add_permission,
add_user_to_group,
create_and_login_example_user,
poll_locator,
run_worker_once,
)
from playwright.sync_api import Page, expect
from pytest_django.live_server_helper import LiveServer

from adit.batch_query.models import BatchQueryJob
Expand All @@ -20,17 +22,15 @@

@pytest.mark.integration
@pytest.mark.django_db(transaction=True)
def test_urgent_batch_query_with_dimse_server(
page: Page, poll: Callable[[Locator], Locator], live_server: LiveServer, create_and_login_user
):
def test_urgent_batch_query_with_dimse_server(page: Page, live_server: LiveServer):
# Arrange
df = pd.DataFrame(
[["1005", "0062115904"]],
columns=["PatientID", "AccessionNumber"], # type: ignore
)
batch_file = create_excel_file(df, "batch_file.xlsx")

user: User = create_and_login_user(live_server.url)
user = create_and_login_example_user(page, live_server.url)
group = create_batch_query_group()
add_user_to_group(user, group)
add_permission(group, BatchQueryJob, "can_process_urgently")
Expand All @@ -51,22 +51,20 @@ def test_urgent_batch_query_with_dimse_server(
run_worker_once()

# Assert
expect(poll(page.locator('dl:has-text("Success")'))).to_be_visible()
expect(poll_locator(page.locator('dl:has-text("Success")'))).to_be_visible()


@pytest.mark.integration
@pytest.mark.django_db(transaction=True)
def test_urgent_batch_query_with_dicomweb_server(
page: Page, poll: Callable[[Locator], Locator], live_server: LiveServer, create_and_login_user
):
def test_urgent_batch_query_with_dicomweb_server(page: Page, live_server: LiveServer):
# Arrange
df = pd.DataFrame(
[["1005", "0062115904"]],
columns=["PatientID", "AccessionNumber"], # type: ignore
)
batch_file = create_excel_file(df, "batch_file.xlsx")

user: User = create_and_login_user(live_server.url)
user = create_and_login_example_user(page, live_server.url)
group = create_batch_query_group()
add_user_to_group(user, group)
add_permission(group, BatchQueryJob, "can_process_urgently")
Expand All @@ -87,4 +85,4 @@ def test_urgent_batch_query_with_dicomweb_server(
run_worker_once()

# Assert
expect(poll(page.locator('dl:has-text("Success")'))).to_be_visible()
expect(poll_locator(page.locator('dl:has-text("Success")'))).to_be_visible()
2 changes: 1 addition & 1 deletion adit/batch_query/utils/testing_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from adit_radis_shared.accounts.factories import GroupFactory
from adit_radis_shared.common.utils.auth_utils import add_permission
from adit_radis_shared.common.utils.testing_helpers import add_permission


def create_batch_query_group():
Expand Down
26 changes: 14 additions & 12 deletions adit/batch_transfer/tests/integration/test_batch_transfer.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from typing import Callable

import pandas as pd
import pytest
from adit_radis_shared.accounts.models import User
from adit_radis_shared.common.utils.auth_utils import add_permission, add_user_to_group
from adit_radis_shared.common.utils.worker_utils import run_worker_once
from playwright.sync_api import Locator, Page, expect
from adit_radis_shared.common.utils.testing_helpers import (
add_permission,
add_user_to_group,
create_and_login_example_user,
poll_locator,
run_worker_once,
)
from playwright.sync_api import Page, expect
from pytest_django.live_server_helper import LiveServer

from adit.batch_transfer.models import BatchTransferJob
Expand All @@ -21,7 +23,7 @@
@pytest.mark.integration
@pytest.mark.django_db(transaction=True)
def test_unpseudonymized_urgent_batch_transfer_with_dimse_server(
page: Page, poll: Callable[[Locator], Locator], live_server: LiveServer, create_and_login_user
page: Page, live_server: LiveServer
):
# Arrange
df = pd.DataFrame(
Expand All @@ -30,7 +32,7 @@ def test_unpseudonymized_urgent_batch_transfer_with_dimse_server(
)
batch_file = create_excel_file(df, "batch_file.xlsx")

user: User = create_and_login_user(live_server.url)
user = create_and_login_example_user(page, live_server.url)
group = create_batch_transfer_group()
add_user_to_group(user, group)
add_permission(group, BatchTransferJob, "can_process_urgently")
Expand All @@ -54,13 +56,13 @@ def test_unpseudonymized_urgent_batch_transfer_with_dimse_server(
run_worker_once()

# Assert
expect(poll(page.locator('dl:has-text("Success")'))).to_be_visible()
expect(poll_locator(page.locator('dl:has-text("Success")'))).to_be_visible()


@pytest.mark.integration
@pytest.mark.django_db(transaction=True)
def test_unpseudonymized_urgent_batch_transfer_with_dicomweb_server(
page: Page, poll: Callable[[Locator], Locator], live_server: LiveServer, create_and_login_user
page: Page, live_server: LiveServer
):
# Arrange
df = pd.DataFrame(
Expand All @@ -69,7 +71,7 @@ def test_unpseudonymized_urgent_batch_transfer_with_dicomweb_server(
)
batch_file = create_excel_file(df, "batch_file.xlsx")

user: User = create_and_login_user(live_server.url)
user = create_and_login_example_user(page, live_server.url)
group = create_batch_transfer_group()
add_user_to_group(user, group)
add_permission(group, BatchTransferJob, "can_process_urgently")
Expand All @@ -93,4 +95,4 @@ def test_unpseudonymized_urgent_batch_transfer_with_dicomweb_server(
run_worker_once()

# Assert
expect(poll(page.locator('dl:has-text("Success")'))).to_be_visible()
expect(poll_locator(page.locator('dl:has-text("Success")'))).to_be_visible()
2 changes: 1 addition & 1 deletion adit/batch_transfer/tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from adit_radis_shared.accounts.factories import UserFactory
from adit_radis_shared.common.utils.auth_utils import add_user_to_group
from adit_radis_shared.common.utils.testing_helpers import add_user_to_group
from django.core.files import File
from pytest_mock import MockerFixture

Expand Down
2 changes: 1 addition & 1 deletion adit/batch_transfer/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from adit_radis_shared.accounts.factories import UserFactory
from adit_radis_shared.common.utils.auth_utils import add_user_to_group
from adit_radis_shared.common.utils.testing_helpers import add_user_to_group
from django.conf import LazySettings
from django.test import Client
from django.urls import reverse
Expand Down
2 changes: 1 addition & 1 deletion adit/batch_transfer/utils/testing_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pandas as pd
from adit_radis_shared.accounts.factories import GroupFactory
from adit_radis_shared.common.utils.auth_utils import add_permission
from adit_radis_shared.common.utils.testing_helpers import add_permission
from django.core.files import File
from django.core.files.uploadedfile import SimpleUploadedFile

Expand Down
2 changes: 1 addition & 1 deletion adit/core/tests/test_processors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
import time_machine
from adit_radis_shared.accounts.factories import UserFactory
from adit_radis_shared.common.utils.auth_utils import add_user_to_group
from adit_radis_shared.common.utils.testing_helpers import add_user_to_group
from pytest_mock import MockerFixture

from adit.core.utils.testing_helpers import create_example_transfer_group, create_resources
Expand Down
2 changes: 1 addition & 1 deletion adit/core/tests/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from adit_radis_shared.common.utils.worker_utils import run_worker_once
from adit_radis_shared.common.utils.testing_helpers import run_worker_once
from pytest_mock import MockerFixture

from adit.core.errors import RetriableDicomError
Expand Down
2 changes: 1 addition & 1 deletion adit/core/utils/testing_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pandas as pd
from adit_radis_shared.accounts.factories import GroupFactory
from adit_radis_shared.common.utils.auth_utils import add_permission
from adit_radis_shared.common.utils.testing_helpers import add_permission
from dicomweb_client import DICOMwebClient
from django.conf import settings
from django.core.management import call_command
Expand Down
2 changes: 1 addition & 1 deletion adit/dicom_web/tests/integration/test_stowrs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from adit_radis_shared.common.utils.testing import ChannelsLiveServer
from adit_radis_shared.common.utils.testing_helpers import ChannelsLiveServer
from pydicom import Dataset
from pytest_django.live_server_helper import LiveServer

Expand Down
2 changes: 1 addition & 1 deletion adit/dicom_web/tests/integration/test_wadors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pydicom
import pytest
from adit_radis_shared.common.utils.testing import ChannelsLiveServer
from adit_radis_shared.common.utils.testing_helpers import ChannelsLiveServer

from adit.core.models import DicomServer
from adit.core.utils.auth_utils import grant_access
Expand Down
2 changes: 1 addition & 1 deletion adit/dicom_web/utils/testing_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from adit_radis_shared.accounts.factories import GroupFactory, UserFactory
from adit_radis_shared.common.utils.auth_utils import add_permission, add_user_to_group
from adit_radis_shared.common.utils.testing_helpers import add_permission, add_user_to_group
from adit_radis_shared.token_authentication.models import Token


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import pytest
from adit_radis_shared.accounts.models import User
from adit_radis_shared.common.utils.auth_utils import add_permission, add_user_to_group
from adit_radis_shared.common.utils.testing import ChannelsLiveServer
from adit_radis_shared.common.utils.worker_utils import run_worker_once
from adit_radis_shared.common.utils.testing_helpers import (
ChannelsLiveServer,
add_permission,
add_user_to_group,
create_and_login_example_user,
run_worker_once,
)
from playwright.sync_api import Page, expect

from adit.core.utils.auth_utils import grant_access
Expand All @@ -14,10 +17,10 @@
@pytest.mark.integration
@pytest.mark.django_db(transaction=True)
def test_unpseudonymized_urgent_selective_transfer_with_dimse_server(
page: Page, channels_live_server: ChannelsLiveServer, create_and_login_user
page: Page, channels_live_server: ChannelsLiveServer
):
# Arrange
user: User = create_and_login_user(channels_live_server.url)
user = create_and_login_example_user(page, channels_live_server.url)
group = create_selective_transfer_group()
add_user_to_group(user, group)
add_permission(group, SelectiveTransferJob, "can_process_urgently")
Expand Down Expand Up @@ -49,10 +52,10 @@ def test_unpseudonymized_urgent_selective_transfer_with_dimse_server(
@pytest.mark.integration
@pytest.mark.django_db(transaction=True)
def test_unpseudonymized_urgent_selective_transfer_with_dicomweb_server(
page: Page, channels_live_server: ChannelsLiveServer, create_and_login_user
page: Page, channels_live_server: ChannelsLiveServer
):
# Arrange
user: User = create_and_login_user(channels_live_server.url)
user = create_and_login_example_user(page, channels_live_server.url)
group = create_selective_transfer_group()
add_user_to_group(user, group)
add_permission(group, SelectiveTransferJob, "can_process_urgently")
Expand Down
2 changes: 1 addition & 1 deletion adit/selective_transfer/utils/testing_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from adit_radis_shared.accounts.factories import GroupFactory
from adit_radis_shared.common.utils.auth_utils import add_permission
from adit_radis_shared.common.utils.testing_helpers import add_permission
from django.contrib.auth.models import Group


Expand Down
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "AGPL-3.0-or-later"
readme = "README.md"

[tool.poetry.dependencies]
adit-radis-shared = { git = "https://github.com/openradx/adit-radis-shared.git", tag = "0.10.1" }
adit-radis-shared = { git = "https://github.com/openradx/adit-radis-shared.git", tag = "0.11.0" }
adrf = "^0.1.1"
aiofiles = "^24.1.0"
asyncinotify = "^4.0.1"
Expand Down

0 comments on commit dd6b597

Please sign in to comment.