diff --git a/tests/conftest.py b/tests/conftest.py index 322ef9d6483a0d27344a070fa2f0fb6a11542ec8..922fc3e24766768d343bd05a7baca3bd279a7994 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -202,6 +202,18 @@ def mock_user_api(responses): ) +@pytest.fixture +def mock_activity_calls(responses): + """ + Mock responses when updating the activity state for multiple element of the same version + """ + responses.add( + responses.PUT, + "http://testserver/api/v1/workers/versions/12341234-1234-1234-1234-123412341234/activity/", + status=200, + ) + + @pytest.fixture def mock_elements_worker(monkeypatch, mock_config_api): """Build and configure an ElementsWorker with fixed CLI parameters to avoid issues with pytest""" diff --git a/tests/test_elements_worker/test_worker.py b/tests/test_elements_worker/test_worker.py index ca52c53a6217403857104e81802b4a418a8623af..1d5b491b259ea011cd6075145720339c1ba0b3cc 100644 --- a/tests/test_elements_worker/test_worker.py +++ b/tests/test_elements_worker/test_worker.py @@ -169,7 +169,12 @@ def test_update_call(responses, mock_elements_worker, mock_process_api): ], ) def test_run( - monkeypatch, mock_elements_worker, responses, process_exception, final_state + monkeypatch, + mock_elements_worker, + responses, + process_exception, + final_state, + mock_activity_calls, ): """Check the normal runtime sends 2 API calls to update activity""" # Disable second configure call from run() @@ -193,29 +198,6 @@ def test_run( "name": "Test Page n°1", }, ) - - # Mock Update activity - responses.add( - responses.PUT, - "http://testserver/api/v1/workers/versions/12341234-1234-1234-1234-123412341234/activity/", - status=200, - json={ - "element_id": "1234-deadbeef", - "process_id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeffff", - "state": "started", - }, - ) - responses.add( - responses.PUT, - "http://testserver/api/v1/workers/versions/12341234-1234-1234-1234-123412341234/activity/", - status=200, - json={ - "element_id": "1234-deadbeef", - "process_id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeffff", - "state": final_state, - }, - ) - assert mock_elements_worker.is_read_only is False # Mock exception in process_element @@ -262,7 +244,7 @@ def test_run( def test_run_cache( - monkeypatch, mocker, mock_elements_worker_with_cache, mock_cached_elements + monkeypatch, mocker, mock_elements_worker_with_cache, mock_cached_elements, mock_activity_calls, ): # Disable second configure call from run() monkeypatch.setattr(mock_elements_worker_with_cache, "configure", lambda: None)