Skip to content

Commit 003248f

Browse files
author
Hisham ElSheshtawy
committed
Add unit tests
1 parent 48665a6 commit 003248f

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

conftest.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
11
import pytest
2-
from quart import Quart
2+
from quart import Quart
3+
4+
5+
@pytest.fixture
6+
def app():
7+
app = Quart("testapp")
8+
@app.route
9+
async def index():
10+
return 'hi'
11+
return app
12+
13+
@pytest.fixture
14+
def client(app):
15+
return app.test_client()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,32 @@
11
import pytest
2+
import pytest_asyncio
3+
import quart
4+
5+
from quart_prometheus_logger import PrometheusRegistry
6+
from prometheus_client import REGISTRY
7+
8+
9+
def test_init_app(app):
10+
registry = PrometheusRegistry()
11+
metrics_endpoint = "root"
12+
registry.init_app(app, metrics_endpoint)
13+
assert "prometheus_error_handler" in app.error_handler_spec
14+
assert "prometheus_before_request_callback" in app.before_request_funcs
15+
assert "prometheus_after_request_callback" in app.after_request_funcs
16+
17+
18+
def test_init(app):
19+
registry = PrometheusRegistry(app=app)
20+
assert "prometheus_error_handler" in app.error_handler_spec
21+
assert "prometheus_before_request_callback" in app.before_request_funcs
22+
assert "prometheus_after_request_callback" in app.after_request_funcs
23+
24+
25+
@pytest.mark.asyncio
26+
async def test_customer_labeler(app, client):
27+
registry = PrometheusRegistry(app=app)
28+
custom_label = lambda _: {"custom_label": 1}
29+
registry.custom_route_labeler(custom_label, ["custom_label"])
30+
await client.get("/")
31+
for _, collector in registry._collectors.items():
32+
assert "custom_label" in collector._labelnames

0 commit comments

Comments
 (0)