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
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
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
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
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
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
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'
    }
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
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
Example #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
Example #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
Example #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'
    }
Example #13
0
def test_request_no_response_type(fetch, url):
    yield request('body type', 'c8ab01', 'pay load')
    assert fetch.call_args[1]['headers'] == {}
Example #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'
Example #15
0
def test_request_no_body_type(fetch, url):
    yield request(None, 'c8ab01', 'pay load')
    assert fetch.call_args[1]['body'] == 'pay load'
Example #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'
Example #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'}
Example #18
0
def test_request_no_response_type(fetch, url):
    yield request('body type', 'c8ab01', 'pay load')
    assert fetch.call_args[1]['headers'] == {}
Example #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'
Example #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'}
Example #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"
Example #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
Example #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"
Example #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'
Example #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
Example #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'}
Example #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'}
Example #28
0
def test_request_no_body_type(fetch, url):
    yield request(None, 'c8ab01', 'pay load')
    assert fetch.call_args[1]['body'] == 'pay load'
Example #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'
Example #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'