Example #1
0
def test_create_or_update_get_connection_error(mock_requests):
    mock_requests.request.side_effect = requests.ConnectionError()

    expected = "The connection failed when determining if the Nexus script oh_so exists"
    with pytest.raises(CachitoError, match=expected):
        nexus.create_or_update_script("oh_so", "/it/is/oh_so.groovy")

    assert mock_requests.request.call_count == 1
    assert mock_requests.request.call_args[0][0] == "get"
Example #2
0
def test_create_or_update_already_set(mock_requests):
    mock_get = mock.Mock()
    mock_get.status_code = 200
    mock_get.json.return_value = {"content": "println('Hello')"}
    mock_requests.request.side_effect = [mock_get]

    nexus.create_or_update_script("oh_so", "/it/is/oh_so.groovy")

    assert mock_requests.request.call_count == 1
    assert mock_requests.request.call_args[0][0] == "get"
Example #3
0
def test_create_or_update_get_fails(mock_requests):
    mock_get = mock.Mock()
    mock_get.status_code = 400
    mock_requests.request.side_effect = [mock_get]

    expected = "Failed to determine if the Nexus script oh_so exists"
    with pytest.raises(CachitoError, match=expected):
        nexus.create_or_update_script("oh_so", "/it/is/oh_so.groovy")

    assert mock_requests.request.call_count == 1
    assert mock_requests.request.call_args[0][0] == "get"
Example #4
0
def test_create_or_update_create(mock_requests):
    mock_get = mock.Mock()
    mock_get.status_code = 404
    mock_post = mock.Mock()
    mock_post.ok = True
    mock_requests.request.side_effect = [mock_get, mock_post]

    nexus.create_or_update_script("oh_so", "/it/is/oh_so.groovy")

    assert mock_requests.request.call_count == 2
    request_calls = mock_requests.request.call_args_list
    assert request_calls[0][0][0] == "get"
    assert request_calls[1][0][0] == "post"
Example #5
0
def test_create_or_update_update(mock_requests):
    mock_get = mock.Mock()
    mock_get.status_code = 200
    mock_get.json.return_value = {"content": "println('Goodbye')"}
    mock_put = mock.Mock()
    mock_put.ok = True
    mock_requests.request.side_effect = [mock_get, mock_put]

    nexus.create_or_update_script("oh_so", "/it/is/oh_so.groovy")

    assert mock_requests.request.call_count == 2
    request_calls = mock_requests.request.call_args_list
    assert request_calls[0][0][0] == "get"
    assert request_calls[1][0][0] == "put"
Example #6
0
def test_create_or_update_create_fails(mock_requests):
    mock_get = mock.Mock()
    mock_get.status_code = 404
    mock_post = mock.Mock()
    mock_post.ok = False
    mock_requests.request.side_effect = [mock_get, mock_post]

    expected = "Failed to create/update the Nexus script oh_so"
    with pytest.raises(CachitoError, match=expected):
        nexus.create_or_update_script("oh_so", "/it/is/oh_so.groovy")

    assert mock_requests.request.call_count == 2
    request_calls = mock_requests.request.call_args_list
    assert request_calls[0][0][0] == "get"
    assert request_calls[1][0][0] == "post"
Example #7
0
def test_create_or_update_update_fails(mock_requests):
    mock_get = mock.Mock()
    mock_get.status_code = 200
    mock_get.json.return_value = {"content": "println('Goodby')"}
    mock_put = mock.Mock()
    mock_put.ok = False
    mock_requests.request.side_effect = [mock_get, mock_put]

    expected = "Failed to create/update the Nexus script oh_so"
    with pytest.raises(CachitoError, match=expected):
        nexus.create_or_update_script("oh_so", "/it/is/oh_so.groovy")

    assert mock_requests.request.call_count == 2
    request_calls = mock_requests.request.call_args_list
    assert request_calls[0][0][0] == "get"
    assert request_calls[1][0][0] == "put"