4141from ietf .utils .models import DumpInfo
4242from ietf .utils .test_utils import TestCase , login_testing_unauthorized , reload_db_objects
4343
44+ from . import Serializer
4445from .ietf_utils import is_valid_token , requires_api_token
4546from .views import EmailIngestionError
4647
@@ -1496,7 +1497,7 @@ def test_good_password(self):
14961497 data = self .response_data (r )
14971498 self .assertEqual (data ["result" ], "success" )
14981499
1499- class TastypieApiTestCase (ResourceTestCaseMixin , TestCase ):
1500+ class TastypieApiTests (ResourceTestCaseMixin , TestCase ):
15001501 def __init__ (self , * args , ** kwargs ):
15011502 self .apps = {}
15021503 for app_name in settings .INSTALLED_APPS :
@@ -1506,7 +1507,7 @@ def __init__(self, *args, **kwargs):
15061507 models_path = os .path .join (os .path .dirname (app .__file__ ), "models.py" )
15071508 if os .path .exists (models_path ):
15081509 self .apps [name ] = app_name
1509- super (TastypieApiTestCase , self ).__init__ (* args , ** kwargs )
1510+ super ().__init__ (* args , ** kwargs )
15101511
15111512 def test_api_top_level (self ):
15121513 client = Client (Accept = 'application/json' )
@@ -1541,6 +1542,21 @@ def test_all_model_resources_exist(self):
15411542 self .assertIn (model ._meta .model_name , list (app_resources .keys ()),
15421543 "There doesn't seem to be any API resource for model %s.models.%s" % (app .__name__ ,model .__name__ ,))
15431544
1545+ def test_serializer_to_etree_handles_nulls (self ):
1546+ """Serializer to_etree() should handle a null character"""
1547+ serializer = Serializer ()
1548+ try :
1549+ serializer .to_etree ("string with no nulls in it" )
1550+ except ValueError :
1551+ self .fail ("serializer.to_etree raised ValueError on an ordinary string" )
1552+ try :
1553+ serializer .to_etree ("string with a \x00 in it" )
1554+ except ValueError :
1555+ self .fail (
1556+ "serializer.to_etree raised ValueError on a string "
1557+ "containing a null character"
1558+ )
1559+
15441560
15451561class RfcdiffSupportTests (TestCase ):
15461562
0 commit comments