@@ -25,7 +25,7 @@ def setUp(self):
2525
2626 def test_auth (self ):
2727 """
28- Test that a user can register using the API, login and logout
28+ Test that a user can register using the API, login, whoami and logout
2929 """
3030 # test registration workflow
3131 username , password = 'newuser' , 'password'
@@ -63,6 +63,26 @@ def test_auth(self):
6363 response = self .client .login (username = username , password = password )
6464 self .assertEqual (response , True )
6565
66+ user = User .objects .get (username = username )
67+ token = Token .objects .get (user = user ).key
68+ url = '/v2/auth/whoami'
69+ response = self .client .get (url , HTTP_AUTHORIZATION = 'token {}' .format (token ))
70+ self .assertEqual (response .status_code , 200 )
71+ for key in response .data :
72+ self .assertIn (key , ['id' , 'last_login' , 'is_superuser' , 'username' , 'first_name' ,
73+ 'last_name' , 'email' , 'is_active' , 'is_superuser' , 'is_staff' ,
74+ 'date_joined' , 'groups' , 'user_permissions' ])
75+ expected = {
76+ 'username' : username ,
77+ 'email' : email ,
78+ 'first_name' : first_name ,
79+ 'last_name' : last_name ,
80+ 'is_active' : True ,
81+ 'is_superuser' : False ,
82+ 'is_staff' : False
83+ }
84+ self .assertDictContainsSubset (expected , response .data )
85+
6686 @override_settings (REGISTRATION_MODE = "disabled" )
6787 def test_auth_registration_disabled (self ):
6888 """test that a new user cannot register when registration is disabled."""
0 commit comments