示例#1
0
    async def test_send(self, loop, signal, params, param_obj):
        session = Mock()
        trace_request_ctx = Mock()
        callback = Mock(side_effect=asyncio.coroutine(Mock()))

        trace_config = TraceConfig()
        getattr(trace_config, "on_%s" % signal).append(callback)
        trace_config.freeze()
        trace = Trace(
            session, trace_config,
            trace_config.trace_config_ctx(trace_request_ctx=trace_request_ctx))
        await getattr(trace, "send_%s" % signal)(*params)

        callback.assert_called_once_with(
            session, SimpleNamespace(trace_request_ctx=trace_request_ctx),
            param_obj(*params))
示例#2
0
    def test_freeze(self):
        trace_config = TraceConfig()
        trace_config.freeze()

        assert trace_config.on_request_start.frozen
        assert trace_config.on_request_end.frozen
        assert trace_config.on_request_exception.frozen
        assert trace_config.on_request_redirect.frozen
        assert trace_config.on_connection_queued_start.frozen
        assert trace_config.on_connection_queued_end.frozen
        assert trace_config.on_connection_create_start.frozen
        assert trace_config.on_connection_create_end.frozen
        assert trace_config.on_connection_reuseconn.frozen
        assert trace_config.on_dns_resolvehost_start.frozen
        assert trace_config.on_dns_resolvehost_end.frozen
        assert trace_config.on_dns_cache_hit.frozen
        assert trace_config.on_dns_cache_miss.frozen
示例#3
0
    def test_freeze(self):
        trace_config = TraceConfig()
        trace_config.freeze()

        assert trace_config.on_request_start.frozen
        assert trace_config.on_request_end.frozen
        assert trace_config.on_request_exception.frozen
        assert trace_config.on_request_redirect.frozen
        assert trace_config.on_connection_queued_start.frozen
        assert trace_config.on_connection_queued_end.frozen
        assert trace_config.on_connection_create_start.frozen
        assert trace_config.on_connection_create_end.frozen
        assert trace_config.on_connection_reuseconn.frozen
        assert trace_config.on_dns_resolvehost_start.frozen
        assert trace_config.on_dns_resolvehost_end.frozen
        assert trace_config.on_dns_cache_hit.frozen
        assert trace_config.on_dns_cache_miss.frozen
示例#4
0
    def test_freeze(self) -> None:
        trace_config = TraceConfig()
        trace_config.freeze()

        assert trace_config.on_request_start.frozen
        assert trace_config.on_request_chunk_sent.frozen
        assert trace_config.on_response_chunk_received.frozen
        assert trace_config.on_request_end.frozen
        assert trace_config.on_request_exception.frozen
        assert trace_config.on_request_redirect.frozen
        assert trace_config.on_connection_queued_start.frozen
        assert trace_config.on_connection_queued_end.frozen
        assert trace_config.on_connection_create_start.frozen
        assert trace_config.on_connection_create_end.frozen
        assert trace_config.on_connection_reuseconn.frozen
        assert trace_config.on_dns_resolvehost_start.frozen
        assert trace_config.on_dns_resolvehost_end.frozen
        assert trace_config.on_dns_cache_hit.frozen
        assert trace_config.on_dns_cache_miss.frozen
        assert trace_config.on_request_headers_sent.frozen
示例#5
0
    async def test_send(self, loop, signal, params, param_obj):
        session = Mock()
        trace_request_ctx = Mock()
        callback = Mock(side_effect=asyncio.coroutine(Mock()))

        trace_config = TraceConfig()
        getattr(trace_config, "on_%s" % signal).append(callback)
        trace_config.freeze()
        trace = Trace(
            session,
            trace_config,
            trace_config.trace_config_ctx(trace_request_ctx=trace_request_ctx)
        )
        await getattr(trace, "send_%s" % signal)(*params)

        callback.assert_called_once_with(
            session,
            SimpleNamespace(trace_request_ctx=trace_request_ctx),
            param_obj(*params)
        )
示例#6
0
    async def test_send(self, signal, params, param_obj) -> None:
        session = Mock()
        trace_request_ctx = Mock()
        callback = Mock(side_effect=make_mocked_coro(Mock()))

        trace_config = TraceConfig()
        getattr(trace_config, f"on_{signal}").append(callback)
        trace_config.freeze()
        trace = Trace(
            session,
            trace_config,
            trace_config.trace_config_ctx(trace_request_ctx=trace_request_ctx),
        )
        await getattr(trace, f"send_{signal}")(*params)

        callback.assert_called_once_with(
            session,
            SimpleNamespace(trace_request_ctx=trace_request_ctx),
            param_obj(*params),
        )
示例#7
0
 def test_trace_config_ctx_request_ctx(self) -> None:
     trace_request_ctx = Mock()
     trace_config = TraceConfig()
     trace_config_ctx = trace_config.trace_config_ctx(
         trace_request_ctx=trace_request_ctx)
     assert trace_config_ctx.trace_request_ctx is trace_request_ctx
示例#8
0
 def test_trace_config_ctx_factory(self) -> None:
     trace_config = TraceConfig(trace_config_ctx_factory=dict)
     assert isinstance(trace_config.trace_config_ctx(), dict)
示例#9
0
 def test_trace_config_ctx_default(self) -> None:
     trace_config = TraceConfig()
     assert isinstance(trace_config.trace_config_ctx(), SimpleNamespace)
示例#10
0
 def test_trace_config_ctx_request_ctx(self):
     trace_request_ctx = Mock()
     trace_config = TraceConfig()
     trace_config_ctx = trace_config.trace_config_ctx(
         trace_request_ctx=trace_request_ctx)
     assert trace_config_ctx.trace_request_ctx is trace_request_ctx
示例#11
0
 def test_trace_config_ctx_factory(self):
     trace_config = TraceConfig(trace_config_ctx_factory=dict)
     assert isinstance(trace_config.trace_config_ctx(), dict)
示例#12
0
 def test_trace_config_ctx_default(self):
     trace_config = TraceConfig()
     assert isinstance(trace_config.trace_config_ctx(), SimpleNamespace)
示例#13
0
 def test_trace_config_ctx_class(self):
     trace_config = TraceConfig(trace_config_ctx_class=dict)
     assert isinstance(trace_config.trace_config_ctx(), dict)