How to use the falcon.testing.create_environ 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 swistakm / graceful / tests / test_resources.py View on Github external
class TestSerializer(BaseSerializer):
        one = StringField("one different than two")
        two = StringField("two different than one")

        def validate(self, object_dict, partial=False):
            super().validate(object_dict, partial)
            # possible use case: kind of uniqueness relationship
            if object_dict['one'] == object_dict['two']:
                raise ValidationError("one must be different than two")

    class TestResource(Resource):
        serializer = TestSerializer()

    resource = TestResource()

    env = create_environ(
        body=json.dumps({'one': 'foo', 'two': 'foo'}),
        headers={'Content-Type': 'application/json'},
    )

    with pytest.raises(errors.HTTPBadRequest):
        resource.require_validated(Request(env))
github falconry / falcon / tests / test_request_attrs.py View on Github external
def _test_header_expected_value(self, name, value, attr, expected_value):
        headers = {name: value}
        req = Request(testing.create_environ(headers=headers))
        assert getattr(req, attr) == expected_value
github att-comdev / shipyard / tests / unit / control / common.py View on Github external
def create_req(ctx, body):
    '''creates a falcon request'''
    env = testing.create_environ(
        path='/',
        query_string='',
        protocol='HTTP/1.1',
        scheme='http',
        host='falconframework.org',
        port=None,
        headers={'Content-Type': 'application/json'},
        app='',
        body=body,
        method='POST',
        wsgierrors=None,
        file_wrapper=None)
    req = falcon.Request(env)
    req.context = ctx
    return req
github falconry / falcon / tests / test_request_attrs.py View on Github external
def test_netloc_default_port(self, protocol):
        req = Request(testing.create_environ(
            protocol=protocol,
            app=self.app,
            path='/hello',
            query_string=self.qs,
            headers=self.headers))

        assert req.netloc == 'falconframework.org'
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 falconry / falcon / tests / test_request_attrs.py View on Github external
def setup_method(self, method):
        self.qs = 'marker=deadbeef&limit=10'

        self.headers = {
            'Content-Type': 'text/plain',
            'Content-Length': '4829',
            'Authorization': ''
        }

        self.app = '/test'
        self.path = '/hello'
        self.relative_uri = self.path + '?' + self.qs

        self.req = Request(testing.create_environ(
            app=self.app,
            port=8080,
            path='/hello',
            query_string=self.qs,
            headers=self.headers))

        self.req_noqs = Request(testing.create_environ(
            app=self.app,
            path='/hello',
            headers=self.headers))
github falconry / falcon / tests / test_request_forwarded.py View on Github external
def test_x_forwarded_host():
    req = Request(testing.create_environ(
        host='suchproxy.suchtesting.com',
        path='/languages',
        headers={'X-Forwarded-Host': 'something.org'}
    ))

    assert req.forwarded is None
    assert req.forwarded_host == 'something.org'
    assert req.forwarded_uri != req.uri
    assert req.forwarded_uri == 'http://something.org/languages'
    assert req.forwarded_prefix == 'http://something.org'
    assert req.forwarded_prefix == 'http://something.org'  # Check cached value
github jookies / jasmin / jasmin / vendor / falcon / bench / 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)