Commit d86f746a authored by Alexandre Vincent's avatar Alexandre Vincent
Browse files

fix warnings in middleware tests

parent 952b1704
......@@ -24,18 +24,17 @@ async def test_fwd_correlation_id_to_outgoing_request_to_storage(ctx_fixture: Co
storage_url = "http://example.com" # well formed url required
expected_correlation_id = 'some-correlation-id'
storage_client = make_storage_record_client(storage_url)
httpx_mock.add_response(match_headers={'correlation-id': expected_correlation_id})
ctx = ctx_fixture.with_correlation_id(expected_correlation_id).with_auth("foobar")
Context.set_current(ctx)
# safety: make sure no methods on tracer have been called yet
assert ctx.tracer.method_calls == []
# force to use endpoint which does not return a response to skip model validation
response = await storage_client.delete_record(id="123", data_partition_id="test")
assert response is not None
async with make_storage_record_client(storage_url) as storage_client:
httpx_mock.add_response(match_headers={'correlation-id': expected_correlation_id})
# force to use endpoint which does not return a response to skip model validation
response = await storage_client.delete_record(id="123", data_partition_id="test")
assert response is not None
# make sure correlation-id is traced when doing a request to storage
ctx.tracer.add_attribute_to_current_span.assert_any_call(
......@@ -48,18 +47,17 @@ async def test_fwd_correlation_id_to_outgoing_request_to_search(ctx_fixture: Con
storage_url = "http://example.com" # well formed url required
expected_correlation_id = 'some-correlation-id'
search_client = make_search_client(storage_url)
httpx_mock.add_response(match_headers={'correlation-id': expected_correlation_id})
ctx = ctx_fixture.with_correlation_id(expected_correlation_id).with_auth("foobar")
Context.set_current(ctx)
# safety: make sure no methods on tracer have been called yet
assert ctx.tracer.method_calls == []
# force to use endpoint which does not return a response to skip model validation
response = await search_client.delete_index(kind="kind", data_partition_id="test")
assert response is not None
async with make_search_client(storage_url) as search_client:
httpx_mock.add_response(match_headers={'correlation-id': expected_correlation_id})
# force to use endpoint which does not return a response to skip model validation
response = await search_client.delete_index(kind="kind", data_partition_id="test")
assert response is not None
# make sure correlation-id is traced when doing a request to search
ctx.tracer.add_attribute_to_current_span.assert_any_call(
......
......@@ -22,7 +22,7 @@ from tests.unit.test_utils import NopeLogger
from unittest.mock import MagicMock
# Initialize traces exporter in app with a custom one to allow validating our traces
class TestExporter(base_exporter.Exporter):
class ExporterInTest(base_exporter.Exporter):
def __init__(self) -> None:
self.exported = []
......@@ -52,7 +52,7 @@ def build_url(path: str):
def test_about_call_creates_correlation_id_if_absent(client: TestClient):
# Initialize traces exporter in app, like it is in app's startup_event
wdms_app.trace_exporter = TestExporter()
wdms_app.trace_exporter = ExporterInTest()
# no header -> works fine
response = client.get(build_url("/about"))
......@@ -62,11 +62,12 @@ def test_about_call_creates_correlation_id_if_absent(client: TestClient):
assert len(wdms_app.trace_exporter.exported) == 1 # one call => one export
spandata = wdms_app.trace_exporter.exported[0]
assert 'correlation-id' in spandata.attributes.keys()
assert spandata.attributes['correlation-id'] is not None
def test_about_call_traces_existing_correlation_id(client: TestClient):
# Initialize traces exporter in app, like it is in app's startup_event
wdms_app.trace_exporter = TestExporter()
wdms_app.trace_exporter = ExporterInTest()
# no header -> works fine
response = client.get(build_url("/about"), headers={'correlation-id': 'some correlation id'})
......@@ -81,7 +82,7 @@ def test_about_call_traces_existing_correlation_id(client: TestClient):
def test_about_call_traces_existing_data_partition_id(client: TestClient):
# Initialize traces exporter in app, like it is in app's startup_event
wdms_app.trace_exporter = TestExporter()
wdms_app.trace_exporter = ExporterInTest()
# no header -> works fine
response = client.get(build_url("/about"))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment