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")))
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 '.*'")
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")
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")
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)
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 '.*'")
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")))