import pytest
import testsuite.plugins.testpoint
async def test_basic(service_client, testpoint: testsuite.plugins.testpoint.TestpointFixture):
@testpoint('simple-testpoint')
def simple_testpoint(data: dict):
assert data == {'payload': 'Hello, world!'}
response = await service_client.get('/testpoint')
assert response.status == 200
assert 'application/json' in response.headers['Content-Type']
assert simple_testpoint.times_called == 1
async def test_injection(service_client, testpoint: testsuite.plugins.testpoint.TestpointFixture):
@testpoint('injection-point')
def injection_point(data: dict):
return {'value': 'injected'}
response = await service_client.get('/testpoint')
assert response.status == 200
assert 'application/json' in response.headers['Content-Type']
assert response.json() == {'value': 'injected'}
assert injection_point.times_called == 1
async def test_disabled_testpoint(service_client, testpoint):
response = await service_client.get('/testpoint')
assert response.status == 200
@testpoint('injection-point')
def injection_point(data: dict):
return {'value': 'injected'}
with pytest.raises(
):
assert injection_point.times_called == 0
await service_client.update_server_state()
assert injection_point.times_called == 0
async def test_manual_testpoint_registration(service_client, testpoint):
@testpoint('injection-point')
def injection_point(data):
return {'value': 'injected'}
await service_client.update_server_state()
assert injection_point.times_called == 0
response = await service_client.get('/testpoint')
assert response.status == 200
assert injection_point.times_called == 1