Esempio n. 1
0
def test_api_call_with_timeout():
    func = mock.Mock(
        side_effect=requests.exceptions.ReadTimeout("msg"),
        __name__="remove_image")
    id = "abcd"

    with mock.patch(
            'docker_custodian.docker_gc.log',
            autospec=True) as mock_log:
        docker_gc.api_call(func, id)

    func.assert_called_once_with(id)
    mock_log.warn.assert_called_once_with('Failed to call remove_image abcd msg')
Esempio n. 2
0
def test_api_call_with_api_error():
    func = mock.Mock(side_effect=docker.errors.APIError("Ooops",
                                                        mock.Mock(
                                                            status_code=409,
                                                            reason="Conflict"),
                                                        explanation="failed"),
                     __name__="remove_image")
    image = "abcd"

    with mock.patch('docker_custodian.docker_gc.log',
                    autospec=True) as mock_log:
        docker_gc.api_call(func, image=image)

    func.assert_called_once_with(image="abcd")
    mock_log.warn.assert_called_once_with(
        'Error calling remove_image image=abcd '
        '409 Client Error: Conflict ("failed")')
Esempio n. 3
0
def test_api_call_with_api_error():
    func = mock.Mock(
        side_effect=docker.errors.APIError(
            "Ooops",
            mock.Mock(status_code=409, reason="Conflict"),
            explanation="failed"),
        __name__="remove_image")
    id = "abcd"

    with mock.patch(
            'docker_custodian.docker_gc.log',
            autospec=True) as mock_log:
        docker_gc.api_call(func, id)

    func.assert_called_once_with(id)
    mock_log.warn.assert_called_once_with(
        'Error calling remove_image abcd '
        '409 Client Error: Conflict ("failed")')
Esempio n. 4
0
def test_api_call_success():
    func = mock.Mock()
    container = "abcd"
    result = docker_gc.api_call(func, container=container)
    func.assert_called_once_with(container="abcd")
    assert result == func.return_value
Esempio n. 5
0
def test_api_call_success():
    func = mock.Mock()
    id = "abcd"
    result = docker_gc.api_call(func, id)
    func.assert_called_once_with(id)
    assert result == func.return_value
Esempio n. 6
0
def test_api_call_success():
    func = mock.Mock()
    id = "abcd"
    result = docker_gc.api_call(func, id)
    func.assert_called_once_with(id)
    assert result == func.return_value
Esempio n. 7
0
def test_api_call_success():
    func = mock.Mock()
    container = "abcd"
    result = docker_gc.api_call(func, container=container)
    func.assert_called_once_with(container="abcd")
    assert result == func.return_value