def test_handle_response_raises_for_no_content_in_response(): responses.add(responses.GET, 'http://127.0.0.1:4003/spongebob', status=404) connection = Connection('http://127.0.0.1:4003') response = requests.get('http://127.0.0.1:4003/spongebob') with pytest.raises(ArkHTTPException) as exception: connection._handle_response(response) assert str(exception.value) == 'No content in response' assert exception.value.response == response
def test_handle_response_raises_for_success_false_in_response(): responses.add( responses.GET, 'http://127.0.0.1:4003/spongebob', json={'success': False, 'error': 'Best error ever'}, status=404 ) connection = Connection('http://127.0.0.1:4003') response = requests.get('http://127.0.0.1:4003/spongebob') with pytest.raises(PhantomHTTPException) as exception: connection._handle_response(response) assert str(exception.value) == 'GET 404 http://127.0.0.1:4003/spongebob - Best error ever' assert exception.value.response == response
def test_handle_response_retuns_body_from_request(): responses.add(responses.GET, 'http://127.0.0.1:4003/spongebob', json={'success': True}, status=200) connection = Connection('http://127.0.0.1:4003') response = requests.get('http://127.0.0.1:4003/spongebob') body = connection._handle_response(response) assert body == {'success': True}