@@ -301,23 +301,33 @@ def test_empty_surname_field(self):
301
301
class AuthenticationTestCase (rest_framework .test .APITestCase ):
302
302
def setUp (self ):
303
303
self .client = rest_framework .test .APIClient ()
304
+ self .signin_url = django .urls .reverse ('api-user:sign-in' )
304
305
super ().setUp ()
305
306
306
307
def tearDown (self ):
307
308
user .models .User .objects .all ().delete ()
308
309
super ().tearDown ()
309
310
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' : '[email protected] ' }, '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' )
316
320
self .assertEqual (
317
321
response .status_code ,
318
322
rest_framework .status .HTTP_400_BAD_REQUEST ,
319
323
)
320
324
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
+
321
331
def test_signin_invalid_password (self ):
322
332
user .models .User .objects .create_user (
323
333
0 commit comments