def test_profile_view(factory, user): path = reverse('profile') request = factory.get(path) request.user = user response = profile(request) assert response.status_code == 200 request = factory.post(path) request.user = user response = profile(request) assert response.status_code == 200
def test_no_friends_call_to_action(self): request = self.request.get(reverse('users:profile')) request.user = self.user response = profile(request) self.assertContains(response, 'Expected to see friends to swap votes with?') self.assertContains(response, 'There aren\'t any friends') # Also when we add a friend, it shouldn't change friend = UserFactory.create(profile__state=self.user.profile.state) self.user.profile.friends.add(friend.profile) response = profile(request) self.assertContains(response, 'Expected to see friends to swap votes with?') self.assertContains(response, 'There aren\'t any friends')
def test_profile(self, rf): User.objects.create_user('*****@*****.**', 'password') req = rf.get('profile/') req.session = {} req.user = mixer.blend(User) resp = views.profile(req) assert resp.status_code == 200
def test_anon_user_saved_products_redirect(self): """ Testing the redirection to a 302 error when the anonymous user try to get his saved products """ request = self.factory.get(reverse('saved-products')) request.user = self.user response = profile(request) self.assertEqual(response.status_code, 302)
def test_anon_user_save_redirect(self): """ Testing the redirection to a 302 error when the anonymous user try to save a product """ request = self.factory.get(reverse('pur-beurre-save')) request.user = self.user response = profile(request) self.assertEqual(response.status_code, 302)
def test_user_profile_page_logged_in(self): """ Testing if the logged user get the correct information about himself on profile view """ request = self.factory.get(reverse('profile')) request.user = self.user response = profile(request) self.assertEqual(response.status_code, 200) self.assertContains(response, "*****@*****.**")
def test_paired_call_to_action(self): friend_state = StateFactory(safe_rank=1) friend = UserFactory.create(profile__state=friend_state.name) self.user.profile.friends.add(friend.profile) self.user.profile.paired_with = friend.profile request = self.request.get(reverse('users:profile')) request.user = self.user response = profile(request) self.assertContains(response, 'You pledged to swap your vote')
def test_profile_post(self, rf, client): user = User.objects.create_user('*****@*****.**', 'password') client.force_login(user) req = rf.post('profile/', {}) req.session = {} req.user = mixer.blend(User) req._messages = default_storage(req) resp = views.profile(req) assert resp.status_code == 200
def test_profile_get_status_code(self): user = mixer.blend(User) Profile.objects.create(user=user, image='default.jpg') path = reverse('profile') request = RequestFactory().get(path) request.method = 'GET' request.user = user response = profile(request) assert response.status_code == 200
def test_profile_missing_info(self): """If data is missing, redirect to update_profile""" self.user.profile.state = '' self.user.profile.save() request = self.request.get(reverse('users:profile')) request.user = self.user response = profile(request) self.assertEqual(response.status_code, HTTP_REDIRECT) self.assertTrue(response.has_header('Location')) self.assertEqual(response.get('Location'), reverse('users:update_profile'))
def test_some_matches_call_to_action(self): friend_state = StateFactory(tipping_point_rank=1) friend = UserFactory.create(profile__state=friend_state.name) friend.profile.preferred_candidate = CANDIDATE_STEIN friend.profile.save() self.user.profile.friends.add(friend.profile) request = self.request.get(reverse('users:profile')) request.user = self.user response = profile(request) self.assertContains(response, 'Expected to see more matches?') self.assertContains(response, 'There aren\'t any more friends')
def test_nav(self): """Login-aware context menu has the right links""" request = self.request.get(reverse('users:profile')) request.user = self.user response = profile(request) self.assertContains(response, "View matches") self.assertContains(response, reverse("users:profile")) self.assertContains(response, "Update profile") self.assertContains(response, reverse("users:update_profile")) self.assertContains(response, "Log out") self.assertContains(response, reverse("logout"))
def __call__(self, request): ext = tldextract.extract(request.build_absolute_uri()) try: profile = Profile.objects.get(subdomain=ext.subdomain) except Profile.DoesNotExist: profile = None response = self._get_response(request) if ext.subdomain and request.get_full_path() == '/': kwargs = {} if request.user.profile != profile: kwargs = {'user': profile.id} response = user_views.profile(request, kwargs) return response
def test_profile_post_invalid(self): path = reverse('profile') request = self.factory.post(path, data={ 'username': '******', 'email': 'paulocamargoss_outlook.com', 'image': '', }) request.user = mixer.blend(User) middleware = SessionMiddleware() middleware.process_request(request) request.session.save() middleware = MessageMiddleware() middleware.process_request(request) request.session.save() response = profile(request) assert response.status_code == 200
def test_anon_user_save_redirect(self): request = self.factory.get(reverse('pur-beurre-save')) request.user = self.user response = profile(request) # User should be redirected to log in page: self.assertEqual(response.status_code, 302)
def test_anon_user_profile_redirect(self): request = self.factory.get(reverse('profile')) request.user = self.user response = profile(request) self.assertEqual(response.status_code, 302)
def test_user_profile_page_logged_in(self): request = self.factory.get(reverse('profile')) request.user = self.user response = profile(request) self.assertEqual(response.status_code, 200) self.assertContains(response, "*****@*****.**")
def test_profile_get(self): path = reverse('profile') request = self.factory.get(path) request.user = mixer.blend(User) response = profile(request) assert response.status_code == 200
def test_display_profile_not_ok(self): request = self.factory.get(reverse("profile")) request.user = AnonymousUser() response = profile(request) self.assertEqual(response.status_code, 302)
def test_display_profile_ok(self): request = self.factory.get(reverse("profile")) request.user = self.user response = profile(request) self.assertEqual(response.status_code, 200)
def test_complete_registration_pixel(self): request = self.request.get(reverse('users:new_profile')) request.user = self.user response = profile(request, new=True) self.assertContains(response, 'CompleteRegistration')
def test_user_saved_page_logged_in(self): request = self.factory.get(reverse('saved-movies')) request.user = self.user response = profile(request) self.assertEqual(response.status_code, 200) self.assertContains(response, "*****@*****.**")
def test_profile_unauthenticated(self): path = reverse('profile') request = self.factory.get(path) request.user = AnonymousUser() response = profile(request) assert 'login' in response.url