Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def client():
return testing.TestClient(falcon.App())
def client():
return testing.TestClient(api)
def test_default_headers_with_override(self):
app = falcon.App()
resource = testing.SimpleTestResource()
app.add_route('/', resource)
override_before = 'something-something'
override_after = 'something-something'[::-1]
headers = {
'Authorization': 'Bearer XYZ',
'Accept': 'application/vnd.siren+json',
'X-Override-Me': override_before,
}
client = testing.TestClient(app, headers=headers)
client.simulate_get(headers={'X-Override-Me': override_after})
assert resource.captured_req.auth == headers['Authorization']
assert resource.captured_req.accept == headers['Accept']
assert resource.captured_req.get_header('X-Override-Me') == override_after
def cors_client():
app = falcon.App(cors_enable=True)
return testing.TestClient(app)
def client():
app = falcon.App()
tehlogger = LoggerResource()
app.add_route('/logger', tehlogger)
return testing.TestClient(app)
def test_middleware_execution_order(self):
global context
app = falcon.App(independent_middleware=False,
middleware=[ExecutedFirstMiddleware(),
ExecutedLastMiddleware()])
app.add_route(TEST_ROUTE, MiddlewareClassResource())
client = testing.TestClient(app)
response = client.simulate_request(path=TEST_ROUTE)
assert _EXPECTED_BODY == response.json
assert response.status == falcon.HTTP_200
# as the method registration is in a list, the order also is
# tested
expectedExecutedMethods = [
'ExecutedFirstMiddleware.process_request',
'ExecutedLastMiddleware.process_request',
'ExecutedFirstMiddleware.process_resource',
'ExecutedLastMiddleware.process_resource',
'ExecutedLastMiddleware.process_response',
'ExecutedFirstMiddleware.process_response'
]
assert expectedExecutedMethods == context['executed_methods']
def client():
app = falcon.App()
return testing.TestClient(app)
def test_cached_text_in_result(self):
app = falcon.App()
app.add_route('/', testing.SimpleTestResource(body='test'))
client = testing.TestClient(app)
result = client.simulate_get()
assert result.text == result.text
if uri == '/test/42/no-uri-template':
return resource, {'GET': resource}, {}, None
if uri == '/test/42/uri-template/backwards-compat':
return resource, {'GET': resource}, {}
if uri == '/404/backwards-compat':
self.reached_backwards_compat = True
return (None, None, None)
return None
router = CustomRouter()
app = falcon.App(router=router)
client = testing.TestClient(app)
response = client.simulate_request(path='/test/42')
assert response.content == b'{"uri_template": "/test/{id}"}'
response = client.simulate_request(path='/test/42/no-uri-template')
assert response.content == b'{"uri_template": "None"}'
response = client.simulate_request(path='/test/42/uri-template/backwards-compat')
assert response.content == b'{"uri_template": "None"}'
for uri in ('/404', '/404/backwards-compat'):
response = client.simulate_request(path=uri)
assert not response.content
assert response.status == falcon.HTTP_404
assert router.reached_backwards_compat
def _user_logging(headers, extra, expected):
app = falcon.API(middleware=[
falcon_logging.LoggingMiddleware()
])
app.add_route('/test/user/logging', UserResourceRoute(extra, expected))
_set_up_falcon_logging(app)
client = testing.TestClient(app)
_check_expected_response(client.simulate_get('/test/user/logging',
headers=headers))