File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change 1
1
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 ()
Original file line number Diff line number Diff line change 1
1
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
You can’t perform that action at this time.
0 commit comments