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)
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')
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
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')
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
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)
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
def test_missing_header_is_none(): req = testing.create_asgi_req() assert req.auth is None
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
def test_log_error_not_supported(): req = testing.create_asgi_req() with pytest.raises(NotImplementedError): req.log_error('Boink')