Skip to content
Snippets Groups Projects
Commit 075ebabe authored by Valentin Rigal's avatar Valentin Rigal
Browse files

Update tests

parent 528bc322
No related branches found
No related tags found
No related merge requests found
Pipeline #78615 passed
......@@ -247,18 +247,21 @@ def test_run_cache(
]
def test_activity_conflict(
def test_start_activity_conflict(
monkeypatch, responses, mocker, mock_elements_worker_with_list
):
# Disable second configure call from run()
monkeypatch.setattr(mock_elements_worker_with_list, "configure", lambda: None)
# Mock a "normal" conflict during in activity update, which returns the Exception
mock_elements_worker_with_list.update_activity = mocker.MagicMock()
mock_elements_worker_with_list.update_activity.return_value = ErrorResponse(
title="conflict",
status_code=409,
content="Either this activity does not exists or this state is not allowed.",
responses.add(
responses.PUT,
"http://testserver/api/v1/workers/versions/12341234-1234-1234-1234-123412341234/activity/",
body=ErrorResponse(
title="conflict",
status_code=409,
content="Either this activity does not exists or this state is not allowed.",
),
)
from arkindex_worker.worker import logger
......@@ -266,25 +269,38 @@ def test_activity_conflict(
mock_elements_worker_with_list.run()
assert mock_elements_worker_with_list.update_activity.call_args_list == [
mocker.call("1234-deadbeef", ActivityState.Started)
assert len(responses.calls) == len(BASE_API_CALLS) + 2
assert [
(call.request.method, call.request.url) for call in responses.calls
] == BASE_API_CALLS + [
("GET", "http://testserver/api/v1/element/1234-deadbeef/"),
(
"PUT",
"http://testserver/api/v1/workers/versions/12341234-1234-1234-1234-123412341234/activity/",
),
]
assert logger.warning.call_args_list == [
mocker.call(
"Failed to update activity of element 1234-deadbeef to started due to an API error: Either this activity does not exists or this state is not allowed."
),
mocker.call(
"Cannot start processing element 1234-deadbeef due to a conflict. "
"Another process could have processed it with the same version already."
)
),
]
def test_activity_error(monkeypatch, responses, mocker, mock_elements_worker_with_list):
def test_start_activity_error(
monkeypatch, responses, mocker, mock_elements_worker_with_list
):
# Disable second configure call from run()
monkeypatch.setattr(mock_elements_worker_with_list, "configure", lambda: None)
# Mock a "normal" conflict during in activity update, which returns the Exception
mock_elements_worker_with_list.update_activity = mocker.MagicMock()
mock_elements_worker_with_list.update_activity.return_value = Exception(
"A wild Petilil appears !"
# Mock a random error occurring during the activity update
responses.add(
responses.PUT,
"http://testserver/api/v1/workers/versions/12341234-1234-1234-1234-123412341234/activity/",
body=Exception("A wild Petilil appears !"),
)
from arkindex_worker.worker import logger
......@@ -293,8 +309,19 @@ def test_activity_error(monkeypatch, responses, mocker, mock_elements_worker_wit
with pytest.raises(SystemExit):
mock_elements_worker_with_list.run()
assert mock_elements_worker_with_list.update_activity.call_args_list == [
mocker.call("1234-deadbeef", ActivityState.Started)
assert [
(call.request.method, call.request.url) for call in responses.calls
] == BASE_API_CALLS + [
("GET", "http://testserver/api/v1/element/1234-deadbeef/"),
(
"PUT",
"http://testserver/api/v1/workers/versions/12341234-1234-1234-1234-123412341234/activity/",
),
# Activity is updated to the "error" state regardless of the Exception occurring during the call
(
"PUT",
"http://testserver/api/v1/workers/versions/12341234-1234-1234-1234-123412341234/activity/",
),
]
assert logger.error.call_args_list == [
mocker.call("Ran on 1 elements: 0 completed, 1 failed")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment