From f2f948920096a6a2b68a57f9e95ea3b71941ae3f Mon Sep 17 00:00:00 2001 From: Sylvan Ridderinkhof Date: Tue, 28 Nov 2023 15:13:36 +0100 Subject: [PATCH] refactor: updated None objects in tests --- .../custom_fields/test_custom_fields.py | 13 +++++++------ .../processing/test_activity_subtypes.py | 11 ++++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/direct_indexing/custom_fields/test_custom_fields.py b/tests/direct_indexing/custom_fields/test_custom_fields.py index 8117232cf..bb748c08c 100644 --- a/tests/direct_indexing/custom_fields/test_custom_fields.py +++ b/tests/direct_indexing/custom_fields/test_custom_fields.py @@ -7,25 +7,25 @@ def test_add_all(mocker): mock_pa = mocker.patch('direct_indexing.custom_fields.custom_fields.process_activity') mock_ca = mocker.patch('direct_indexing.custom_fields.custom_fields.currency_aggregation') mock_h2 = mocker.patch('direct_indexing.custom_fields.custom_fields.raise_h2_budget_data_to_h1') - + mock = mocker.MagicMock() # Test that the h2 function is not called when fcdo instance is false, # and that the process_activity and currency_aggregation functions are called once mocker.patch(FCDO_IN, False) data = {} - add_all(data, None, None, None) + add_all(data, mock, mock, {}) mock_pa.assert_called_once() mock_ca.assert_called_once() mock_h2.assert_not_called() # Test that the process_activity function is called len(data) times data = [{}, {}] - add_all(data, None, None, None) + add_all(data, mock, mock, {}) assert mock_pa.call_count == len(data) + 1 # +1 for the previous test # Test that the h2 function is called when fcdo instance is true mocker.patch(FCDO_IN, True) data = {} - add_all(data, None, None, None) + add_all(data, mock, mock, {}) mock_h2.assert_called_once() @@ -41,11 +41,12 @@ def test_process_activity(mocker): mock_ajd = mocker.patch('direct_indexing.custom_fields.custom_fields.add_json_dumps') mock_adq = mocker.patch('direct_indexing.custom_fields.custom_fields.add_date_quarter_fields') mock_dlcc = mocker.patch('direct_indexing.custom_fields.custom_fields.document_link_category_combined') + mock = mocker.MagicMock() # Test that all subfunctions are called once mocker.patch(FCDO_IN, False) activity = {} - process_activity(activity, None, None, None) + process_activity(activity, mock, mock, {}) mock_ac.assert_called_once() mock_tn.assert_called_once() mock_ad.assert_called_once() @@ -60,7 +61,7 @@ def test_process_activity(mocker): # Test that the remaining functions are called when FCDO_INSTANCE is True mocker.patch(FCDO_IN, True) - process_activity(activity, None, None, None) + process_activity(activity, mock, mock, {}) mock_ajd.assert_called_once() mock_adq.assert_called_once() mock_dlcc.assert_called_once() diff --git a/tests/direct_indexing/processing/test_activity_subtypes.py b/tests/direct_indexing/processing/test_activity_subtypes.py index ec1ad0b86..4750854a4 100644 --- a/tests/direct_indexing/processing/test_activity_subtypes.py +++ b/tests/direct_indexing/processing/test_activity_subtypes.py @@ -23,25 +23,26 @@ def test_extract_subtype(mocker): assert mock_process.call_count == len(data.keys()) # once for each key in data -def test_process_subtype_dict(): +def test_process_subtype_dict(mocker): tvu = 'transaction.value-usd' bvu = 'budget.value-usd' # Test if key is in AVAILABLE_SUBTYPES, it is nothing changes in subtype_dict subtype_dict = {'transaction': {'value': 1}} expected_res = subtype_dict.copy() key = 'transaction' - res = process_subtype_dict(subtype_dict, key, None, None, None, None) + mock = mocker.MagicMock() + res = process_subtype_dict(subtype_dict, key, mock, None, None, None) assert res == expected_res # Test if key is in exclude fields we do not include it in the subtype dict - res = process_subtype_dict(subtype_dict, bvu, None, None, [bvu], None) + res = process_subtype_dict(subtype_dict, bvu, mock, None, [bvu], None) assert res == expected_res # Test that a specific value which is a dict can be retrieved data = {'title': 'title', 'budget': {'value': 1}, tvu: 1.1} expected_res = subtype_dict.copy() expected_res[tvu] = 1.1 - res = process_subtype_dict(subtype_dict, tvu, None, data, [], [tvu]) + res = process_subtype_dict(subtype_dict, tvu, mock, data, [], [tvu]) assert res == expected_res # Test that the value of a specific element is extracted from the list @@ -53,7 +54,7 @@ def test_process_subtype_dict(): # Test that additional fields are kept without modification expected_res['title'] = 'title' - res = process_subtype_dict(subtype_dict, 'title', None, data, [], []) + res = process_subtype_dict(subtype_dict, 'title', mock, data, [], []) assert res == expected_res