Example #1
0
def test_delete():
    item_id = 1

    client, http = get_client_and_http()
    http.request = Mock(return_value=(None, None))

    result = client.Item.delete(item_id)

    eq_(None, result)
    http.request.assert_called_once_with("%s/item/%s?" % (URL_BASE, item_id),
                                         'DELETE',
                                         body=None,
                                         headers={})
Example #2
0
def test_delete():
    item_id = 1

    client, http = get_client_and_http()
    http.request = Mock(return_value=(None, None))

    result = client.Item.delete(item_id)

    eq_(None, result)
    http.request.assert_called_once_with("%s/item/%s?" % (URL_BASE, item_id),
                                         'DELETE',
                                         body=None,
                                         headers={})
Example #3
0
def test_get_url():
    client, _ = get_client_and_http()
    transport = client.transport
    transport._params = MagicMock()

    # Test get_url with URL coming from the _attribute_stack
    transport._attribute_stack = ['/task/']
    assert transport.get_url() == 'https://api.example.com/task/'
    transport._attribute_stack = ['task']
    assert transport.get_url() == 'https://api.example.com/task'

    # Test get_url with URL passed as an argument
    transport._attribute_stack = ['/random/']
    assert transport.get_url('/task/') == 'https://api.example.com/task/'
    transport._attribute_stack = ['random/']
    assert transport.get_url('task') == 'https://api.example.com/task'
Example #4
0
def test_transport(mock_sleep):
    mock_status = MagicMock()
    mock_status.status = 502

    client, _ = get_client_and_http()
    client.setup_retry(3, 2, 2, 10)
    client.transport._http.request = MagicMock(side_effect=TransportException(mock_status, None))

    try:
        client.Contact.get_contacts()
    except TransportException:
        pass
    else:
        raise AssertionError()

    assert client.transport._http.request.call_count == 3
    assert mock_sleep.call_count == 2