示例#1
0
def test_request_response_has_status_code():
    """An RequestResponseStub object's has expected properties."""
    response = RequestResponseStub(status_code=301)

    assert str(response.status_code) == '301'

    assert str(RequestResponseStub().status_code) == '200'
示例#2
0
def test_request_response_can_be_used_for_tests():
    """An RequestResponseStub object's has expected properties."""
    response = RequestResponseStub(payload={
                                   'url': 'https://example.com/',
                                   'params': {'abc': 123, 'def': 456}})

    assert response.json() == {'url': 'https://example.com/',
                               'params': {'abc': 123, 'def': 456}}
示例#3
0
def test_api_response_works_with_request_response_int():
    """An ApiResponse object works with a request response object that is
    simply an integer."""
    request_response = RequestResponseStub(payload=5, status_code=200)
    response = ApiResponse(request_response)

    assert response.payload == 5
示例#4
0
 def post_mock(url, params=None, payload=payload):
     """A mock post request to return the request-prepared url."""
     if not payload:
         payload = {
             'url': url,
             'params': params,
         }
     return RequestResponseStub(payload=payload)
示例#5
0
 def test_api_get(*args, **kwargs):
     assert len(kwargs) == 1
     assert kwargs['domain_name'] == 'my_example.com'
     return RequestResponseStub(payload={
         'key_1': 'AAA',
         'key_2': 'BBB',
         'key_3': 'CCC',
         'key_4': 'DDD'
     })
示例#6
0
 def test_api_call(*args, **kwargs):
     return RequestResponseStub(
         payload={
             'status':
             'Failed',
             'statusDescription':
             'Invalid authentication, incorrect ' +
             'auth-id or auth-password.'
         })
示例#7
0
def test_api_response_can_be_converted_to_string():
    """ApiResponse can be converted to a string."""
    request_response = RequestResponseStub(payload={'test': 123},
                                           status_code=200)
    response = ApiResponse(request_response)

    expected_string = '{"status_code": 200, "success": true, "payload": ' \
        + '{"test": 123}}'

    assert response.string() == expected_string
    assert str(response) == expected_string
示例#8
0
def test_api_response_works_with_request_response_list():
    """An ApiResponse object works with a request response object that is a
    list."""
    request_response = RequestResponseStub(payload=[{'test1': 123},
                                                    {'test2': 456},
                                                    {'test3': 789}],
                                           status_code=200)
    response = ApiResponse(request_response)

    assert response.payload == [{'test1': 123},
                                {'test2': 456},
                                {'test3': 789}]
示例#9
0
def test_api_response_payload_is_normalized_to_snake_case():
    """An ApiResponse object's payload keys are normalized to snake case."""
    pre_normalized_data = {
        'test':          123,
        'testTest':      123,
        'testTestTest':  123,
        'testTTL':       123,
    }
    request_response = RequestResponseStub(payload=pre_normalized_data)
    response = ApiResponse(request_response)

    assert response.payload == {
        'test':            123,
        'test_test':       123,
        'test_test_test':  123,
        'test_ttl':        123,
    }
示例#10
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}
        }
示例#11
0
 def update(*args, **kwargs):
     return RequestResponseStub(payload=kwargs)
示例#12
0
 def test_api_get(*args, **kwargs):
     return RequestResponseStub(payload={'status': 'Failed',
                                         'statusDescription':
                                         'Missing domain-name'})
示例#13
0
 def test_api_call(*args, **kwargs):
     return RequestResponseStub(payload={'response': 'Testing...'},
                                status_code='500')
示例#14
0
def test_request_response_has_a_payload():
    """An RequestResponseStub object's has expected properties."""
    response = RequestResponseStub(payload={'abc': 123, 'def': 456})

    assert response.payload == {'abc': 123, 'def': 456}
    assert response.json() == {'abc': 123, 'def': 456}