Пример #1
0
def test_request_uninitialised_namespace_then_invalid_query(fetch, url, create_namespace):
    fetch.side_effect = [httpclient.HTTPError(404, 'Not Found'), httpclient.HTTPError(500, 'Internal Server Error')]
    with pytest.raises(httpclient.HTTPError) as exc:
        yield request(None, 'c8ab01', 'pay load')
    assert create_namespace.call_count == 1
    assert fetch.call_count == 2
    assert exc.value.code == 500
Пример #2
0
def test_request_invalid_query(fetch, url, create_namespace):
    fetch.side_effect = HTTPError(500, 'Internal Server Error')
    with pytest.raises(HTTPError) as exc:
        yield request(None, 'c8ab01', 'pay load')
    assert not create_namespace.called
    assert fetch.call_count == 1
    assert exc.value.status_code == 500
Пример #3
0
def test_request_invalid_query(fetch, url, create_namespace):
    fetch.side_effect = HTTPError(500, 'Internal Server Error')
    with pytest.raises(HTTPError) as exc:
        yield request(None, 'c8ab01', 'pay load')
    assert not create_namespace.called
    assert fetch.call_count == 1
    assert exc.value.status_code == 500
Пример #4
0
def test_request_initialise_namespace_http_error(fetch, url, create_namespace, error):
    fetch.side_effect = [httpclient.HTTPError(404, 'Not Found')]
    create_namespace.side_effect = httpclient.HTTPError(500, 'Internal Server Error')
    yield request(None, 'c8ab01', 'pay load')
    assert create_namespace.call_count == 1
    assert fetch.call_count == 2
    assert error.called
Пример #5
0
def test_request_initialise_namespace_http_conflict(fetch, url, create_namespace, warning):
    fetch.side_effect = [httpclient.HTTPError(404, 'Not Found')]
    create_namespace.side_effect = httpclient.HTTPError(409, 'Namespace already exists')
    yield request(None, 'c8ab01', 'pay load')
    assert create_namespace.call_count == 1
    assert fetch.call_count == 2
    assert warning.called
Пример #6
0
def test_request_uninitialised_namespace_standalone_mode(options, fetch, url, create_namespace):
    options.standalone = True
    fetch.side_effect = [httpclient.HTTPError(404, 'Not Found')]
    with pytest.raises(httpclient.HTTPError) as exc:
        yield request(None, 'c8ab01', 'pay load')
    assert not create_namespace.called
    assert fetch.call_count == 1
    assert exc.value.code == 404
Пример #7
0
def test_request_has_content_type(fetch, url):
    yield request('body type',
                  'c8ab01',
                  'pay load',
                  content_type='application/json')
    assert fetch.call_args[1]['headers'] == {
        'Content-Type': 'application/json'
    }
Пример #8
0
def test_request_uninitialised_namespace_standalone_mode(
        options, fetch, url, create_namespace):
    options.standalone = True
    fetch.side_effect = [httpclient.HTTPError(404, 'Not Found')]
    with pytest.raises(httpclient.HTTPError) as exc:
        yield request(None, 'c8ab01', 'pay load')
    assert not create_namespace.called
    assert fetch.call_count == 1
    assert exc.value.code == 404
Пример #9
0
def test_request_initialise_namespace_http_conflict(fetch, url,
                                                    create_namespace, warning):
    fetch.side_effect = [httpclient.HTTPError(404, 'Not Found')]
    create_namespace.side_effect = httpclient.HTTPError(
        409, 'Namespace already exists')
    yield request(None, 'c8ab01', 'pay load')
    assert create_namespace.call_count == 1
    assert fetch.call_count == 2
    assert warning.called
Пример #10
0
def test_request_initialise_namespace_http_error(fetch, url, create_namespace,
                                                 error):
    fetch.side_effect = [httpclient.HTTPError(404, 'Not Found')]
    create_namespace.side_effect = httpclient.HTTPError(
        500, 'Internal Server Error')
    yield request(None, 'c8ab01', 'pay load')
    assert create_namespace.call_count == 1
    assert fetch.call_count == 2
    assert error.called
Пример #11
0
def test_request_uninitialised_namespace_then_invalid_query(
        fetch, url, create_namespace):
    fetch.side_effect = [
        httpclient.HTTPError(404, 'Not Found'),
        httpclient.HTTPError(500, 'Internal Server Error')
    ]
    with pytest.raises(httpclient.HTTPError) as exc:
        yield request(None, 'c8ab01', 'pay load')
    assert create_namespace.call_count == 1
    assert fetch.call_count == 2
    assert exc.value.code == 500
