コード例 #1
0
ファイル: tests.py プロジェクト: mtyaka/django-splash
 def setUp(self):
     """
     Init
     """
     self.splash_middleware = SplashMiddleware()
     self.request_factory = RequestFactory(SERVER_NAME='example.org')
     SplashConfig().save()
コード例 #2
0
    def test_no_cookie(self):
        """
        No cookie present should redirect
        """
        SplashConfig(enabled=True, ).save()

        response = self.client.get(self.home_url)
        self.assert_redirect(response, 'http://edx.org')
コード例 #3
0
ファイル: tests.py プロジェクト: mtyaka/django-splash
 def test_set_non_absolute_url(self):
     """
     Make sure the URL is absolute, to make sure we can compare it
     to the current URL
     Should not validate with a non-absolute URL
     """
     config = SplashConfig(redirect_url='/somewhere')
     self.assertRaises(ValidationError, config.save)
コード例 #4
0
    def test_path_not_equal(self):
        """
        When the URL of the redirection not equal it will redirect.
        """
        SplashConfig(enabled=True, redirect_url='http://edx.org').save()

        response = self.client.get(self.home_url)
        self.assert_redirect(response, 'http://edx.org')
コード例 #5
0
ファイル: tests.py プロジェクト: mtyaka/django-splash
    def test_no_cookie(self):
        """
        No cookie present should redirect
        """
        SplashConfig(enabled=True, ).save()

        request = self.build_request()
        response = self.splash_middleware.process_request(request)
        self.assert_redirect(response, 'http://edx.org')
コード例 #6
0
    def test_wrong_cookie_different_cookie_name(self):
        SplashConfig(
            enabled=True,
            cookie_name='othername',
            cookie_allowed_values='ok1,ok2',
        ).save()

        self.client.cookies = cookies.SimpleCookie({'othername': 'not'})
        response = self.client.get(self.home_url)
        self.assert_redirect(response, 'http://edx.org')
コード例 #7
0
    def test_redirect_with_different_current_url(self):
        """
         When the URL of the redirection is the different from current URL,
         redirect it.
        """
        # to avoid the direct call and replace with test server doing this in two steps.
        SplashConfig(enabled=True, redirect_url='http://edx.org').save()

        response = self.client.get('http://testserver/home')
        self.assert_redirect(response, 'http://edx.org')
コード例 #8
0
    def test_affected_path(self):
        """
        Affected paths should never be redirected - custom value
        """
        SplashConfig(
            enabled=True,
            unaffected_url_paths='/home,/my/url/',
        ).save()

        self.assert_no_redirect()
コード例 #9
0
ファイル: tests.py プロジェクト: mtyaka/django-splash
    def test_right_cookie(self):
        """
        A cookie value corresponding to one of the allowed ones should not redirect
        """
        SplashConfig(enabled=True,
                     cookie_allowed_values='ok1,ok2',
                     redirect_url='http://example.com').save()

        request = self.build_request(cookies={'edx_splash_screen': 'ok2'})
        response = self.splash_middleware.process_request(request)
        self.assertEquals(response, None)
コード例 #10
0
ファイル: tests.py プロジェクト: mtyaka/django-splash
    def test_redirect_to_current_url(self):
        """
        When the URL of the redirection is the same as the current URL,
        we shouldn't be redirected
        """
        SplashConfig(enabled=True,
                     redirect_url='http://example.org/somewhere').save()

        request = self.build_request()
        response = self.splash_middleware.process_request(request)
        self.assertEquals(response, None)
コード例 #11
0
ファイル: tests.py プロジェクト: mtyaka/django-splash
    def test_wrong_cookie(self):
        """
        A cookie value different from the allowed ones should redirect
        """
        SplashConfig(enabled=True,
                     cookie_allowed_values='ok1,ok2',
                     redirect_url='http://example.com').save()

        request = self.build_request(cookies={'edx_splash_screen': 'not ok'})
        response = self.splash_middleware.process_request(request)
        self.assert_redirect(response, 'http://example.com')
コード例 #12
0
    def test_right_cookie(self):
        """
        A cookie value corresponding to one of the allowed ones should not redirect
        """
        SplashConfig(enabled=True,
                     cookie_allowed_values='ok1,ok2',
                     redirect_url='http://example.com').save()

        self.client.cookies = cookies.SimpleCookie(
            {'edx_splash_screen': 'ok1'})
        self.assert_no_redirect()
コード例 #13
0
ファイル: tests.py プロジェクト: mtyaka/django-splash
    def test_unaffected_path(self):
        """
        Unaffected paths should never be redirected - custom value
        """
        SplashConfig(
            enabled=True,
            unaffected_url_paths='/test1,/my/url/',
        ).save()

        request = self.build_request(url_path='/my/url/')
        response = self.splash_middleware.process_request(request)
        self.assertEquals(response, None)
コード例 #14
0
ファイル: tests.py プロジェクト: mtyaka/django-splash
    def test_unaffected_user(self):
        """
        Unaffected users should never be redirected
        """
        SplashConfig(
            enabled=True,
            unaffected_usernames='user1',
        ).save()

        request = self.build_request(username='******')
        response = self.splash_middleware.process_request(request)
        self.assertEquals(response, None)
