Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_default_request_context(self):
env = testing.create_environ()
req = Request(env)
req.context.hello = 'World'
assert req.context.hello == 'World'
assert req.context['hello'] == 'World'
req.context['note'] = 'Default Request.context_type used to be dict.'
assert 'note' in req.context
assert hasattr(req.context, 'note')
assert req.context.get('note') == req.context['note']
def test_no_content_length(self, client, status):
client.app.add_route('/xxx', testing.SimpleTestResource(status=status))
result = client.simulate_get('/xxx')
assert 'Content-Length' not in result.headers
assert not result.content
def client():
return testing.TestClient(api)
def client():
return testing.TestClient(falcon.App())
def simulate(protocol, headers=None):
env = testing.create_environ(
method='GET',
scheme=protocol,
path=_TEST_PATH,
query_string='',
headers=headers,
)
srmock = testing.StartResponseMock()
iterable = app(env, srmock)
return testing.Result(iterable, srmock.status, srmock.headers)
def client():
from certidude.api import certidude_app
from falcon import testing
app = certidude_app()
return testing.TestClient(app)
def test_custom_request_context_request_access(self):
def create_context(req):
return {'uri': req.uri}
# Define a Request-alike with a custom context type
class MyCustomRequest(Request):
context_type = create_context
env = testing.create_environ()
req = MyCustomRequest(env)
assert isinstance(req.context, dict)
assert req.context['uri'] == req.uri
def test_both_schemas_validation_failure():
with pytest.raises(HTTPError) as excinfo:
Resource().both_validated(GoodData(), BadData())
assert excinfo.value.title == falcon.HTTP_INTERNAL_SERVER_ERROR
assert excinfo.value.description == "Response data failed validation"
with pytest.raises(HTTPError) as excinfo:
Resource().both_validated(BadData(), GoodData())
msg = "Request data failed validation: data must contain ['message'] properties"
assert excinfo.value.title == falcon.HTTP_BAD_REQUEST
assert excinfo.value.description == msg
client = testing.TestClient(falcon.API())
client.app.add_route("/test", Resource())
result = client.simulate_put("/test", json=BadData.media)
assert result.status_code == 400
def create_bench(name, env):
srmock = helpers.StartResponseMock()
function = name.lower().replace('-', '_')
app = eval('{0}(BODY, HEADERS)'.format(function))
def bench():
app(env, srmock)
if srmock.status != '200 OK':
raise AssertionError(srmock.status + ' != 200 OK')
return bench
def queues_env():
request_headers = {'Content-Type': 'application/json'}
path = ('/v1/852809/queues/0fd4c8c6-bd72-11e2-8e47-db5ebd4c8125'
'/claims/db5ebd4c8125')
qs = 'limit=10&thing=a%20b&x=%23%24'
return helpers.create_environ(path, query_string=qs,
headers=request_headers)