コード例 #1
0
ファイル: test_trigger.py プロジェクト: HazardDede/pnp
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'
            }]
        }
コード例 #2
0
ファイル: test_log_level.py プロジェクト: HazardDede/pnp
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'
            }]
        }
コード例 #3
0
ファイル: test_log_level.py プロジェクト: HazardDede/pnp
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
コード例 #4
0
ファイル: test_trigger.py プロジェクト: HazardDede/pnp
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.'
        }
コード例 #5
0
ファイル: test_trigger.py プロジェクト: HazardDede/pnp
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."
        }
コード例 #6
0
ファイル: test_trigger.py プロジェクト: HazardDede/pnp
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"
        }
コード例 #7
0
ファイル: test_trigger.py プロジェクト: HazardDede/pnp
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]
コード例 #8
0
ファイル: test_log_level.py プロジェクト: HazardDede/pnp
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'
            }]
        }
コード例 #9
0
def test_endpoint():
    with api_client() as client:
        response = client.get('/docs')
        assert response.status_code == 200
コード例 #10
0
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__