Esempio n. 1
0
 def test_unauth_user_is_redirected_to_login(self, rf, unauth_user):
     """ Asserts an unauth user cannot access a non-existent `profile` """
     kwargs = {'username': '******'}
     path = reverse('blog:users:profile', kwargs=kwargs)
     request = rf.get(path)
     apps_helpers.add_middlewares(request)
     request.user = unauth_user
     response = ProfileView.as_view()(request, **kwargs)
     assert response.status_code == 302, 'Should be redirected'
     assert resolve_url(settings.LOGIN_URL) in response.url
Esempio n. 2
0
 def test_unauth_user_cannot_access(self, rf, auth_user, unauth_user):
     """
     Asserts `profile update` view inaccessible by unauthenticated user
     """
     kwargs = {'username': auth_user.username}
     path = reverse('blog:users:profile_update', kwargs=kwargs)
     request = rf.get(path)
     request.user = unauth_user
     apps_helpers.add_middlewares(request)
     response = ProfileUpdateView.as_view()(request, **kwargs)
     assert response.status_code == 302, 'Should return with an `redirect` status code'
     assert '/login/' in response.url, 'Should redirect to login page'
Esempio n. 3
0
 def test_another_user_cannot_access(self, rf, auth_user, li_sec_user):
     """
     Asserts `profile update` view inaccessible by unauthenticated user
     """
     kwargs = {'username': auth_user.username}
     path = reverse('blog:users:profile_update', kwargs=kwargs)
     request = rf.get(path)
     request.user = li_sec_user
     apps_helpers.add_middlewares(request)
     response = ProfileUpdateView.as_view()(request, **kwargs)
     assert response.status_code == 302, 'Mixin should yield permanent redirect'
     assert resolve_url(settings.LOGIN_URL
                        ) in response.url, 'Should redirect to login page'
Esempio n. 4
0
 def test_form_valid(self, rf, django_user_model, sample_user_data):
     """
     Asserts that a form with valid data is considered valid and
     redirects the user accordingly
     """
     django_user_model.objects.create(username='******', id=2)
     kwargs = sample_user_data
     request = rf.post(self.path, kwargs)
     apps_helpers.add_middlewares(request)
     response = UserRegisterView.as_view()(request, **kwargs)
     assert response.status_code == 302, 'Should be redirected'
     assert '/blog/' in response.url, 'Should redirect to `blog` home screen'
     assert Profile.objects.count(
     ) == 2, 'Should have 2 objects in the database'