How to use the falcon.testing function in falcon

To help you get started, we’ve selected a few falcon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github falconry / falcon / tests / test_request_context.py View on Github external
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']
github falconry / falcon / tests / test_headers.py View on Github external
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
github CyberReboot / poseidon / tests / test_api.py View on Github external
def client():
    return testing.TestClient(api)
github falconry / falcon / tests / test_default_router.py View on Github external
def client():
    return testing.TestClient(falcon.App())
github falconry / falcon-require-https / tests / test_middleware.py View on Github external
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)
github laurivosandi / certidude / tests / test_cli.py View on Github external
def client():
    from certidude.api import certidude_app
    from falcon import testing
    app = certidude_app()
    return testing.TestClient(app)
github falconry / falcon / tests / test_request_context.py View on Github external
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
github admiralobvious / falcon-boilerplate / tests / test_validators.py View on Github external
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
github zeaphoo / cocopot / scripts / bench.py View on Github external
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
github zeaphoo / cocopot / scripts / bench.py View on Github external
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)