Skip to content

Commit 02cbbfe

Browse files
committed
Replace hardcoded interface kinds with enum choice
1 parent 11791b3 commit 02cbbfe

5 files changed

Lines changed: 70 additions & 37 deletions

File tree

app/tests/archives_tests/test_views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ def test_archive_item_upload_corrupt_image(
13821382
editor = UserFactory()
13831383
archive = ArchiveFactory()
13841384
archive.add_editor(editor)
1385-
ci_img = ComponentInterfaceFactory(kind="IMG")
1385+
ci_img = ComponentInterfaceFactory(kind=InterfaceKindChoices.PANIMG_IMAGE)
13861386

13871387
im_upload = create_upload_from_file(
13881388
file_path=RESOURCE_PATH / "corrupt.png",

app/tests/components_tests/test_tasks.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def test_add_image_to_object(
394394

395395
obj = object_type(**extra_object_kwargs)
396396
us = RawImageUploadSessionFactory(status=RawImageUploadSession.SUCCESS)
397-
ci = ComponentInterfaceFactory(kind="IMG")
397+
ci = ComponentInterfaceFactory(kind=InterfaceKindChoices.PANIMG_IMAGE)
398398
ImageFactory(origin=us)
399399

400400
linked_task = some_async_task.signature(
@@ -430,7 +430,7 @@ def test_add_image_to_object_updates_upload_session_on_validation_fail(
430430

431431
obj = object_type()
432432
us = RawImageUploadSessionFactory(status=RawImageUploadSession.SUCCESS)
433-
ci = ComponentInterfaceFactory(kind="IMG")
433+
ci = ComponentInterfaceFactory(kind=InterfaceKindChoices.PANIMG_IMAGE)
434434

435435
error_message = f"Image validation for socket {ci.title} failed with error: Image imports should result in a single image. "
436436

@@ -465,7 +465,7 @@ def test_add_image_to_object_marks_job_as_failed_on_validation_fail(
465465

466466
obj = AlgorithmJobFactory(time_limit=10)
467467
us = RawImageUploadSessionFactory(status=RawImageUploadSession.SUCCESS)
468-
ci = ComponentInterfaceFactory(kind="IMG")
468+
ci = ComponentInterfaceFactory(kind=InterfaceKindChoices.PANIMG_IMAGE)
469469

470470
error_message = f"Image validation for socket {ci.title} failed with error: Image imports should result in a single image. "
471471

@@ -543,7 +543,7 @@ def test_task_handles_deleted_object(
543543
kwargs={"foo": "bar"}, immutable=True
544544
)
545545

546-
ci = ComponentInterfaceFactory(kind="IMG")
546+
ci = ComponentInterfaceFactory(kind=InterfaceKindChoices.PANIMG_IMAGE)
547547

548548
task_kwargs = {
549549
"app_label": obj._meta.app_label,
@@ -597,7 +597,7 @@ def test_add_file_to_object(
597597
)
598598
us.save()
599599
ci = ComponentInterfaceFactory(
600-
kind="JSON",
600+
kind=InterfaceKindChoices.ANY,
601601
store_in_database=False,
602602
schema={
603603
"$schema": "http://json-schema.org/draft-07/schema",
@@ -650,7 +650,7 @@ def test_add_file_to_object_sends_notification_on_validation_fail(
650650
)
651651
us.save()
652652
ci = ComponentInterfaceFactory(
653-
kind="JSON",
653+
kind=InterfaceKindChoices.ANY,
654654
store_in_database=False,
655655
schema={
656656
"$schema": "http://json-schema.org/draft-07/schema",
@@ -700,7 +700,7 @@ def test_add_file_to_object_updates_job_on_validation_fail(
700700
)
701701
us.save()
702702
ci = ComponentInterfaceFactory(
703-
kind="JSON",
703+
kind=InterfaceKindChoices.ANY,
704704
store_in_database=False,
705705
schema={
706706
"$schema": "http://json-schema.org/draft-07/schema",

app/tests/components_tests/test_views.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,15 @@ def _get_view(user, context):
6565

6666
@pytest.mark.django_db
6767
def test_component_interface_autocomplete(client):
68-
ci_json = ComponentInterfaceFactory(title="test-json", kind="JSON")
69-
ci_img = ComponentInterfaceFactory(title="test-img", kind="IMG")
70-
ci_img_2 = ComponentInterfaceFactory(title="foo-img", kind="IMG")
68+
ci_json = ComponentInterfaceFactory(
69+
title="test-json", kind=InterfaceKindChoices.ANY
70+
)
71+
ci_img = ComponentInterfaceFactory(
72+
title="test-img", kind=InterfaceKindChoices.PANIMG_IMAGE
73+
)
74+
ci_img_2 = ComponentInterfaceFactory(
75+
title="foo-img", kind=InterfaceKindChoices.PANIMG_IMAGE
76+
)
7177
user = UserFactory()
7278
rs = ReaderStudyFactory()
7379

@@ -178,9 +184,15 @@ def test_component_interface_autocomplete(client):
178184

179185
@pytest.mark.django_db
180186
def test_ci_autocomplete_for_archives(client):
181-
ci_json = ComponentInterfaceFactory(title="test-json", kind="JSON")
182-
ci_img = ComponentInterfaceFactory(title="test-img", kind="IMG")
183-
ci_img_2 = ComponentInterfaceFactory(title="foo-img", kind="IMG")
187+
ci_json = ComponentInterfaceFactory(
188+
title="test-json", kind=InterfaceKindChoices.ANY
189+
)
190+
ci_img = ComponentInterfaceFactory(
191+
title="test-img", kind=InterfaceKindChoices.PANIMG_IMAGE
192+
)
193+
ci_img_2 = ComponentInterfaceFactory(
194+
title="foo-img", kind=InterfaceKindChoices.PANIMG_IMAGE
195+
)
184196

185197
user = UserFactory()
186198
archive = ArchiveFactory()
@@ -476,7 +488,9 @@ def test_file_upload_form_field_view(client, factory):
476488
u, editor = UserFactory.create_batch(2)
477489
instance.add_editor(editor)
478490

479-
ci_json = ComponentInterfaceFactory(kind="JSON", store_in_database=False)
491+
ci_json = ComponentInterfaceFactory(
492+
kind=InterfaceKindChoices.ANY, store_in_database=False
493+
)
480494

481495
response = get_view_for_user(
482496
viewname="components:file-upload",

app/tests/reader_studies_tests/test_forms.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,9 @@ def test_display_set_update_form(form_class):
14231423

14241424
for slug, store_in_db in [("slug-1", False), ("slug-2", True)]:
14251425
ci = ComponentInterfaceFactory(
1426-
title=slug, kind="JSON", store_in_database=store_in_db
1426+
title=slug,
1427+
kind=InterfaceKindChoices.ANY,
1428+
store_in_database=store_in_db,
14271429
)
14281430
civ = ComponentInterfaceValueFactory(interface=ci)
14291431
ds.values.add(civ)
@@ -1445,7 +1447,9 @@ def test_display_set_update_form(form_class):
14451447
JSONEditorWidget,
14461448
)
14471449

1448-
ci = ComponentInterfaceFactory(kind="STR", title="slug-3")
1450+
ci = ComponentInterfaceFactory(
1451+
kind=InterfaceKindChoices.STRING, title="slug-3"
1452+
)
14491453
QuestionFactory(reader_study=rs, answer_type=AnswerType.TEXT, interface=ci)
14501454
del rs.interfaces_and_values
14511455
del rs.values_for_interfaces
@@ -1532,9 +1536,11 @@ def test_display_set_form_interface_fields_not_required(form_class):
15321536
rs = ReaderStudyFactory()
15331537
user = UserFactory()
15341538
rs.add_editor(user)
1535-
ci_img = ComponentInterfaceFactory(kind="IMG")
1536-
ci_file = ComponentInterfaceFactory(kind="JSON", store_in_database=False)
1537-
ci_str = ComponentInterfaceFactory(kind="STR")
1539+
ci_img = ComponentInterfaceFactory(kind=InterfaceKindChoices.PANIMG_IMAGE)
1540+
ci_file = ComponentInterfaceFactory(
1541+
kind=InterfaceKindChoices.ANY, store_in_database=False
1542+
)
1543+
ci_str = ComponentInterfaceFactory(kind=InterfaceKindChoices.STRING)
15381544
for ci in [ci_img, ci_file, ci_str]:
15391545
civ = ComponentInterfaceValueFactory(interface=ci)
15401546
ds = DisplaySetFactory(reader_study=rs)
@@ -1599,9 +1605,15 @@ def test_display_set_add_interface_form():
15991605
user = UserFactory()
16001606
rs.add_editor(user)
16011607

1602-
ci_file = ComponentInterfaceFactory(kind="JSON", store_in_database=False)
1603-
ci_value = ComponentInterfaceFactory(kind="JSON", store_in_database=True)
1604-
ci_image = ComponentInterfaceFactory(kind="IMG", store_in_database=False)
1608+
ci_file = ComponentInterfaceFactory(
1609+
kind=InterfaceKindChoices.ANY, store_in_database=False
1610+
)
1611+
ci_value = ComponentInterfaceFactory(
1612+
kind=InterfaceKindChoices.ANY, store_in_database=True
1613+
)
1614+
ci_image = ComponentInterfaceFactory(
1615+
kind=InterfaceKindChoices.PANIMG_IMAGE, store_in_database=False
1616+
)
16051617

16061618
form = SingleCIVForm(
16071619
pk=ds.pk,

app/tests/reader_studies_tests/test_views.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
INTERFACE_FORM_FIELD_PREFIX,
1313
FlexibleFileField,
1414
)
15-
from grandchallenge.components.models import ComponentInterfaceValue
15+
from grandchallenge.components.models import (
16+
ComponentInterfaceValue,
17+
InterfaceKindChoices,
18+
)
1619
from grandchallenge.notifications.models import Notification
1720
from grandchallenge.profiles.templatetags.profiles import user_profile_link
1821
from grandchallenge.reader_studies.interactive_algorithms import (
@@ -439,16 +442,16 @@ def test_display_set_update(
439442
rs.add_editor(user)
440443
# 3 interfaces of different types
441444
ci_json = ComponentInterfaceFactory(
442-
kind="JSON",
445+
kind=InterfaceKindChoices.ANY,
443446
schema={
444447
"$schema": "http://json-schema.org/draft-07/schema",
445448
"type": "object",
446449
},
447450
)
448451
ci_json_file = ComponentInterfaceFactory(
449-
kind="JSON", store_in_database=False
452+
kind=InterfaceKindChoices.ANY, store_in_database=False
450453
)
451-
ci_img = ComponentInterfaceFactory(kind="IMG")
454+
ci_img = ComponentInterfaceFactory(kind=InterfaceKindChoices.PANIMG_IMAGE)
452455
# create CIVs for those interfaces
453456
im1, im2 = ImageFactory.create_batch(2)
454457
assign_perm("cases.view_image", user, im2)
@@ -624,12 +627,16 @@ def test_add_display_set_to_reader_study(
624627
rs = ReaderStudyFactory()
625628
ds1 = DisplaySetFactory(reader_study=rs)
626629
rs.add_editor(u1)
627-
ci_str = ComponentInterfaceFactory(kind="STR")
628-
ci_img = ComponentInterfaceFactory(kind="IMG")
630+
ci_str = ComponentInterfaceFactory(kind=InterfaceKindChoices.STRING)
631+
ci_img = ComponentInterfaceFactory(kind=InterfaceKindChoices.PANIMG_IMAGE)
629632

630-
ci_img_new = ComponentInterfaceFactory(kind="IMG")
631-
ci_str_new = ComponentInterfaceFactory(kind="STR")
632-
ci_json = ComponentInterfaceFactory(kind="JSON", store_in_database=False)
633+
ci_img_new = ComponentInterfaceFactory(
634+
kind=InterfaceKindChoices.PANIMG_IMAGE
635+
)
636+
ci_str_new = ComponentInterfaceFactory(kind=InterfaceKindChoices.STRING)
637+
ci_json = ComponentInterfaceFactory(
638+
kind=InterfaceKindChoices.ANY, store_in_database=False
639+
)
633640

634641
im1, im2 = ImageFactory.create_batch(2)
635642
civ_str = ComponentInterfaceValueFactory(
@@ -721,7 +728,7 @@ def test_add_display_set_update_when_disabled(client):
721728
rs = ReaderStudyFactory()
722729
ds = DisplaySetFactory(reader_study=rs)
723730
rs.add_editor(editor)
724-
ci_str = ComponentInterfaceFactory(kind="STR")
731+
ci_str = ComponentInterfaceFactory(kind=InterfaceKindChoices.STRING)
725732

726733
# add an answer for the ds
727734
AnswerFactory(question__reader_study=rs, display_set=ds, answer="true")
@@ -749,9 +756,9 @@ def test_add_display_set_update_when_disabled(client):
749756
@pytest.mark.parametrize(
750757
"interface_kind, store_in_database, field_type",
751758
(
752-
("JSON", False, FlexibleFileField),
753-
("JSON", True, JSONField),
754-
("IMG", False, FlexibleImageField),
759+
(InterfaceKindChoices.ANY, False, FlexibleFileField),
760+
(InterfaceKindChoices.ANY, True, JSONField),
761+
(InterfaceKindChoices.PANIMG_IMAGE, False, FlexibleImageField),
755762
),
756763
)
757764
@pytest.mark.django_db
@@ -893,7 +900,7 @@ def test_display_set_upload_corrupt_image(
893900
editor = UserFactory()
894901
rs = ReaderStudyFactory()
895902
rs.add_editor(editor)
896-
ci_img = ComponentInterfaceFactory(kind="IMG")
903+
ci_img = ComponentInterfaceFactory(kind=InterfaceKindChoices.PANIMG_IMAGE)
897904

898905
im_upload = create_upload_from_file(
899906
file_path=RESOURCE_PATH / "corrupt.png",

0 commit comments

Comments
 (0)