Exemple #1
0
def test_api_response_without_request_response_shows_error_when_debugging():
    """An ApiResponse object that is initialized without a request response
    object shows an error in the json when debugging."""
    response = ApiResponse()

    # It's not yet initilized with an error
    assert response.error is None

    # But it will give an error converting to json (when debug mode is set)
    assert response.json()['error'] == \
        'Response has not yet been created with a requests.response.'
Exemple #2
0
def test_api_response_can_be_initialized_without_request_response():
    """An ApiResponse object can be initialized without a request response
    object."""
    response = ApiResponse()

    assert not response.error
    assert not response.response
    assert not response.success
    assert not response.status_code
    assert response.payload == {}
    assert response.json() == {
            'status_code':  None,
            'success':      False,
            'payload':      {}
        }
Exemple #3
0
def test_api_response_can_be_initialized_with_request_response():
    """An ApiResponse object can be initialized with a request response object.
    """
    request_response = RequestResponseStub(payload={'test': 123},
                                           status_code=200)
    response = ApiResponse(request_response)

    assert not response.error
    assert response.response == request_response
    assert response.success
    assert str(response.status_code) == '200'
    assert response.payload == {'test': 123}
    assert response.json() == {
            'status_code':   200,
            'success':      True,
            'payload':      {'test': 123}
        }