-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
57 lines (40 loc) · 1.44 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import muffin
import pytest
@pytest.fixture
def app():
return muffin.Application(DEBUG=True, PROMETHEUS_METRICS_URL='/metrics')
async def test_base(app, client):
from muffin_prometheus import Plugin
metrics = Plugin(app)
assert metrics.cfg.metrics_url == '/metrics'
res = await client.get('/')
assert res.status_code == 404
res = await client.get('/metrics')
assert res.status_code == 200
text = await res.text()
assert text
assert 'requests_count_total' in text
assert 'requests_time' in text
async def test_group_path(app, client):
from muffin_prometheus import Plugin
Plugin(app, group_paths=['/api', '/api/v1/users'])
async def send_ok(request):
return 'OK'
app.route('/')(send_ok)
app.route('/api')(send_ok)
app.route('/api/v1/messages')(send_ok)
app.route('/api/v1/users/{id}')(send_ok)
res = await client.get('/')
assert res.status_code == 200
assert await res.text() == 'OK'
res = await client.get('/api/v1/users/2')
assert res.status_code == 200
res = await client.get('/api/v1/messages')
assert res.status_code == 200
res = await client.get('/unknown')
assert res.status_code == 404
res = await client.get('/metrics')
assert res.status_code == 200
text = await res.text()
assert 'requests_count_total{method="GET",path="/api*"}' in text
assert 'requests_count_total{method="GET",path="/api/v1/users*"}' in text