@@ -952,7 +952,7 @@ def test_field_validation(self):
952952 ]:
953953 try :
954954 enum_field .clean (bad_value )
955- except ValidationError :
955+ except ValidationError : # pragma: no cover
956956 self .fail (f'non-strict choice field for { enum_field .enum } raised ValidationError on { bad_value } during clean' )
957957
958958 def test_non_strict_field (self ):
@@ -1303,7 +1303,7 @@ def get_enum_val(self, enum, value, null=True, coerce=True, strict=True):
13031303 return enum (float (value ))
13041304 return enum (value )
13051305 except ValueError as err :
1306- if strict :
1306+ if strict : # pragma: no cover
13071307 raise err
13081308
13091309 if value not in {None , '' }:
@@ -1367,7 +1367,7 @@ def verify_form(self, obj, soup):
13671367 coerce = field .coerce ,
13681368 strict = field .strict
13691369 )
1370- except ValueError :
1370+ except ValueError : # pragma: no cover
13711371 self .assertFalse (field .strict )
13721372 value = self .enum_primitive (field .name )(option ['value' ])
13731373 self .assertEqual (str (expected [value ]), option .text )
@@ -1393,8 +1393,8 @@ def verify_form(self, obj, soup):
13931393 self .assertFalse (
13941394 null_opt ,
13951395 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
13981398 self .assertTrue (
13991399 null_opt ,
14001400 f"Expected a null option on field { field .name } , but none was present."
@@ -1489,14 +1489,20 @@ def test_django_filter(self):
14891489 reverse (f'{ self .NAMESPACE } :enum-filter' )
14901490 )
14911491
1492- def do_test_django_filter (self , url ):
1492+ def do_test_django_filter (self , url , skip_non_strict = True ):
14931493 """
14941494 Exhaustively test query parameter permutations based on data
14951495 created in setUp
14961496 """
14971497 client = Client ()
14981498 for attr , val_map in self .values .items ():
14991499 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
15001506 if val in {None , '' }:
15011507 # todo how to query None or empty?
15021508 continue
@@ -2180,7 +2186,8 @@ def field_filter_properties(self):
21802186 if DJANGO_FILTERS_INSTALLED :
21812187 def test_django_filter (self ):
21822188 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
21842191 )
21852192 else :
21862193 pass # pragma: no cover
0 commit comments