Exemplo n.º 1
0
    def test_public_view(self):
        mw = LoginRequiredMiddleware()

        # Authenticated request:
        req = self.factory.get(reverse('login_not_required_view'))
        req.user = self.user
        self.assertEqual(mw.process_view(req, login_not_required_view, [], {}), None)

        # Unauthenticated request:
        req = self.factory.get(reverse('login_not_required_view'))
        req.user = AnonymousUser()
        self.assertEqual(mw.process_view(req, login_not_required_view, [], {}), None)
Exemplo n.º 2
0
    def test_public_view(self):
        mw = LoginRequiredMiddleware()

        # Authenticated request:
        req = self.factory.get(reverse('login_not_required_view'))
        req.user = self.user
        self.assertEqual(mw.process_view(req, login_not_required_view, [], {}), None)

        # Unauthenticated request:
        req = self.factory.get(reverse('login_not_required_view'))
        req.user = AnonymousUser()
        self.assertEqual(mw.process_view(req, login_not_required_view, [], {}), None)
Exemplo n.º 3
0
    def test_statics(self):
        mw = LoginRequiredMiddleware()

        # Unauthenticated request that should have been handled by web server:
        req = self.factory.get(settings.STATIC_URL + 'logo.png')
        req.user = AnonymousUser()
        resp = mw.process_view(req, None, None, None)
        self.assertEqual(resp.status_code, 401)

        # Unauthenticated request that should have been handled by web server:
        req = self.factory.get(settings.MEDIA_URL + 'logo.png')
        req.user = AnonymousUser()
        resp = mw.process_view(req, None, None, None)
        self.assertEqual(resp.status_code, 401)
Exemplo n.º 4
0
    def test_statics(self):
        mw = LoginRequiredMiddleware()

        # Unauthenticated request that should have been handled by web server:
        req = self.factory.get(settings.STATIC_URL + 'logo.png')
        req.user = AnonymousUser()
        resp = mw.process_view(req, None, None, None)
        self.assertEqual(resp.status_code, 401)

        # Unauthenticated request that should have been handled by web server:
        req = self.factory.get(settings.MEDIA_URL + 'logo.png')
        req.user = AnonymousUser()
        resp = mw.process_view(req, None, None, None)
        self.assertEqual(resp.status_code, 401)
Exemplo n.º 5
0
    def test_statics_debug(self):
        # Statics can be served in DEBUG mode though:
        mw = LoginRequiredMiddleware()

        # Unauthenticated request that should have been handled by web server:
        req = self.factory.get(settings.STATIC_URL + 'logo.png')
        req.user = AnonymousUser()
        resp = mw.process_view(req, None, None, None)
        self.assertEqual(resp, None)

        # Unauthenticated request that should have been handled by web server:
        req = self.factory.get(settings.MEDIA_URL + 'logo.png')
        req.user = AnonymousUser()
        resp = mw.process_view(req, None, None, None)
        self.assertEqual(resp, None)
Exemplo n.º 6
0
    def test_ajax(self):
        mw = LoginRequiredMiddleware()

        # Authenticated request:
        req = self.factory.get(reverse('another_view'))
        req.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
        req.user = self.user
        self.assertEqual(mw.process_view(req, None, None, None), None)

        # Unauthenticated request:
        req = self.factory.get(reverse('another_view'))
        req.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
        req.user = AnonymousUser()
        resp = mw.process_view(req, None, None, None)
        self.assertEqual(resp.status_code, 401)
Exemplo n.º 7
0
    def test_login_required(self):
        mw = LoginRequiredMiddleware()

        # Authenticated request:
        req = self.factory.get(reverse('another_view'))
        req.user = self.user
        self.assertEqual(mw.process_view(req, None, None, None), None)

        # Unauthenticated request:
        req = self.factory.get(reverse('another_view'))
        req.user = AnonymousUser()
        resp = mw.process_view(req, None, None, None)
        self.assertEqual(resp.status_code, 200)
        self.assertContains(resp, 'id_username')
        self.assertContains(resp, 'id_password')
Exemplo n.º 8
0
    def test_statics_debug(self):
        # Statics can be served in DEBUG mode though:
        mw = LoginRequiredMiddleware()

        # Unauthenticated request that should have been handled by web server:
        req = self.factory.get(settings.STATIC_URL + 'logo.png')
        req.user = AnonymousUser()
        resp = mw.process_view(req, None, None, None)
        self.assertEqual(resp, None)

        # Unauthenticated request that should have been handled by web server:
        req = self.factory.get(settings.MEDIA_URL + 'logo.png')
        req.user = AnonymousUser()
        resp = mw.process_view(req, None, None, None)
        self.assertEqual(resp, None)
Exemplo n.º 9
0
    def test_ajax(self):
        mw = LoginRequiredMiddleware()

        # Authenticated request:
        req = self.factory.get(reverse('another_view'))
        req.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
        req.user = self.user
        self.assertEqual(mw.process_view(req, None, None, None), None)

        # Unauthenticated request:
        req = self.factory.get(reverse('another_view'))
        req.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
        req.user = AnonymousUser()
        resp = mw.process_view(req, None, None, None)
        self.assertEqual(resp.status_code, 401)
Exemplo n.º 10
0
    def test_login_required(self):
        mw = LoginRequiredMiddleware()

        # Authenticated request:
        req = self.factory.get(reverse('another_view'))
        req.user = self.user
        self.assertEqual(mw.process_view(req, None, None, None), None)

        # Unauthenticated request:
        req = self.factory.get(reverse('another_view'))
        req.user = AnonymousUser()
        resp = mw.process_view(req, None, None, None)
        self.assertEqual(resp.status_code, 200)
        self.assertContains(resp, 'id_username')
        self.assertContains(resp, 'id_password')