예제 #1
0
    def test_user_agrees_multiple_times(self):
        login_response = self.client.post(reverse('login'), {
            'username': '******',
            'password': '******',
        })

        self.assertTrue(login_response)

        response = self.client.post(reverse('tos_check_tos'),
                                    {'accept': 'accept'})

        self.assertEqual(response.status_code, 302)
        self.assertEqual(
            UserAgreement.objects.filter(user=self.user2).count(), 1)

        response = self.client.post(reverse('tos_check_tos'),
                                    {'accept': 'accept'})

        self.assertEqual(response.status_code, 302)
        self.assertEqual(
            UserAgreement.objects.filter(user=self.user2).count(), 1)

        response = self.client.post(reverse('tos_check_tos'),
                                    {'accept': 'accept'})

        self.assertEqual(response.status_code, 302)
        self.assertEqual(
            UserAgreement.objects.filter(user=self.user2).count(), 1)
예제 #2
0
    def setUp(self):
        # User that has agreed to TOS
        self.user1 = get_runtime_user_model().objects.create_user(
            'user1', '*****@*****.**', 'user1pass')

        # User that has not yet agreed to TOS
        self.user2 = get_runtime_user_model().objects.create_user(
            'user2', '*****@*****.**', 'user2pass')
        self.user3 = get_runtime_user_model().objects.create_user(
            'user3', '*****@*****.**', 'user3pass')

        self.tos1 = TermsOfService.objects.create(
            content="first edition of the terms of service", active=True)
        self.tos2 = TermsOfService.objects.create(
            content="second edition of the terms of service", active=False)
        self.login_url = getattr(settings, 'LOGIN_URL', '/login/')

        UserAgreement.objects.create(terms_of_service=self.tos1,
                                     user=self.user1)

        self.redirect_page = '{0}?{1}={2}'.format(
            reverse('tos_check_tos'),
            REDIRECT_FIELD_NAME,
            reverse('index'),
        )
예제 #3
0
    def test_accept_after_middleware_redirects_properly(self):
        self.client.login(username='******', password='******')

        response = self.client.get(reverse('index'), follow=True)

        self.assertRedirects(response, self.redirect_page)

        # Agree
        response = self.client.post(self.redirect_page, {'accept': 'accept'})

        # Confirm redirects back to the index page
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response.url.replace('http://testserver', ''),
                         str(reverse('index')))
예제 #4
0
    def test_middleware_redirects(self):
        """
        User that hasn't accepted TOS should be redirected to confirm. Also make sure
        confirm works.
        """
        self.client.login(username='******', password='******')
        response = self.client.get(reverse('index'))
        self.assertRedirects(response, self.redirect_page)

        # Make sure confirm works after middleware redirect.
        response = self.client.post(reverse('tos_check_tos'),
                                    {'accept': 'accept'})

        # Confirm redirects.
        self.assertEqual(response.status_code, 302)
예제 #5
0
    def test_reject_agreement(self):

        self.assertFalse(has_user_agreed_latest_tos(self.user2))

        response = self.client.post(
            self.login_url, dict(username='******', password='******'))
        self.assertContains(response, "first edition of the terms of service")
        url = reverse('tos_check_tos')
        response = self.client.post(url, {'accept': 'reject'})

        self.assertFalse(has_user_agreed_latest_tos(self.user2))
예제 #6
0
    def test_skip_for_user(self):
        cache = get_cache(getattr(settings, 'TOS_CACHE_NAME', 'default'))

        key_version = cache.get('django:tos:key_version')

        cache.set('django:tos:skip_tos_check:{0}'.format(str(self.user1.id)),
                  True,
                  version=key_version)

        self.client.login(username='******', password='******')
        response = self.client.get(reverse('index'))

        self.assertEqual(response.status_code, 200)
예제 #7
0
    def test_invalidate_cache_on_accept_fix_redirect_loop(self):
        """
        Make sure accepting doesnt send you right back to tos page.
        """
        self.assertFalse(
            UserAgreement.objects.filter(terms_of_service=self.tos1,
                                         user=self.user2).exists())

        self.client.login(username='******', password='******')
        response = self.client.get(reverse('index'))
        self.assertRedirects(response, self.redirect_page)

        # Make sure confirm works after middleware redirect.
        response = self.client.post(reverse('tos_check_tos'),
                                    {'accept': 'accept'})

        self.assertTrue(
            UserAgreement.objects.filter(terms_of_service=self.tos1,
                                         user=self.user2).exists())

        response = self.client.get(reverse('index'))
        self.assertEqual(response.status_code, 200)

        self.assertIn('index', str(response.content))
예제 #8
0
    def test_bump_new_agreement(self):

        # Change the tos
        self.tos2.active = True
        self.tos2.save()

        # is user1 agreed now?
        self.assertFalse(has_user_agreed_latest_tos(self.user1))

        # user1 agrees again
        response = self.client.post(
            self.login_url, dict(username='******', password='******'))
        self.assertContains(response, "second edition of the terms of service")
        self.assertFalse(has_user_agreed_latest_tos(self.user2))
        url = reverse('tos_check_tos')
        response = self.client.post(url, {'accept': 'accept'})

        self.assertTrue(has_user_agreed_latest_tos(self.user1))
예제 #9
0
 def test_anonymous_user_200(self):
     response = self.client.get(reverse('index'))
     self.assertEqual(response.status_code, 200)
예제 #10
0
 def test_middleware_doesnt_redirect(self):
     """User that has accepted TOS should get 200."""
     self.client.login(username='******', password='******')
     response = self.client.get(reverse('index'))
     self.assertEqual(response.status_code, 200)