@@ -99,3 +99,49 @@ def test_cancel(self):
9999 response = self .client .delete (url ,
100100 HTTP_AUTHORIZATION = 'token {}' .format (token ))
101101 self .assertEqual (response .status_code , 204 )
102+
103+ def test_passwd (self ):
104+ """Test that a registered user can change the password."""
105+ # test registration workflow
106+ username , password = 'newuser' , 'password'
107+ first_name , last_name = 'Otto' , 'Test'
108+ email = 'autotest@deis.io'
109+ submit = {
110+ 'username' : username ,
111+ 'password' : password ,
112+ 'first_name' : first_name ,
113+ 'last_name' : last_name ,
114+ 'email' : email ,
115+ }
116+ url = '/v1/auth/register'
117+ response = self .client .post (url , json .dumps (submit ), content_type = 'application/json' )
118+ self .assertEqual (response .status_code , 201 )
119+ # change password
120+ url = '/v1/auth/passwd'
121+ user = User .objects .get (username = username )
122+ token = Token .objects .get (user = user ).key
123+ submit = {
124+ 'password' : 'password2' ,
125+ 'new_password' : password ,
126+ }
127+ response = self .client .post (url , json .dumps (submit ), content_type = 'application/json' ,
128+ HTTP_AUTHORIZATION = 'token {}' .format (token ))
129+ self .assertEqual (response .status_code , 400 )
130+ submit = {
131+ 'password' : password ,
132+ 'new_password' : 'password2' ,
133+ }
134+ response = self .client .post (url , json .dumps (submit ), content_type = 'application/json' ,
135+ HTTP_AUTHORIZATION = 'token {}' .format (token ))
136+ self .assertEqual (response .status_code , 200 )
137+ # test login with old password
138+ url = '/v1/auth/login/'
139+ payload = urllib .urlencode ({'username' : username , 'password' : password })
140+ response = self .client .post (url , data = payload ,
141+ content_type = 'application/x-www-form-urlencoded' )
142+ self .assertEqual (response .status_code , 400 )
143+ # test login with new password
144+ payload = urllib .urlencode ({'username' : username , 'password' : 'password2' })
145+ response = self .client .post (url , data = payload ,
146+ content_type = 'application/x-www-form-urlencoded' )
147+ self .assertEqual (response .status_code , 200 )
0 commit comments