@@ -952,7 +952,7 @@ def test_field_validation(self):
952
952
]:
953
953
try :
954
954
enum_field .clean (bad_value )
955
- except ValidationError :
955
+ except ValidationError : # pragma: no cover
956
956
self .fail (f'non-strict choice field for { enum_field .enum } raised ValidationError on { bad_value } during clean' )
957
957
958
958
def test_non_strict_field (self ):
@@ -1303,7 +1303,7 @@ def get_enum_val(self, enum, value, null=True, coerce=True, strict=True):
1303
1303
return enum (float (value ))
1304
1304
return enum (value )
1305
1305
except ValueError as err :
1306
- if strict :
1306
+ if strict : # pragma: no cover
1307
1307
raise err
1308
1308
1309
1309
if value not in {None , '' }:
@@ -1367,7 +1367,7 @@ def verify_form(self, obj, soup):
1367
1367
coerce = field .coerce ,
1368
1368
strict = field .strict
1369
1369
)
1370
- except ValueError :
1370
+ except ValueError : # pragma: no cover
1371
1371
self .assertFalse (field .strict )
1372
1372
value = self .enum_primitive (field .name )(option ['value' ])
1373
1373
self .assertEqual (str (expected [value ]), option .text )
@@ -1393,8 +1393,8 @@ def verify_form(self, obj, soup):
1393
1393
self .assertFalse (
1394
1394
null_opt ,
1395
1395
f"An unexpected null option is present on { field .name } "
1396
- ) # pragma: no cover
1397
- elif field .blank :
1396
+ )
1397
+ elif field .blank : # pragma: no cover
1398
1398
self .assertTrue (
1399
1399
null_opt ,
1400
1400
f"Expected a null option on field { field .name } , but none was present."
@@ -1489,14 +1489,20 @@ def test_django_filter(self):
1489
1489
reverse (f'{ self .NAMESPACE } :enum-filter' )
1490
1490
)
1491
1491
1492
- def do_test_django_filter (self , url ):
1492
+ def do_test_django_filter (self , url , skip_non_strict = True ):
1493
1493
"""
1494
1494
Exhaustively test query parameter permutations based on data
1495
1495
created in setUp
1496
1496
"""
1497
1497
client = Client ()
1498
1498
for attr , val_map in self .values .items ():
1499
1499
for val , objs in val_map .items ():
1500
+ if (
1501
+ skip_non_strict and not
1502
+ self .MODEL_CLASS ._meta .get_field (attr ).strict and not
1503
+ any ([val == en for en in self .MODEL_CLASS ._meta .get_field (attr ).enum ])
1504
+ ):
1505
+ continue
1500
1506
if val in {None , '' }:
1501
1507
# todo how to query None or empty?
1502
1508
continue
@@ -2180,7 +2186,8 @@ def field_filter_properties(self):
2180
2186
if DJANGO_FILTERS_INSTALLED :
2181
2187
def test_django_filter (self ):
2182
2188
self .do_test_django_filter (
2183
- reverse (f'{ self .NAMESPACE } :enum-filter-symmetric' )
2189
+ reverse (f'{ self .NAMESPACE } :enum-filter-symmetric' ),
2190
+ skip_non_strict = False
2184
2191
)
2185
2192
else :
2186
2193
pass # pragma: no cover
0 commit comments