From bd5d15aea0069b2e839414993c6f608f45376637 Mon Sep 17 00:00:00 2001 From: Valentin Rigal <rigal@teklia.com> Date: Wed, 19 May 2021 15:28:14 +0200 Subject: [PATCH] Update existing tests --- tests/conftest.py | 12 +++++++++ tests/test_elements_worker/test_worker.py | 32 +++++------------------ 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 322ef9d6..922fc3e2 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 ca52c53a..1d5b491b 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) -- GitLab