Example #1
0
 def test_simple_methods(self):
     self.assertIsNone(
         preflight.check_method(_response(), _request(method="GET")))
     self.assertIsNone(
         preflight.check_method(_response(), _request(method="HEAD")))
     self.assertIsNone(
         preflight.check_method(_response(), _request(method="POST")))
Example #2
0
    def test_non_simple_method(self):
        with self.assertRaises(preflight.AccessControlError) as context:
            preflight.check_method(_response(), _request(method="DELETE"))

        self.assertRegexpMatches(
            context.exception.message,
            "Method '.+' not allowed for resource '.*'")
Example #3
0
    def test_simple_headers(self):
        preflight.check_method(_response(), _request(headers={"Accept": "foo"}))
        preflight.check_method(_response(), _request(headers={"Content-Type": "application/json"}))

        with self.assertRaises(preflight.AccessControlError) as context:
            preflight.check_headers(
                _response(),
                _request(headers={"X-Auth-Token": "foo"}))

        self.assertRegexpMatches(
            context.exception.message,
            "Headers .* not allowed")
Example #4
0
    def test_simple_headers(self):
        preflight.check_method(_response(),
                               _request(headers={"Accept": "foo"}))
        preflight.check_method(
            _response(),
            _request(headers={"Content-Type": "application/json"}))

        with self.assertRaises(preflight.AccessControlError) as context:
            preflight.check_headers(_response(),
                                    _request(headers={"X-Auth-Token": "foo"}))

        self.assertRegexpMatches(context.exception.message,
                                 "Headers .* not allowed")
Example #5
0
    def test_allowed_method():
        headers = {"Access-Control-Allow-Methods": "PUT"}
        preflight_response = _response(headers=headers)
        prepared_request = _request(method="PUT")

        preflight.check_method(preflight_response, prepared_request)
Example #6
0
    def test_non_simple_method(self):
        with self.assertRaises(preflight.AccessControlError) as context:
            preflight.check_method(_response(), _request(method="DELETE"))

        self.assertRegexpMatches(context.exception.message,
                                 "Method '.+' not allowed for resource '.*'")
Example #7
0
    def test_allowed_method():
        headers = {"Access-Control-Allow-Methods": "PUT"}
        preflight_response = _response(headers=headers)
        prepared_request = _request(method="PUT")

        preflight.check_method(preflight_response, prepared_request)
Example #8
0
 def test_simple_methods(self):
     self.assertIsNone(preflight.check_method(_response(), _request(method="GET")))
     self.assertIsNone(preflight.check_method(_response(), _request(method="HEAD")))
     self.assertIsNone(preflight.check_method(_response(), _request(method="POST")))