Skip to content

Commit e2673b1

Browse files
committed
Update test
1 parent 6a97ff7 commit e2673b1

1 file changed

Lines changed: 21 additions & 16 deletions

File tree

tests/unit_tests/service/test_main.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from unittest import mock
2-
from unittest.mock import Mock
2+
from unittest.mock import Mock, call
33

44
import pytest
55
from fastapi import FastAPI, Request
@@ -29,31 +29,36 @@ async def root():
2929
assert response.headers["X-BlueAPI-VERSION"] == __version__
3030

3131

32-
async def test_log_request_details():
32+
@pytest.mark.parametrize("path,level", [("/", "info"), ("/healthz", "debug")])
33+
async def test_log_request_details(path: str, level: str):
3334
with mock.patch("blueapi.service.main.LOGGER") as logger:
3435
app = FastAPI()
3536
app.middleware("http")(log_request_details)
3637

37-
@app.post("/")
38+
@app.post(path)
3839
async def root():
3940
return {"message": "Hello World"}
4041

4142
client = TestClient(app)
42-
response = client.post("/", content="foo")
43+
response = client.post(path, content="foo")
4344

4445
assert response.status_code == 200
45-
logger.debug.assert_called_once_with(
46-
"testclient:50000 POST /",
47-
extra={
48-
"request_body": b"foo",
49-
},
50-
)
51-
52-
logger.info.assert_called_once_with(
53-
"testclient:50000 POST / 200",
54-
extra={
55-
"request_body": b"foo",
56-
},
46+
log_level = getattr(logger, level)
47+
log_level.assert_has_calls(
48+
[
49+
call(
50+
f"testclient:50000 POST {path}",
51+
extra={
52+
"request_body": b"foo",
53+
},
54+
),
55+
call(
56+
f"testclient:50000 POST {path} 200",
57+
extra={
58+
"request_body": b"foo",
59+
},
60+
),
61+
]
5762
)
5863

5964

0 commit comments

Comments
 (0)