def test_endpoint_no_task(): with api_client(Trigger([])) as client: response = client.post('/trigger') assert response.status_code == 422 assert response.json() == { 'detail': [{ 'loc': ['query', 'task'], 'msg': 'field required', 'type': 'value_error.missing' }] }
def test_endpoint_no_log_level(): with api_client() as client: response = client.post('/loglevel') assert response.status_code == 422 assert response.json() == { 'detail': [{ 'loc': ['query', 'level'], 'msg': 'field required', 'type': 'value_error.missing' }] }
def test_endpoint(): with api_client() as client: response = client.post('/loglevel?level=ERROR') assert response.status_code == 200 assert response.json() == {} assert logging.getLogger().level == logging.ERROR response = client.post('/loglevel?level=INFO') assert response.status_code == 200 assert response.json() == {} assert logging.getLogger().level == logging.INFO
def test_endpoint_polling_error(): tasks = { 'pytest': TaskModel( name='pytest', pull=PullModel(instance=ErrorPollingDummy(name='pytest_pull')), pushes=[PushModel(instance=Nop(name='pytest_push'))]) } with api_client(Trigger(tasks)) as client: response = client.post('/trigger?task=pytest') assert response.status_code == 500 assert response.json() == { 'detail': 'While triggering the poll an error occurred.' }
def test_endpoint_unknown_task(): tasks = { 'pytest': TaskModel( name='pytest', pull=PullModel(instance=SyncPollingDummy(name='pytest_pull')), pushes=[PushModel(instance=Nop(name='pytest_push'))]) } with api_client(Trigger(tasks)) as client: response = client.post('/trigger?task=unknown') assert response.status_code == 422 assert response.json() == { 'detail': "Given task name 'unknown' is not a known task." }
def test_endpoint_not_a_poll(): tasks = { 'pytest': TaskModel(name='pytest', pull=PullModel(instance=NoPollingDummy(name='pytest_pull')), pushes=[PushModel(instance=Nop(name='pytest_push'))]) } with api_client(Trigger(tasks)) as client: response = client.post('/trigger?task=pytest') assert response.status_code == 422 assert response.json() == { 'detail': "Task 'pytest' does not support pull_now(). " "Implement PullNowMixin / AsyncPullNowMixin for support" }
def test_endpoint_working(clazz): polling = clazz(name='pytest_pull') result = [] polling.callback(lambda pull, payload: result.append(payload)) tasks = { 'pytest': TaskModel(name='pytest', pull=PullModel(instance=polling), pushes=[PushModel(instance=Nop(name='pytest_push'))]) } with api_client(Trigger(tasks)) as client: response = client.post('/trigger?task=pytest') assert response.status_code == 200 assert response.json() == {} assert result == [42]
def test_endpoint_unknown_log_level(): with api_client() as client: response = client.post('/loglevel?level=UNKNOWN') assert response.status_code == 422 assert response.json() == { 'detail': [{ 'ctx': { 'pattern': '^DEBUG|INFO|WARNING|ERROR|CRITICAL$' }, 'loc': ['query', 'level'], 'msg': 'string does not match regex ' '"^DEBUG|INFO|WARNING|ERROR|CRITICAL$"', 'type': 'value_error.str.regex' }] }
def test_endpoint(): with api_client() as client: response = client.get('/docs') assert response.status_code == 200
def test_endpoint(): with api_client() as client: response = client.get('/version') assert response.status_code == 200 from pnp import __version__ assert response.json()['version'] == __version__