コード例 #15
0
ファイル: tests.py プロジェクト: mtyaka/django-splash
    def test_not_unaffected_user(self):
        """
        Setting unaffected users should still redirect other users
        """
        SplashConfig(
            enabled=True,
            unaffected_usernames='user1',
        ).save()

        request = self.build_request(username='******')
        response = self.splash_middleware.process_request(request)
        self.assert_redirect(response, 'http://edx.org')
コード例 #16
0
    def test_unaffected_user(self):
        """
        Unaffected users should never be redirected
        """
        SplashConfig(
            enabled=True,
            unaffected_usernames='user1',
        ).save()

        user = User.objects.create_user('user1', '*****@*****.**', PASSWORD)
        self.client.login(username=user.username, password=PASSWORD)
        self.assert_no_redirect()
コード例 #17
0
    def test_affected_wildcard_path(self):
        """
        Unaffected wildcard paths should never be redirected - custom value
        """
        SplashConfig(
            enabled=True,
            unaffected_url_paths=
            '/test1/*, /test2/*/after, /test3/*/before/*/after',
        ).save()

        # These paths match and should NOT redirect.
        response = self.client.get(self.home_url)
        self.assert_redirect(response, 'http://edx.org')
コード例 #18
0
ファイル: tests.py プロジェクト: mtyaka/django-splash
    def test_right_cookie_different_cookie_name(self):
        """
        Different cookie name
        A cookie value corresponding to one of the allowed ones should not redirect
        """
        SplashConfig(
            enabled=True,
            cookie_name='othername',
        ).save()

        request = self.build_request(cookies={'othername': 'seen'})
        response = self.splash_middleware.process_request(request)
        self.assertEquals(response, None)
コード例 #19
0
    def test_not_unaffected_user(self):
        """
        Setting unaffected users should still redirect other users
        """
        SplashConfig(
            enabled=True,
            unaffected_usernames='user1',
        ).save()

        user = User.objects.create_user('user2', '*****@*****.**', PASSWORD)
        self.client.login(username=user.username, password=PASSWORD)
        response = self.client.get(self.home_url)
        self.assert_redirect(response, 'http://edx.org')
コード例 #20
0
ファイル: tests.py プロジェクト: mtyaka/django-splash
    def test_wrong_cookie_different_cookie_name(self):
        """
        Different cookie name
        A cookie value different from the allowed ones should redirect
        """
        SplashConfig(
            enabled=True,
            cookie_name='othername',
        ).save()

        request = self.build_request(cookies={'othername': 'not ok'})
        response = self.splash_middleware.process_request(request)
        self.assert_redirect(response, 'http://edx.org')
コード例 #21
0
    def test_redirect_to_current_url(self):
        """
          When the URL of the redirection is the same as the current URL,
          we shouldn't be redirected
        """
        # to avoid the direct call and replace with test server doing this in two steps.
        SplashConfig(enabled=True, redirect_url='http://edx.org').save()

        # Above save method url triggers the validation error http://testserver/home
        # update this url to match the testserver url.

        SplashConfig.objects.filter(id=1).update(
            redirect_url='http://testserver/home')  # pylint: disable=no-member
        self.assert_no_redirect()
コード例 #22
0
ファイル: test_splash.py プロジェクト: Jawayria/django-splash
    def test_unaffected_wildcard_path(self):
        """
        Unaffected wildcard paths should never be redirected - custom value
        """
        SplashConfig(
            enabled=True,
            unaffected_url_paths=
            '/test1/*, /test2/*/after, /test3/*/before/*/after',
        ).save()

        # These paths match and should NOT redirect.
        request = self.build_request(url_path='/test1/')
        response = self.splash_middleware.process_request(request)
        assert response is None
        request = self.build_request(url_path='/test1/something')
        response = self.splash_middleware.process_request(request)
        assert response is None
        request = self.build_request(url_path='/test1/something/else')
        response = self.splash_middleware.process_request(request)
        assert response is None
        request = self.build_request(url_path='/test2/something/after')
        response = self.splash_middleware.process_request(request)
        assert response is None
        request = self.build_request(
            url_path='/test3/something/before/something/else/after')
        response = self.splash_middleware.process_request(request)
        assert response is None

        # These paths don't match and should redirect.
        request = self.build_request(url_path='/test2/')
        response = self.splash_middleware.process_request(request)
        self.assert_redirect(response, 'http://edx.org')
        request = self.build_request(url_path='/test2/after')
        response = self.splash_middleware.process_request(request)
        self.assert_redirect(response, 'http://edx.org')
        request = self.build_request(url_path='/test3/before/after')
        response = self.splash_middleware.process_request(request)
        self.assert_redirect(response, 'http://edx.org')
        request = self.build_request(
            url_path='/test3/something/before/something/after/more')
        response = self.splash_middleware.process_request(request)
        self.assert_redirect(response, 'http://edx.org')