1import pytest
3
4
5
6async def test_basic(service_client, testpoint):
7 @testpoint('simple-testpoint')
8 def simple_testpoint(data):
9 assert data == {'payload': 'Hello, world!'}
10
11 response = await service_client.get('/testpoint')
12 assert response.status == 200
13 assert 'application/json' in response.headers['Content-Type']
14 assert simple_testpoint.times_called == 1
15
16
17
18
19async def test_injection(service_client, testpoint):
20 @testpoint('injection-point')
21 def injection_point(data):
22 return {'value': 'injected'}
23
24 response = await service_client.get('/testpoint')
25 assert response.status == 200
26 assert 'application/json' in response.headers['Content-Type']
27 assert response.json() == {'value': 'injected'}
28
29
30 assert injection_point.times_called == 1
31
32
33
34async def test_disabled_testpoint(service_client, testpoint):
35 response = await service_client.get('/testpoint')
36 assert response.status == 200
37
38 @testpoint('injection-point')
39 def injection_point(data):
40 return {'value': 'injected'}
41
42
43 with pytest.raises(
45 ):
46 assert injection_point.times_called == 0
47
48
49 await service_client.update_server_state()
50 assert injection_point.times_called == 0
51
52
53async def test_manual_testpoint_registration(service_client, testpoint):
54
55 @testpoint('injection-point')
56 def injection_point(data):
57 return {'value': 'injected'}
58
59 await service_client.update_server_state()
60 assert injection_point.times_called == 0
61
62
63 response = await service_client.get('/testpoint')
64 assert response.status == 200
65
66 assert injection_point.times_called == 1