def test_custom_request_context_failure(self):

        # Define a Request-alike with a non-callable custom context type
        class MyCustomRequest(Request):
            context_type = False

        with pytest.raises(TypeError):
            testing.create_asgi_req(req_type=MyCustomRequest)
Exemplo n.º 2
0
    def test_slots_request(self, asgi):
        req = testing.create_asgi_req() if asgi else testing.create_req()

        try:
            req.doesnt = 'exist'
        except AttributeError:
            pytest.fail('Unable to add additional variables dynamically')
Exemplo n.º 3
0
    async def test_direct():
        resource = WrappedRespondersBodyParserAsyncResource()

        req = testing.create_asgi_req()
        resp = create_resp(True)

        await resource.on_get(req, resp, doc)
        assert resource.doc == doc
Exemplo n.º 4
0
    async def test_direct():
        resource = ClassResourceWithURIFieldsAsync()

        req = testing.create_asgi_req()
        resp = create_resp(True)

        await resource.on_get(req, resp, '1', '2')
        assert resource.fields == ('1', '2')
Exemplo n.º 5
0
def test_create_scope_default_ua_override():
    ua = 'curl/7.64.1'

    scope = testing.create_scope(headers={'user-agent': ua})
    assert dict(scope['headers'])[b'user-agent'] == ua.encode()

    req = testing.create_asgi_req(headers={'user-agent': ua})
    assert req.user_agent == ua
Exemplo n.º 6
0
def test_create_scope_default_ua():
    default_ua = 'falcon-client/' + falcon.__version__

    scope = testing.create_scope()
    assert dict(scope['headers'])[b'user-agent'] == default_ua.encode()

    req = testing.create_asgi_req()
    assert req.user_agent == default_ua
    def test_default_request_context(self, ):
        req = testing.create_asgi_req()

        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_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

        req = testing.create_asgi_req(req_type=MyCustomRequest)
        assert isinstance(req.context, dict)
        assert req.context['uri'] == req.uri
    def test_custom_request_context(self):

        # Define a Request-alike with a custom context type
        class MyCustomContextType():
            pass

        class MyCustomRequest(Request):
            context_type = MyCustomContextType

        req = testing.create_asgi_req(req_type=MyCustomRequest)
        assert isinstance(req.context, MyCustomContextType)
Exemplo n.º 10
0
def test_create_scope_default_ua_modify_global():
    default_ua = 'URL/Emacs Emacs/26.3 (x86_64-pc-linux-gnu)'

    prev_default = falcon.testing.helpers.DEFAULT_UA
    falcon.testing.helpers.DEFAULT_UA = default_ua

    try:
        req = testing.create_asgi_req()
        assert req.user_agent == default_ua
    finally:
        falcon.testing.helpers.DEFAULT_UA = prev_default
Exemplo n.º 11
0
def test_missing_header_is_none():
    req = testing.create_asgi_req()
    assert req.auth is None
Exemplo n.º 12
0
def test_missing_server_in_scope():
    req = testing.create_asgi_req(include_server=False, http_version='1.0')
    assert req.host == 'localhost'
    assert req.port == 80
Exemplo n.º 13
0
def test_log_error_not_supported():
    req = testing.create_asgi_req()
    with pytest.raises(NotImplementedError):
        req.log_error('Boink')