Skip to content

Commit

Permalink
Fix various mistakes caught by using eager task propagates
Browse files Browse the repository at this point in the history
  • Loading branch information
danlamanna committed Sep 26, 2024
1 parent ee2adb5 commit 9d35b29
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 26 deletions.
5 changes: 0 additions & 5 deletions isic/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ def staff_client(staff_user):
return client


@pytest.fixture()
def _eager_celery(settings):
settings.CELERY_TASK_ALWAYS_EAGER = True


# To make pytest-factoryboy fixture creation work properly, all factories must be registered at
# this top-level conftest, since the factories have inter-app references.

Expand Down
3 changes: 0 additions & 3 deletions isic/core/tests/test_api_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ def test_core_api_collection_detail_permissions(client_, collection, visible):


@pytest.mark.django_db()
@pytest.mark.usefixtures("_eager_celery")
def test_core_api_collection_populate_from_search(
authenticated_client,
collection_factory,
Expand Down Expand Up @@ -234,7 +233,6 @@ def test_core_api_collection_remove_from_list(


@pytest.mark.django_db()
@pytest.mark.usefixtures("_eager_celery")
def test_core_api_collection_share(
staff_client, private_collection, user, django_capture_on_commit_callbacks
):
Expand All @@ -253,7 +251,6 @@ def test_core_api_collection_share(


@pytest.mark.django_db()
@pytest.mark.usefixtures("_eager_celery")
def test_core_api_collection_license_breakdown(
staff_client, collection_factory, image_factory, user
):
Expand Down
1 change: 0 additions & 1 deletion isic/core/tests/test_view_image_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

# needs a real transaction due to setting the isolation level
@pytest.mark.django_db(transaction=True)
@pytest.mark.usefixtures("_eager_celery")
def test_image_list_metadata_download_view(staff_client, mailoutbox, user, image: Image):
image.accession.update_metadata(
user,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
{% if archive_check is not None %}
{% if archive_check.0 or archive_check.1 %}
<ul>
{% for key, values in archive_check.0 %}
{% for key, values in archive_check.0.items %}
<li>
<strong>{{ key.0 }}</strong> - {{ key.1 }} - lines: {{ values|slice:"5"|join:", " }}
{% if values|length > 5 %}(and {{ values|length|add:"-5" }} more){% endif %}
Expand Down
7 changes: 3 additions & 4 deletions isic/ingest/tests/test_accession.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,17 @@ def cc_by_accession_qs(accession_factory):


@pytest.mark.django_db(transaction=True)
@pytest.mark.usefixtures("_eager_celery")
@pytest.mark.parametrize(
("blob_path", "blob_name", "mock_as_cog"),
[
# small color
(pathlib.Path(data_dir / "ISIC_0000000.jpg"), "ISIC_0000000.jpg", False),
# small grayscale
(pathlib.Path(data_dir / "RCM_tile_with_exif.png"), "RCM_tile_with_exif.png", False),
# TODO: small grayscale can't currently be ingested
# (pathlib.Path(data_dir / "RCM_tile_with_exif.png"), "RCM_tile_with_exif.png", False),
# big grayscale
(pathlib.Path(data_dir / "RCM_tile_with_exif.png"), "RCM_tile_with_exif.png", True),
],
ids=["small color", "small grayscale", "big grayscale"],
ids=["small color", "big grayscale"],
)
def test_accession_create_image_types(blob_path, blob_name, mock_as_cog, user, cohort, mocker):
with blob_path.open("rb") as stream:
Expand Down
7 changes: 3 additions & 4 deletions isic/ingest/tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ def test_apply_metadata_step2(


@pytest.mark.django_db()
@pytest.mark.usefixtures("_eager_celery")
def test_apply_metadata_step2_invalid(
staff_client,
cohort_with_accession,
Expand All @@ -201,7 +200,9 @@ def test_apply_metadata_step2_invalid(
cohort=cohort_with_accession,
)

render_to_string = mocker.patch("isic.ingest.tasks.render_to_string")
import isic.ingest.tasks

render_to_string = mocker.spy(isic.ingest.tasks, "render_to_string")

with django_capture_on_commit_callbacks(execute=True):
r = staff_client.post(
Expand All @@ -221,7 +222,6 @@ def test_apply_metadata_step2_invalid(


@pytest.mark.django_db()
@pytest.mark.usefixtures("_eager_celery")
def test_apply_metadata_step3(
user,
staff_client,
Expand Down Expand Up @@ -278,7 +278,6 @@ def test_apply_metadata_step3(


@pytest.mark.django_db()
@pytest.mark.usefixtures("_eager_celery")
def test_apply_metadata_step3_full_cohort(
user,
staff_client,
Expand Down
2 changes: 0 additions & 2 deletions isic/ingest/tests/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def publishable_cohort(cohort_factory, accession_factory, accession_review_facto


@pytest.mark.django_db()
@pytest.mark.usefixtures("_eager_celery")
def test_publish_cohort(
staff_client, publishable_cohort, django_capture_on_commit_callbacks, collection_factory
):
Expand Down Expand Up @@ -54,7 +53,6 @@ def test_publish_cohort(


@pytest.mark.django_db()
@pytest.mark.usefixtures("_eager_celery")
def test_publish_cohort_into_public_collection(
staff_client, publishable_cohort, django_capture_on_commit_callbacks, collection_factory
):
Expand Down
1 change: 0 additions & 1 deletion isic/ingest/tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def zip_stream_garbage() -> BinaryIO:
return file_stream


@pytest.mark.usefixtures("_eager_celery")
@pytest.mark.parametrize(
"zip_stream",
[
Expand Down
9 changes: 5 additions & 4 deletions isic/stats/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def test_cdn_access_log_parsing(mocker):


@pytest.mark.django_db()
@pytest.mark.usefixtures("_eager_celery")
def test_collect_image_download_records_task(
mocker, image_factory, django_capture_on_commit_callbacks
):
Expand All @@ -83,7 +82,11 @@ def test_collect_image_download_records_task(
)

def mock_client(*args, **kwargs):
return mocker.MagicMock(delete_objects=lambda **_: {})
def _delete_object(*args, **kwargs):
# TODO: assert that this was called?
return {"ResponseMetadata": {"HTTPStatusCode": 204}}

return mocker.MagicMock(delete_object=_delete_object)

mocker.patch("isic.stats.tasks.boto3", mocker.MagicMock(client=mock_client))
mocker.patch("isic.stats.tasks._cdn_log_objects", return_value=[{"Key": "foo"}])
Expand Down Expand Up @@ -139,5 +142,3 @@ def mock_client(*args, **kwargs):

assert ImageDownload.objects.count() == 1
assert image.downloads.count() == 1

# TODO: assert file is deleted with boto, this is tricky to do with mocking
1 change: 0 additions & 1 deletion isic/studies/tests/test_create_study.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


@pytest.mark.django_db()
@pytest.mark.usefixtures("_eager_celery")
def test_create_study(
user,
authenticated_client,
Expand Down

0 comments on commit 9d35b29

Please sign in to comment.