Ejemplo n.º 1
0
def test_request(mock_request):
    mock_response = mock.create_autospec(requests.Response)
    mock_response.status_code = 200
    mock_request.return_value = mock_response

    client = VCloudClient(HOST, VERSION, ORG)
    client.auth_token = 'test-token'
    assert client.request(
        'test-method', 'test-url', headers={'test-header': 'test'})
Ejemplo n.º 2
0
def test_request_failure(mock_request):
    mock_response = mock.create_autospec(requests.Response)
    mock_response.status_code = 400
    mock_request.return_value = mock_response

    client = VCloudClient(HOST, VERSION, ORG)
    client.auth_token = 'test-token'

    with nose.tools.assert_raises(errors.VCloudAPIError):
        client.request('test-method', 'test-url')
Ejemplo n.º 3
0
def test_wait_for_task_success(mock_request):
    mock_task = objectify.Element('Task')
    mock_task.attrib['operation'] = 'test-operation'
    mock_task.attrib['status'] = 'success'

    mock_response = mock.create_autospec(requests.Response)
    mock_response.status_code = 200
    mock_response.content = etree.tostring(mock_task)
    mock_request.return_value = mock_response

    client = VCloudClient(HOST, VERSION, ORG)
    client.auth_token = 'test-token'

    assert not client.wait_for_task('test-task-url', 2, 0)
Ejemplo n.º 4
0
def test_wait_for_task_timeout(mock_request):
    mock_task = objectify.Element('Task')
    mock_task.attrib['operation'] = 'test-operation'
    mock_task.attrib['status'] = 'running'

    mock_response = mock.create_autospec(requests.Response)
    mock_response.status_code = 200
    mock_response.content = etree.tostring(mock_task)
    mock_request.return_value = mock_response

    client = VCloudClient(HOST, VERSION, ORG)
    client.auth_token = 'test-token'

    with nose.tools.assert_raises(errors.VCloudTimeoutError):
        client.wait_for_task('test-task-url', 2, 0)