Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Open Subsurface Data Universe Software
Platform
Domain Data Mgmt Services
Wellbore
Wellbore Domain Services
Commits
d86f746a
Commit
d86f746a
authored
Jul 09, 2021
by
Alexandre Vincent
Browse files
fix warnings in middleware tests
parent
952b1704
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/unit/clients/clients_middleware_test.py
View file @
d86f746a
...
...
@@ -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
(
...
...
tests/unit/middleware/traces_middleware_test.py
View file @
d86f746a
...
...
@@ -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
Test
Exporter
(
base_exporter
.
Exporter
):
class
Exporter
InTest
(
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
=
Test
Exporter
()
wdms_app
.
trace_exporter
=
Exporter
InTest
()
# 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
=
Test
Exporter
()
wdms_app
.
trace_exporter
=
Exporter
InTest
()
# 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
=
Test
Exporter
()
wdms_app
.
trace_exporter
=
Exporter
InTest
()
# no header -> works fine
response
=
client
.
get
(
build_url
(
"/about"
))
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment