Exemplo n.º 1
0
def client(mock_store):
    api = look.app.create_app(mock_store)
    return testing.TestClient(api)
Exemplo n.º 2
0
def client():
    return testing.TestClient(app)
Exemplo n.º 3
0
def client_dual_2() -> testing.TestClient:
    """Create testing client"""
    return testing.TestClient(app_dual_2)
Exemplo n.º 4
0
 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')
Exemplo n.º 5
0
 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')
Exemplo n.º 6
0
def client(db):
    return testing.TestClient(create_app())
Exemplo n.º 7
0
 def setUp(self):
     self.db_file = tempfile.mktemp()
     self.api = make_api(self.db_file)
     self.client = testing.TestClient(self.api)
Exemplo n.º 8
0
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)
Exemplo n.º 10
0
def client():
    mongoengine.connection.disconnect()
    mongoengine.connect("testdb", host="mongomock://localhost")
    return testing.TestClient(app)
Exemplo n.º 11
0
def client(app_config):
    yield testing.TestClient(create_app(app_config))
Exemplo n.º 12
0
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)
Exemplo n.º 13
0
def client():
    return testing.TestClient(falcon.asgi.App())
Exemplo n.º 14
0
def client():
    return testing.TestClient(init())
Exemplo n.º 15
0
def client(asgi):
    app = create_app(asgi)
    return testing.TestClient(app)
Exemplo n.º 16
0
def client():
    '''API test client'''
    return testing.TestClient(api)
Exemplo n.º 17
0
def client(asgi):
    return testing.TestClient(create_app(asgi))
Exemplo n.º 18
0
def client():
    return testing.TestClient(APP)
def client(resource):
    app = falcon.API()
    app.add_route('/', resource)
    return testing.TestClient(app)
Exemplo n.º 20
0
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)
Exemplo n.º 21
0
 def test_decode_empty_result(self, app):
     client = testing.TestClient(app)
     response = client.simulate_request(path='/')
     assert response.text == ''
Exemplo n.º 22
0
def client():
    configure()
    return testing.TestClient(create_app())
Exemplo n.º 23
0
    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
Exemplo n.º 24
0
    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)
Exemplo n.º 25
0
def client():
    # Assume the hypothetical `myapp` package has a function called
    # `create()` to initialize and return a `falcon.API` instance.
    return testing.TestClient(api)
Exemplo n.º 26
0
def client():
    return testing.TestClient(promenade.start_promenade(disable='keystone'))
Exemplo n.º 27
0
def client_db_1() -> testing.TestClient:
    """Create testing client"""
    return testing.TestClient(app_db_1)
Exemplo n.º 28
0
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)
Exemplo n.º 29
0
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)
Exemplo n.º 30
0
def client(mock_conn, mock_image):
    api = app.create_app(mock_conn, mock_image)
    return testing.TestClient(api)