@@ -155,14 +155,11 @@ def test_whois_enabled(self):
155155 app_settings , "WHOIS_CONFIGURED" , False
156156 ), self .assertRaises (ValidationError ) as context_manager :
157157 org_settings_obj .full_clean ()
158- try :
159- self .assertEqual (
160- context_manager .exception .message_dict ["whois_enabled" ][0 ],
161- "WHOIS_GEOIP_ACCOUNT and WHOIS_GEOIP_KEY must be set "
162- + "before enabling WHOIS feature." ,
163- )
164- except AssertionError :
165- self .fail ("ValidationError message not equal to expected message." )
158+ self .assertEqual (
159+ context_manager .exception .message_dict ["whois_enabled" ][0 ],
160+ "WHOIS_GEOIP_ACCOUNT and WHOIS_GEOIP_KEY must be set "
161+ + "before enabling WHOIS feature." ,
162+ )
166163
167164 with mock .patch .object (app_settings , "WHOIS_CONFIGURED" , True ):
168165 org_settings_obj .full_clean ()
@@ -173,13 +170,13 @@ def test_whois_enabled(self):
173170 org_settings_obj .whois_enabled = True
174171 org_settings_obj .save (update_fields = ["whois_enabled" ])
175172 org_settings_obj .refresh_from_db (fields = ["whois_enabled" ])
176- self .assertEqual ( getattr ( org_settings_obj , " whois_enabled" ), True )
173+ self .assertTrue ( org_settings_obj . whois_enabled )
177174
178175 with self .subTest ("Test setting WHOIS enabled to False" ):
179176 org_settings_obj .whois_enabled = False
180177 org_settings_obj .save (update_fields = ["whois_enabled" ])
181178 org_settings_obj .refresh_from_db (fields = ["whois_enabled" ])
182- self .assertEqual ( getattr ( org_settings_obj , " whois_enabled" ), False )
179+ self .assertFalse ( org_settings_obj . whois_enabled )
183180
184181 with self .subTest (
185182 "Test setting WHOIS enabled to None fallbacks to global setting"
@@ -190,7 +187,7 @@ def test_whois_enabled(self):
190187 org_settings_obj .save (update_fields = ["whois_enabled" ])
191188 org_settings_obj .refresh_from_db (fields = ["whois_enabled" ])
192189 self .assertEqual (
193- getattr ( org_settings_obj , " whois_enabled" ) ,
190+ org_settings_obj . whois_enabled ,
194191 app_settings .WHOIS_ENABLED ,
195192 )
196193
@@ -335,28 +332,22 @@ def test_whois_model_fields_validation(self):
335332
336333 with self .assertRaises (ValidationError ) as context_manager :
337334 self ._create_whois_info (ip_address = "127.0.0.1" )
338- try :
339- self .assertEqual (
340- context_manager .exception .message_dict ["ip_address" ][0 ],
341- "WHOIS information cannot be created for private IP addresses." ,
342- )
343- except AssertionError :
344- self .fail ("ValidationError message not equal to expected message." )
335+ self .assertEqual (
336+ context_manager .exception .message_dict ["ip_address" ][0 ],
337+ "WHOIS information cannot be created for private IP addresses." ,
338+ )
345339
346340 with self .assertRaises (ValidationError ):
347341 self ._create_whois_info (timezone = "a" * 36 )
348342
349343 with self .assertRaises (ValidationError ) as context_manager :
350344 self ._create_whois_info (cidr = "InvalidCIDR" )
351- try :
352- # Not using assertEqual here because we are adding error message raised by
353- # ipaddress module to the ValidationError message.
354- self .assertIn (
355- "Invalid CIDR format: 'InvalidCIDR'" ,
356- context_manager .exception .message_dict ["cidr" ][0 ],
357- )
358- except AssertionError :
359- self .fail ("ValidationError message not equal to expected message." )
345+ # Not using assertEqual here because we are adding error message raised by
346+ # ipaddress module to the ValidationError message.
347+ self .assertIn (
348+ "Invalid CIDR format: 'InvalidCIDR'" ,
349+ context_manager .exception .message_dict ["cidr" ][0 ],
350+ )
360351
361352 with self .assertRaises (ValidationError ):
362353 self ._create_whois_info (asn = "InvalidASNNumber" )
@@ -372,13 +363,10 @@ def test_whois_model_fields_validation(self):
372363 with self .assertRaises (ValidationError ) as context_manager :
373364 point = Point (longitude , latitude , srid = 4326 )
374365 self ._create_whois_info (coordinates = point )
375- try :
376- self .assertEqual (
377- context_manager .exception .message_dict ["coordinates" ][0 ],
378- expected_msg ,
379- )
380- except AssertionError :
381- self .fail ("ValidationError message not equal to expected message." )
366+ self .assertEqual (
367+ context_manager .exception .message_dict ["coordinates" ][0 ],
368+ expected_msg ,
369+ )
382370
383371
384372class TestWHOISTransaction (
0 commit comments