Skip to content

Commit 8b89aea

Browse files
committed
Fix test coverage
1 parent 7e8d183 commit 8b89aea

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

apitally/litestar.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
import json
42
import sys
53
import time

tests/test_litestar.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ async def foo() -> str:
3333
return "foo"
3434

3535
@get("/foo/{bar:str}")
36-
async def foo_bar(bar: str) -> str:
36+
async def foo_bar(request: Request, bar: str) -> str:
37+
request.state.consumer_identifier = "test2"
3738
return f"foo: {bar}"
3839

3940
@post("/bar")
@@ -49,7 +50,7 @@ async def val(foo: int) -> str:
4950
return "val"
5051

5152
def identify_consumer(request: Request) -> Optional[str]:
52-
return "test"
53+
return "test1" if "/foo" in request.route_handler.paths else None
5354

5455
plugin = ApitallyPlugin(
5556
client_id=CLIENT_ID,
@@ -74,7 +75,7 @@ def test_middleware_requests_ok(app: Litestar, mocker: MockerFixture):
7475
assert response.status_code == 200
7576
mock.assert_called_once()
7677
assert mock.call_args is not None
77-
assert mock.call_args.kwargs["consumer"] == "test"
78+
assert mock.call_args.kwargs["consumer"] == "test1"
7879
assert mock.call_args.kwargs["method"] == "GET"
7980
assert mock.call_args.kwargs["path"] == "/foo"
8081
assert mock.call_args.kwargs["status_code"] == 200
@@ -84,6 +85,7 @@ def test_middleware_requests_ok(app: Litestar, mocker: MockerFixture):
8485
assert response.status_code == 200
8586
assert mock.call_count == 2
8687
assert mock.call_args is not None
88+
assert mock.call_args.kwargs["consumer"] == "test2"
8789
assert mock.call_args.kwargs["path"] == "/foo/{bar:str}"
8890

8991
response = client.post("/bar")

0 commit comments

Comments
 (0)