Пример #12
0
def test_request_has_content_type_and_response_type(fetch, _set_accept_header,
                                                    url):
    yield request('body type',
                  'c8ab01',
                  'pay load',
                  response_type='csv',
                  content_type='application/json')
    _set_accept_header.assert_called_once_with('csv')
    assert fetch.call_args[1]['headers'] == {
        'Content-Type': 'application/json',
        'Accept': 'text/csv'
    }
Пример #13
0
def test_request_no_response_type(fetch, url):
    yield request('body type', 'c8ab01', 'pay load')
    assert fetch.call_args[1]['headers'] == {}
Пример #14
0
def test_request_valid_query(fetch, url):
    result = yield request(None, 'c8ab01', 'pay load')
    assert fetch.call_count == 1
    assert result == 'my response'
Пример #15
0
def test_request_no_body_type(fetch, url):
    yield request(None, 'c8ab01', 'pay load')
    assert fetch.call_args[1]['body'] == 'pay load'
Пример #16
0
def test_request_has_body_type(fetch, url):
    yield request('body type', 'c8ab01', 'pay load')
    assert fetch.call_args[1]['body'] == 'body+type=pay+load'
Пример #17
0
def test_request_has_content_type_and_response_type(fetch, _set_accept_header, url):
    yield request('body type', 'c8ab01', 'pay load', response_type='csv', content_type='application/json')
    _set_accept_header.assert_called_once_with('csv')
    assert fetch.call_args[1]['headers'] == {'Content-Type': 'application/json', 'Accept': 'text/csv'}
Пример #18
0
def test_request_no_response_type(fetch, url):
    yield request('body type', 'c8ab01', 'pay load')
    assert fetch.call_args[1]['headers'] == {}
Пример #19
0
def test_request_valid_query(fetch, url):
    result = yield request(None, 'c8ab01', 'pay load')
    assert fetch.call_count == 1
    assert result == 'my response'
Пример #20
0
def test_request_has_response_type(fetch, _set_accept_header, url):
    yield request('body type', 'c8ab01', 'pay load', response_type='csv')
    _set_accept_header.assert_called_once_with('csv')
    assert fetch.call_args[1]['headers'] == {'Accept': 'text/csv'}
Пример #21
0
def test_request_no_namespace(url, create_namespace):
    with pytest.raises(httpclient.HTTPError) as exc:
        yield request(None, None, 'pay load')
        assert exc.value.code == 400
        assert exc.value.message == "HTTP 400: Namespace/Repository missing"
Пример #22
0
def test_request_uninitialised_namespace(fetch, url, create_namespace):
    fetch.side_effect = [httpclient.HTTPError(404, 'Not Found')]
    yield request(None, 'c8ab01', 'pay load')
    assert create_namespace.call_count == 1
    assert fetch.call_count == 2
Пример #23
0
def test_request_no_namespace(url, create_namespace):
    with pytest.raises(httpclient.HTTPError) as exc:
        yield request(None, None, 'pay load')
        assert exc.value.code == 400
        assert exc.value.message == "HTTP 400: Namespace/Repository missing"
Пример #24
0
def test_request_has_body_type(fetch, url):
    yield request('body type', 'c8ab01', 'pay load')
    assert fetch.call_args[1]['body'] == 'body+type=pay+load'
Пример #25
0
def test_request_uninitialised_namespace(fetch, url, create_namespace):
    fetch.side_effect = [httpclient.HTTPError(404, 'Not Found')]
    yield request(None, 'c8ab01', 'pay load')
    assert create_namespace.call_count == 1
    assert fetch.call_count == 2
Пример #26
0
def test_request_has_content_type(fetch, url):
    yield request('body type', 'c8ab01', 'pay load', content_type='application/json')
    assert fetch.call_args[1]['headers'] == {'Content-Type': 'application/json'}
Пример #27
0
def test_request_has_response_type(fetch, _set_accept_header, url):
    yield request('body type', 'c8ab01', 'pay load', response_type='csv')
    _set_accept_header.assert_called_once_with('csv')
    assert fetch.call_args[1]['headers'] == {'Accept': 'text/csv'}
Пример #28
0
def test_request_no_body_type(fetch, url):
    yield request(None, 'c8ab01', 'pay load')
    assert fetch.call_args[1]['body'] == 'pay load'
Пример #29
0
def test_request_uses_generated_db_url(fetch, url):
    yield request('body type', 'c8ab01', 'pay load')
    assert fetch.call_args[0][0] == 'https://localhost:8000/bigdata/namespace/c8ab01'
Пример #30
0
def test_request_uses_generated_db_url(fetch, url):
    yield request('body type', 'c8ab01', 'pay load')
    assert fetch.call_args[0][
        0] == 'https://localhost:8000/bigdata/namespace/c8ab01'