def test_signal_called_once_during_normal_flow(self):
        def allow_all(sender, request, **kwargs):
            allow_all.calls += 1
            return True
        allow_all.calls = 0

        with temporary_check_request_hander(allow_all):
            self.client.get('/', HTTP_ORIGIN='http://example.org')

            assert allow_all.calls == 1
    def test_signal_handler_that_returns_true(self):
        def handler(*args, **kwargs):
            return True

        with temporary_check_request_hander(handler):
            resp = self.client.options(
                "/",
                HTTP_ORIGIN="http://example.com",
                HTTP_ACCESS_CONTROL_REQUEST_METHOD="value",
            )
            assert resp.status_code == 200
            assert resp[ACCESS_CONTROL_ALLOW_ORIGIN] == "http://example.com"
Ejemplo n.º 3
0
    def test_signal_called_once_during_normal_flow(self):
        calls = 0

        def allow_all(sender, request, **kwargs):
            nonlocal calls
            calls += 1
            return True

        with temporary_check_request_hander(allow_all):
            self.client.get("/", HTTP_ORIGIN="http://example.org")

            assert calls == 1
Ejemplo n.º 4
0
    def test_signal_handler_that_returns_true(self):
        def handler(*args, **kwargs):
            return True

        with temporary_check_request_hander(handler):
            resp = self.client.options(
                '/',
                HTTP_ORIGIN='http://example.com',
                HTTP_ACCESS_CONTROL_REQUEST_METHOD='value',
            )
            assert resp.status_code == 200
            assert resp[ACCESS_CONTROL_ALLOW_ORIGIN] == 'http://example.com'
    def test_signal_handler_that_returns_false(self):
        def handler(*args, **kwargs):
            return False

        with temporary_check_request_hander(handler):
            resp = self.client.options(
                '/',
                HTTP_ORIGIN='http://example.com',
                HTTP_ACCESS_CONTROL_REQUEST_METHOD='value',
            )

            assert resp.status_code == 200
            assert ACCESS_CONTROL_ALLOW_ORIGIN not in resp
    def test_signal_handler_allow_some_urls_to_everyone(self):
        def allow_api_to_all(sender, request, **kwargs):
            return request.path.startswith("/api/")

        with temporary_check_request_hander(allow_api_to_all):
            resp = self.client.options(
                "/",
                HTTP_ORIGIN="http://example.org",
                HTTP_ACCESS_CONTROL_REQUEST_METHOD="value",
            )
            assert resp.status_code == 200
            assert ACCESS_CONTROL_ALLOW_ORIGIN not in resp

            resp = self.client.options(
                "/api/something/",
                HTTP_ORIGIN="http://example.org",
                HTTP_ACCESS_CONTROL_REQUEST_METHOD="value",
            )
            assert resp.status_code == 200
            assert resp[ACCESS_CONTROL_ALLOW_ORIGIN] == "http://example.org"
Ejemplo n.º 7
0
    def test_signal_handler_allow_some_urls_to_everyone(self):
        def allow_api_to_all(sender, request, **kwargs):
            return request.path.startswith('/api/')

        with temporary_check_request_hander(allow_api_to_all):
            resp = self.client.options(
                '/',
                HTTP_ORIGIN='http://example.org',
                HTTP_ACCESS_CONTROL_REQUEST_METHOD='value',
            )
            assert resp.status_code == 200
            assert ACCESS_CONTROL_ALLOW_ORIGIN not in resp

            resp = self.client.options(
                '/api/something/',
                HTTP_ORIGIN='http://example.org',
                HTTP_ACCESS_CONTROL_REQUEST_METHOD='value',
            )
            assert resp.status_code == 200
            assert resp[ACCESS_CONTROL_ALLOW_ORIGIN] == 'http://example.org'