@@ -301,23 +301,33 @@ def test_empty_surname_field(self):
301301class AuthenticationTestCase (rest_framework .test .APITestCase ):
302302 def setUp (self ):
303303 self .client = rest_framework .test .APIClient ()
304+ self .signin_url = django .urls .reverse ('api-user:sign-in' )
304305 super ().setUp ()
305306
306307 def tearDown (self ):
307308 user .models .User .objects .all ().delete ()
308309 super ().tearDown ()
309310
310- def test_signin_missing_fields (self ):
311- response = self .client .post (
312- django .urls .reverse ('api-user:sign-in' ),
313- {},
314- format = 'json' ,
315- )
311+ @parameterized .parameterized .expand (
312+ [
313+ ('missing_password' , {'email' : 'valid@example.com' }, 'password' ),
314+ ('missing_email' , {'password' : 'any' }, 'email' ),
315+ ('empty_data' , {}, ['email' , 'password' ]),
316+ ],
317+ )
318+ def test_missing_required_fields (self , case_name , data , expected_fields ):
319+ response = self .client .post (self .signin_url , data , format = 'json' )
316320 self .assertEqual (
317321 response .status_code ,
318322 rest_framework .status .HTTP_400_BAD_REQUEST ,
319323 )
320324
325+ if isinstance (expected_fields , list ):
326+ for field in expected_fields :
327+ self .assertIn (field , response .data )
328+ else :
329+ self .assertIn (expected_fields , response .data )
330+
321331 def test_signin_invalid_password (self ):
322332 user .models .User .objects .create_user (
323333 email = 'minecraft.digger@gmail.com' ,
0 commit comments