Beispiel #1
0
class TermsOfServiceAcceptanceMiddlewareTests(TestCase):
    def setUp(self):
        self.middleware = TermsOfServiceAcceptanceMiddleware()
        self.user = get_user()
        self.agreement = Agreement.objects.create(name=TOS_NAME)
        get_agreement_version(self.agreement)

    def test_process_request_accepted(self):
        self.agreement.accept(self.user)

        if not self.client.login(username=self.user.username, password=PASSWORD):
            self.fail('User login failed!')

        request = RequestFactory().get('/')
        request.user = self.user
        response = self.middleware.process_request(request)

        self.assertIsNone(response)

    def test_process_request_unaccepted(self):
        if not self.client.login(username=self.user.username, password=PASSWORD):
            self.fail('User login failed!')

        request = RequestFactory().get('/?param=xxx')
        request.user = self.user
        response = self.middleware.process_request(request)

        self.assertIs(type(response), HttpResponseRedirect)

        next_param = urlencode({'next': '/?%s' % urlencode({'param': 'xxx'})})
        expected_url = reverse('tos_accept') + '?%s' % next_param
        self.assertEqual(expected_url, response.url)

    def test_ignored_urls(self):
        if not self.client.login(username=self.user.username, password=PASSWORD):
            self.fail('User login failed!')

        ignored_paths = [reverse('tos_accept'), resolve_url(settings.LOGIN_URL), resolve_url(settings.LOGOUT_URL),
                        reverse('tos'), reverse('privacy_policy')]

        for path in ignored_paths:
            request = RequestFactory().get(path)
            request.user = self.user
            self.assertIsNone(self.middleware.process_request(request), 'The path %s should be ignored!' % path)
Beispiel #2
0
 def setUp(self):
     self.middleware = TermsOfServiceAcceptanceMiddleware()
     self.user = get_user()
     self.agreement = Agreement.objects.create(name=TOS_NAME)
     get_agreement_version(self.agreement)