def client(mock_store): api = look.app.create_app(mock_store) return testing.TestClient(api)
def client(): return testing.TestClient(app)
def client_dual_2() -> testing.TestClient: """Create testing client""" return testing.TestClient(app_dual_2)
def test_path_must_start_with_slash(self, app): app.add_route('/', testing.SimpleTestResource()) client = testing.TestClient(app) with pytest.raises(ValueError): client.simulate_get('foo')
def test_query_string_no_question(self, app): app.add_route('/', testing.SimpleTestResource()) client = testing.TestClient(app) with pytest.raises(ValueError): client.simulate_get(query_string='?x=1')
def client(db): return testing.TestClient(create_app())
def setUp(self): self.db_file = tempfile.mktemp() self.api = make_api(self.db_file) self.client = testing.TestClient(self.api)
def client(): return testing.TestClient(webhook.app)
def client_fixture(sessions_resource: SessionsResource, session_path: str) -> testing.TestClient: api = API() api.add_route(session_path, sessions_resource) return testing.TestClient(api)
def client(): mongoengine.connection.disconnect() mongoengine.connect("testdb", host="mongomock://localhost") return testing.TestClient(app)
def client(app_config): yield testing.TestClient(create_app(app_config))
def custom_http_client(asgi, request, cleanup_constants, resource_things): falcon.constants.COMBINED_METHODS += FALCON_CUSTOM_HTTP_METHODS app = create_app(asgi) app.add_route('/things', resource_things) return testing.TestClient(app)
def client(): return testing.TestClient(falcon.asgi.App())
def client(): return testing.TestClient(init())
def client(asgi): app = create_app(asgi) return testing.TestClient(app)
def client(): '''API test client''' return testing.TestClient(api)
def client(asgi): return testing.TestClient(create_app(asgi))
def client(): return testing.TestClient(APP)
def client(resource): app = falcon.API() app.add_route('/', resource) return testing.TestClient(app)
def cors_client(asgi): # NOTE(kgriffs): Disable wrapping to test that built-in middleware does # not require it (since this will be the case for non-test apps). with disable_asgi_non_coroutine_wrapping(): app = create_app(asgi, cors_enable=True) return testing.TestClient(app)
def test_decode_empty_result(self, app): client = testing.TestClient(app) response = client.simulate_request(path='/') assert response.text == ''
def client(): configure() return testing.TestClient(create_app())
def test_cached_text_in_result(self, app): app.add_route('/', testing.SimpleTestResource(body='test')) client = testing.TestClient(app) result = client.simulate_get() assert result.text == result.text
def test_api_update_reference_009(server): """Update reference with PUT request. Send PUT /references/{id} to replace existing resource with digest. The PUT sets all but the mandatory ``links`` attribute to empty values. """ storage = { 'data': [ Storage.gitlog ] } storage['data'][0]['brief'] = '' storage['data'][0]['description'] = '' storage['data'][0]['name'] = '' storage['data'][0]['groups'] = () storage['data'][0]['tags'] = () storage['data'][0]['source'] = '' storage['data'][0]['versions'] = () storage['data'][0]['filename'] = '' storage['data'][0]['created'] = Content.GITLOG_TIME storage['data'][0]['updated'] = Content.PYTEST_TIME storage['data'][0]['digest'] = '54c493ade0f808e3d1b16bb606484a51bb0f7eb9c0592c46aea5196bd891881c' request_body = { 'data': { 'type': 'reference', 'attributes': { 'links': storage['data'][0]['links'], 'brief': '', 'description': '', 'name': '', 'groups': (), 'tags': (), 'source': '', 'versions': (), 'filename': '' } } } expect_headers = { 'content-type': 'application/vnd.api+json; charset=UTF-8', 'content-length': '634' } expect_body = { 'links': { 'self': 'http://falconframework.org/api/snippy/rest/references/' + Reference.GITLOG_UUID }, 'data': { 'type': 'reference', 'id': storage['data'][0]['uuid'], 'attributes': storage['data'][0] } } result = testing.TestClient(server.server.api).simulate_put( path='/api/snippy/rest/references/5c2071094dbfaa33', headers={'accept': 'application/vnd.api+json; charset=UTF-8'}, body=json.dumps(request_body)) assert result.status == falcon.HTTP_200 assert result.headers == expect_headers Content.assert_restapi(result.json, expect_body) Content.assert_storage(storage)
def client(): # Assume the hypothetical `myapp` package has a function called # `create()` to initialize and return a `falcon.API` instance. return testing.TestClient(api)
def client(): return testing.TestClient(promenade.start_promenade(disable='keystone'))
def client_db_1() -> testing.TestClient: """Create testing client""" return testing.TestClient(app_db_1)
def test_multiple_events(): expected_result_text = ('data: ketchup\n' '\n' 'event: condiment\n' 'data: mustard\n' '\n' 'event: condiment\n' 'id: 1234\n' 'data: mayo\n' '\n' 'event: topping\n' 'id: 5678\n' 'retry: 100\n' 'data: onions\n' '\n' ': Serve with chips.\n' 'retry: 100\n' 'data: guacamole \u1F951\n' '\n' 'retry: 100\n' 'data: {"condiment": "salsa"}\n' '\n') class SomeResource: async def on_get(self, req, resp): async def emitter(): for event in [ SSEvent(data=b'ketchup'), SSEvent(data=b'mustard', event='condiment'), SSEvent(data=b'mayo', event='condiment', event_id='1234'), SSEvent(data=b'onions', event='topping', event_id='5678', retry=100), SSEvent(text='guacamole \u1F951', retry=100, comment='Serve with chips.'), SSEvent(json={'condiment': 'salsa'}, retry=100), ]: yield event await asyncio.sleep(0.001) resp.sse = emitter() resource = SomeResource() app = App() app.add_route('/', resource) client = testing.TestClient(app) async def _test(): async with client as conductor: # NOTE(kgriffs): Single-shot test will only allow the first # one or two events since a client disconnect will be emitted # into the app immediately. result = await conductor.simulate_get() assert expected_result_text.startswith(result.text) async with conductor.simulate_get_stream() as sr: event_count = 0 result_text = '' while True: chunk = (await sr.stream.read()).decode() if not chunk: continue result_text += chunk event_count += len(chunk.strip().split('\n\n')) if 'salsa' in chunk: break assert not (await sr.stream.read()) assert event_count == 6 assert result_text == expected_result_text falcon.async_to_sync(_test)
def client_udp_logger_2() -> testing.TestClient: """Create testing client""" from .Syslog.app import app_udp_syslog_logger_2 # pylint: disable=import-outside-toplevel return testing.TestClient(app_udp_syslog_logger_2)
def client(mock_conn, mock_image): api = app.create_app(mock_conn, mock_image) return testing.TestClient(api)