2626from grandchallenge .subdomains .utils import reverse
2727from grandchallenge .uploads .models import UserUpload
2828from tests .algorithms_tests .factories import AlgorithmInterfaceFactory
29+ from tests .algorithms_tests .test_forms import extract_form_data_from_response
2930from tests .archives_tests .factories import (
3031 ArchiveFactory ,
3132 ArchiveItemFactory ,
@@ -1182,12 +1183,11 @@ def test_archive_item_create_view(
11821183 client = client ,
11831184 user = editor ,
11841185 )
1185- assert len (response .context ["form" ].fields ) == 6
11861186 assert response .context ["form" ].fields [
11871187 f"{ INTERFACE_FORM_FIELD_PREFIX } { ci_str .slug } "
11881188 ]
11891189 assert response .context ["form" ].fields [
1190- f"{ INTERFACE_FORM_FIELD_PREFIX } { ci_img .slug } "
1190+ f"{ FlexibleWidgetPrefixes . CHOICE } { ci_img .slug } "
11911191 ]
11921192 assert response .context ["form" ].fields ["title" ]
11931193
@@ -1261,22 +1261,37 @@ def test_archive_item_create_view_with_empty_value(
12611261 existing_archive_item = ArchiveItemFactory (archive = archive )
12621262 ci_str = ComponentInterfaceFactory (kind = InterfaceKindChoices .STRING )
12631263 ci_img = ComponentInterfaceFactory (kind = InterfaceKindChoices .PANIMG_IMAGE )
1264+ ci_file = ComponentInterfaceFactory (
1265+ kind = InterfaceKindChoices .ANY , store_in_database = False
1266+ )
12641267 civ_str = ci_str .create_instance (value = "foo" )
12651268 civ_img = ci_img .create_instance (image = ImageFactory ())
1266- existing_archive_item .values .set ([civ_str , civ_img ])
1269+ civ_file = ComponentInterfaceValueFactory (interface = ci_file )
1270+ existing_archive_item .values .set ([civ_str , civ_img , civ_file ])
1271+
1272+ response = get_view_for_user (
1273+ viewname = "archives:item-create" ,
1274+ client = client ,
1275+ reverse_kwargs = {"slug" : archive .slug },
1276+ user = editor ,
1277+ method = client .get ,
1278+ )
1279+ data = extract_form_data_from_response (response )
1280+ data .update (
1281+ {
1282+ ** get_interface_form_data (interface_slug = ci_str .slug , data = "bar" ),
1283+ f"{ FlexibleWidgetPrefixes .CHOICE } { ci_img .slug } " : ImageSourceChoices .UNDEFINED .value ,
1284+ f"{ FlexibleWidgetPrefixes .CHOICE } { ci_file .slug } " : ImageSourceChoices .UNDEFINED .value ,
1285+ "title" : "archive-item title" ,
1286+ }
1287+ )
12671288
12681289 with django_capture_on_commit_callbacks (execute = True ):
12691290 response = get_view_for_user (
12701291 viewname = "archives:item-create" ,
12711292 client = client ,
12721293 reverse_kwargs = {"slug" : archive .slug },
1273- data = {
1274- ** get_interface_form_data (
1275- interface_slug = ci_str .slug , data = "bar"
1276- ),
1277- f"{ FlexibleWidgetPrefixes .CHOICE } { ci_img .slug } " : ImageSourceChoices .UNDEFINED .value ,
1278- "title" : "archive-item title" ,
1279- },
1294+ data = data ,
12801295 user = editor ,
12811296 method = client .post ,
12821297 )
@@ -1289,6 +1304,8 @@ def test_archive_item_create_view_with_empty_value(
12891304 assert new_archive_item .values .get (interface = ci_str ).value == "bar"
12901305 with pytest .raises (ObjectDoesNotExist ):
12911306 new_archive_item .values .get (interface = ci_img )
1307+ with pytest .raises (ObjectDoesNotExist ):
1308+ new_archive_item .values .get (interface = ci_file )
12921309
12931310
12941311@pytest .mark .django_db
0 commit comments