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
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))
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))
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']
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'))
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'))
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'))
def test_post_returns_response(): httpretty.register_uri(httpretty.POST, 'http://localhost:9000/endpoint', body='{"hello":"world"}') assert 'world' == SonarQube().post(Endpoint('/endpoint'))['hello']