Exemplo n.º 1
0
async def test_patch_aiohttp_session(*, execution):

    patch_aiohttp_session()
    from aiohttp.client import ClientSession
    trace_configs = []
    async with ClientSession(trace_configs=trace_configs):
        assert trace_configs
        config = trace_configs[-1]
        on_request_start = config.on_request_start[-1]

        session = Mock()
        ctx = SimpleNamespace()
        params = Mock()
        params.headers = {}

        assert current_test_stack.top is None

        await on_request_start(session, ctx, params)

        with current_test_stack.push(execution):
            await on_request_start(session, ctx, params)
            assert params.headers
            assert 'LiveCheck-Test-Id' in params.headers

    async with ClientSession(trace_configs=None):
        pass
Exemplo n.º 2
0
 async def __call__(self, request: web.Request, handler: Any) -> Any:
     """Call to handle new web request."""
     related_test = TestExecution.from_headers(request.headers)
     with ExitStack() as stack:
         if related_test:
             stack.enter_context(current_test_stack.push(related_test))
         return await handler(request)
Exemplo n.º 3
0
 def test_on_produce_attach_test_headers__missing(self, *, livecheck, app):
     test = Mock()
     with current_test_stack.push(test):
         with pytest.raises(TypeError):
             livecheck.on_produce_attach_test_headers(
                 sender=app,
                 key=b'k',
                 value=b'v',
                 partition=3,
                 headers=None,
             )
Exemplo n.º 4
0
 async def test_send(self, *, signal, execution):
     with current_test_stack.push(execution):
         signal.case = Mock(app=Mock(bus=Mock(send=AsyncMock())))
         await signal.send('value', key=None, force=True)
         signal.case.app.bus.send.coro.assert_called_once_with(
             key=execution.id,
             value=SignalEvent(
                 signal_name=signal.name,
                 case_name=signal.case.name,
                 key=execution.id,
                 value='value',
             ),
         )
Exemplo n.º 5
0
 def test_on_produce_attach_test_headers(self, *, livecheck, app, execution):
     headers = [("Foo-Bar-Baz", b"moo")]
     original_headers = list(headers)
     with current_test_stack.push(execution):
         livecheck.on_produce_attach_test_headers(
             sender=app,
             key=b"k",
             value=b"v",
             partition=3,
             headers=headers,
         )
         kafka_headers = {
             k: want_bytes(v) for k, v in execution.as_headers().items()
         }
         assert headers == (original_headers + list(kafka_headers.items()))
Exemplo n.º 6
0
 def test_current_test(self, *, livecheck):
     test = Mock()
     assert livecheck.current_test is None
     with current_test_stack.push(test):
         assert livecheck.current_test is test
     assert livecheck.current_test is None