예제 #1
0
def test_get_response_400_should_raise_validation_error_with_message():

    httpretty.register_uri(httpretty.GET, 'http://localhost:9000/endpoint',
                           body='{"errors":[{"msg":"error"}]}', status=400)
    with pytest.raises(ValidationError) as err:
        SonarQube().get(Endpoint('/endpoint'))
        assert 'error' in err.value
예제 #2
0
def test_paged_get_returns_single_page():
    httpretty.register_uri(httpretty.GET,
                           'http://localhost:9000/endpoint?p=1',
                           body=__paged_response(page_index=1, total=1))
    generator = SonarQube().paged_get(
        Endpoint('/endpoint', pager=Pager(response_items='items')))
    assert 1 == len(list(generator))
예제 #3
0
def test_paged_get_returns_multiple_pages():
    httpretty.register_uri(httpretty.GET, 'http://localhost:9000/endpoint',
                           match_querystring=True,
                           body=__paged_response(page_index=1, total=2))
    httpretty.register_uri(httpretty.GET, 'http://localhost:9000/endpoint?p=2',
                           match_querystring=True,
                           body=__paged_response(page_index=2, total=2))
    generator = SonarQube().paged_get(Endpoint('/endpoint', pager=Pager(response_items='items')))
    assert 2 == len(list(generator))
예제 #4
0
def test_get_returns_item_in_response():
    httpretty.register_uri(httpretty.GET, 'http://localhost:9000/endpoint',
                           body='{"item":{"hello":"world"}}')
    assert 'world' == SonarQube().get(Endpoint('/endpoint', response_item='item'))['hello']
예제 #5
0
def test_get_response_500_should_raise_server_error():
    httpretty.register_uri(httpretty.GET, 'http://localhost:9000/endpoint', status=500)
    with pytest.raises(ServerError):
        SonarQube().get(Endpoint('/endpoint'))
예제 #6
0
def test_get_response_404_should_raise_client_error():
    httpretty.register_uri(httpretty.GET, 'http://localhost:9000/endpoint', status=404)
    with pytest.raises(ClientError):
        SonarQube().get(Endpoint('/endpoint'))
예제 #7
0
def test_response_403_should_raise_auth_error():
    httpretty.register_uri(httpretty.GET,
                           'http://localhost:9000/endpoint',
                           status=403)
    with pytest.raises(AuthError):
        SonarQube().get(Endpoint('/endpoint'))
예제 #8
0
def test_post_returns_response():
    httpretty.register_uri(httpretty.POST,
                           'http://localhost:9000/endpoint',
                           body='{"hello":"world"}')
    assert 'world' == SonarQube().post(Endpoint('/endpoint'))['hello']