Exemplo n.º 1
0
def test_ask_select_multiple(mock_input, question_list, answers, promt, expected):
    mock_input.side_effect = answers

    res = ask_select_multiple(question_list, promt)

    assert_deep_equal(res, expected)
    assert mock_input.call_count == 2
    mock_input.assert_called_with(promt)
Exemplo n.º 2
0
def test_post_should_return_cors_headers(client):
    res = client.post('/testing/hello', headers={'Origin': b'http://example.com'})

    assert res.status_code == 200, res.text
    assert res.text == 'Hello'
    cors_headers = dict((k, v) for k, v in res.headers.items() if 'Access-Control' in k)
    assert_deep_equal(cors_headers, {
        'Access-Control-Allow-Origin': 'http://example.com',
        'Access-Control-Allow-Credentials': 'true'
    })
Exemplo n.º 3
0
def test_not_found(client):
    res = client.delete_json('/testing/not_existed', expect_errors=True)

    assert res.status_code == 404, res.text
    assert_deep_equal(res.json, {
        'error': {
            'id': '11111111111111111111111111111111',
            'type': 'notFound',
            'message': 'Requested resource is not found'
        }
    })
Exemplo n.º 4
0
def test_internal_error(client):
    # TODO test error traceback visible/hidden depending on X-Debug header
    res = client.get('/testing/error', expect_errors=True)
    assert res.status_code == 500, res.text
    assert_deep_equal(res.json, {
        'error': {
            'id': '11111111111111111111111111111111',
            'type': 'internal',
            'message': 'division by zero'
        }
    })
Exemplo n.º 5
0
def test_method_not_allowed(client):
    res = client.delete('/testing/error', expect_errors=True)

    assert res.status_code == 405, res.text
    assert_deep_equal(res.json, {
        'error': {
            'id': '11111111111111111111111111111111',
            'type': 'methodNotAllowed',
            'message': 'The method is not allowed for the requested resource',
            'allowed_methods': ['OPTIONS', 'GET']
        }
    })
Exemplo n.º 6
0
def test_paginated_result(api_pages_response, page_search_response):
    query = ResponsePaginatedResult('pages', api_pages_response, (), {})
    query.request_next()

    assert len(query) == 6

    records = list(query.get(2))
    assert len(records) == 2
    assert query.has_next()

    record = query.get_one()
    assert_deep_equal(page_search_response['pages'][0], record)

    records = list(query.filter_by(lambda p: p['url'] == 'test.yml'))
    assert len(records) == 2
Exemplo n.º 7
0
def test_get_error_should_return_cors_headers(client):
    res = client.post('/testing/error', headers={'Origin': b'http://example.com'}, expect_errors=True)

    assert res.status_code == 500, res.text
    assert_deep_equal(res.json, {
        'error': {
            'id': '11111111111111111111111111111111',
            'type': 'internal',
            'message': 'division by zero'
        }
    })
    cors_headers = dict((k, v) for k, v in res.headers.items() if 'Access-Control' in k)
    assert_deep_equal(cors_headers, {
        'Access-Control-Allow-Origin': 'http://example.com',
        'Access-Control-Allow-Credentials': 'true'
    })
Exemplo n.º 8
0
def test_preflight_request_should_return_cors_headers(client):
    # TODO update webtest client, let developer pass HTTP header value as unicode string
    res = client.options('/testing/hello', headers={
        'Origin': b'http://example.com',
        'Access-Control-Request-Method': b'POST',
        'Access-Control-Request-Headers': b'Accept, Content-Type, Authorization'
    })

    assert res.status_code == 204, res.text
    cors_headers = dict((k, v) for k, v in res.headers.items() if 'Access-Control' in k)
    assert_deep_equal(cors_headers, {
        'Access-Control-Allow-Headers': 'Accept, Content-Type, Authorization',
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Credentials': 'true',
        'Access-Control-Allow-Methods': 'POST',
        'Access-Control-Max-Age': '1728000'
    })