Changeset fe6089a in OpenWorkouts-current for ow/tests/views/test_user.py
- Timestamp:
- Dec 21, 2018, 11:11:44 AM (5 years ago)
- Branches:
- current, feature/docs, master
- Children:
- 64e8299
- Parents:
- 31adfa5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ow/tests/views/test_user.py
r31adfa5 rfe6089a 122 122 assert response.location == request.resource_url(root, 'login') 123 123 124 def test_dashboard_redirect_authenticated(self, root ):124 def test_dashboard_redirect_authenticated(self, root, john): 125 125 """ 126 126 Authenticated user accesing the root object, send the user to her … … 131 131 authenticated_userid, which cannot be easily set in the DummyRequest 132 132 """ 133 alt_request = DummyRequest() 133 134 request = Mock() 134 135 request.root = root 135 request.authenticated_userid = 'john'136 request.resource_url .return_value = '/dashboard'136 request.authenticated_userid = str(john.uid) 137 request.resource_url = alt_request.resource_url 137 138 response = user_views.dashboard_redirect(root, request) 138 139 assert isinstance(response, HTTPFound) 139 assert response.location == '/dashboard' 140 assert response.location == request.resource_url(john) 141 # if authenticated_userid is the id of an user that does not exist 142 # anymore, we send the user to the logout page 143 request.authenticated_userid = 'faked-uid' 144 response = user_views.dashboard_redirect(root, request) 145 assert isinstance(response, HTTPFound) 146 assert response.location == request.resource_url(root, 'logout') 140 147 141 148 def test_dashboard(self, dummy_request, john): … … 287 294 assert response['form'].errorlist() == html_error 288 295 assert response['form'].errors_for('email') == [error] 296 297 def test_edit_profile_post_ok_picture_empty_bytes( 298 self, profile_post_request, john): 299 """ 300 POST request with an empty picture, the content of 301 request['POST'].picture is a empty bytes string (b'') which triggers 302 a bug in formencode, we put a fix in place, test that 303 (more in ow.user.views.edit_profile) 304 """ 305 # for the purposes of this test, we can mock the picture 306 picture = Mock() 307 john.picture = picture 308 request = profile_post_request 309 user = john 310 # Mimic what happens when a picture is not provided by the user 311 request.POST['picture'] = b'' 312 response = user_views.edit_profile(user, request) 313 assert isinstance(response, HTTPFound) 314 assert response.location == request.resource_url(user, 'profile') 315 assert user.picture == picture 316 317 def test_edit_profile_post_ok_missing_picture( 318 self, profile_post_request, john): 319 """ 320 POST request without picture 321 """ 322 # for the purposes of this test, we can mock the picture 323 picture = Mock() 324 john.picture = picture 325 request = profile_post_request 326 user = john 327 # No pic is provided in the request POST values 328 del request.POST['picture'] 329 response = user_views.edit_profile(user, request) 330 assert isinstance(response, HTTPFound) 331 assert response.location == request.resource_url(user, 'profile') 332 assert user.picture == picture 333 334 def test_edit_profile_post_ok_nickname(self, profile_post_request, john): 335 """ 336 User with a nickname set saves profile without changing the profile, 337 we have to be sure there are no "nickname already in use" errors 338 """ 339 request = profile_post_request 340 user = john 341 user.nickname = 'mr_jones' 342 # add the nickname, the default post request has not a nickname set 343 request.POST['nickname'] = 'mr_jones' 344 response = user_views.edit_profile(user, request) 345 assert isinstance(response, HTTPFound) 346 assert response.location == request.resource_url(user, 'profile') 289 347 290 348 def test_change_password_get(self, dummy_request, john):
Note: See TracChangeset
for help on using the changeset viewer.