diff --git a/services/solr-names-updater/src/solr_names_updater/version.py b/services/solr-names-updater/src/solr_names_updater/version.py index e35237c0f..bd2425859 100644 --- a/services/solr-names-updater/src/solr_names_updater/version.py +++ b/services/solr-names-updater/src/solr_names_updater/version.py @@ -22,4 +22,4 @@ Development release segment: .devN """ -__version__ = '0.2.0' # pylint: disable=invalid-name +__version__ = '0.3.0' # pylint: disable=invalid-name diff --git a/services/solr-names-updater/src/solr_names_updater/worker.py b/services/solr-names-updater/src/solr_names_updater/worker.py index 309b9a7cd..e711c935f 100644 --- a/services/solr-names-updater/src/solr_names_updater/worker.py +++ b/services/solr-names-updater/src/solr_names_updater/worker.py @@ -67,11 +67,14 @@ def is_names_event_msg_type(msg: dict): def is_processable(msg: dict): """Determine if message is processable using message type of msg.""" - nr_num = msg.get('nrNum', None) - if msg and is_names_event_msg_type(msg) \ - and (nr := RequestDAO.find_by_nr(nr_num)) \ - and nr.entity_type_cd not in ('FR', 'GP'): - return True + with FLASK_APP.app_context(): + if msg and is_names_event_msg_type(msg) \ + and (nr_num := msg.get('data', {}) + .get('request', {}) + .get('nrNum', None)) \ + and (nr := RequestDAO.find_by_nr(nr_num)) \ + and nr.entity_type_cd not in ('FR', 'GP'): + return True return False diff --git a/services/solr-names-updater/tests/unit/test_names_processor.py b/services/solr-names-updater/tests/unit/test_names_processor.py index 57d5db2b6..a7dd6947e 100644 --- a/services/solr-names-updater/tests/unit/test_names_processor.py +++ b/services/solr-names-updater/tests/unit/test_names_processor.py @@ -86,7 +86,7 @@ async def test_should_add_names_to_solr( queue_util.send_name_request_state_msg = mock.Mock(return_value="True") nr_num = message_payload['data']['request']['nrNum'] nr_new_state = message_payload['data']['request']['newState'] - mock_nr = create_nr(nr_num, nr_new_state, names, names_state) + create_nr(nr_num, nr_new_state, names, names_state) mock_msg = create_queue_mock_message(message_payload) mock_response = MockResponse({}, 200) @@ -98,27 +98,25 @@ async def test_should_add_names_to_solr( with patch.object(worker, 'process_possible_conflicts_add', return_value=True): # mock process_possible_conflicts_delete to do nothing in order to isolate testing relevant to this test with patch.object(worker, 'process_possible_conflicts_delete', return_value=True): - # mock find_by_nr to do nothing in order to isolate testing relevant to this test - with patch.object(RequestDAO, 'find_by_nr', return_value=mock_nr): - await worker.cb_subscription_handler(mock_msg) + await worker.cb_subscription_handler(mock_msg) - if len(expected_names_to_add_to_solr) > 0: - assert mock_solr_feeder_api_post.called == True - assert 'api/v1/feeds' in mock_solr_feeder_api_post.call_args[0][0] + if len(expected_names_to_add_to_solr) > 0: + assert mock_solr_feeder_api_post.called == True + assert 'api/v1/feeds' in mock_solr_feeder_api_post.call_args[0][0] - post_json = mock_solr_feeder_api_post.call_args[1]['json'] - assert post_json['solr_core'] - assert post_json['solr_core'] == 'names' + post_json = mock_solr_feeder_api_post.call_args[1]['json'] + assert post_json['solr_core'] + assert post_json['solr_core'] == 'names' - request_json = post_json['request'] + request_json = post_json['request'] - for index, expect_name in enumerate(expected_names_to_add_to_solr): - assert expect_name in request_json + for index, expect_name in enumerate(expected_names_to_add_to_solr): + assert expect_name in request_json - for index, not_expect_name in enumerate(not_expected_names_to_add_to_solr): - assert not_expect_name not in request_json - else: - assert mock_solr_feeder_api_post.called == False + for index, not_expect_name in enumerate(not_expected_names_to_add_to_solr): + assert not_expect_name not in request_json + else: + assert mock_solr_feeder_api_post.called == False @pytest.mark.parametrize( @@ -179,21 +177,19 @@ async def test_should_delete_names_from_solr( with patch.object(requests, 'post', return_value=mock_response) as mock_solr_feeder_api_post: # mock process_possible_conflicts_delete to do nothing in order to isolate testing relevant to this test with patch.object(worker, 'process_possible_conflicts_delete', return_value=True): - # mock find_by_nr to do nothing in order to isolate testing relevant to this test - with patch.object(RequestDAO, 'find_by_nr', return_value=mock_nr): - await worker.cb_subscription_handler(mock_msg) + await worker.cb_subscription_handler(mock_msg) - assert mock_solr_feeder_api_post.called == True - assert 'api/v1/feeds' in mock_solr_feeder_api_post.call_args[0][0] + assert mock_solr_feeder_api_post.called == True + assert 'api/v1/feeds' in mock_solr_feeder_api_post.call_args[0][0] - post_json = mock_solr_feeder_api_post.call_args[1]['json'] - assert post_json['solr_core'] - assert post_json['solr_core'] == 'names' + post_json = mock_solr_feeder_api_post.call_args[1]['json'] + assert post_json['solr_core'] + assert post_json['solr_core'] == 'names' - request_json = post_json['request'] + request_json = post_json['request'] - assert 'delete' in request_json - assert len(nr_ids_to_delete_from_solr) > 0 - request_json = post_json['request'] - for nr_id in nr_ids_to_delete_from_solr: - assert nr_id in request_json + assert 'delete' in request_json + assert len(nr_ids_to_delete_from_solr) > 0 + request_json = post_json['request'] + for nr_id in nr_ids_to_delete_from_solr: + assert nr_id in request_json diff --git a/services/solr-names-updater/tests/unit/test_possible_conflicts_processor.py b/services/solr-names-updater/tests/unit/test_possible_conflicts_processor.py index c07a17870..f5e939297 100644 --- a/services/solr-names-updater/tests/unit/test_possible_conflicts_processor.py +++ b/services/solr-names-updater/tests/unit/test_possible_conflicts_processor.py @@ -115,7 +115,7 @@ async def test_should_add_possible_conflicts_to_solr( queue_util.send_name_request_state_msg = mock.Mock(return_value="True") nr_num = message_payload['data']['request']['nrNum'] - mock_nr = create_nr(nr_num, new_nr_state, names, name_states) + create_nr(nr_num, new_nr_state, names, name_states) mock_msg = create_queue_mock_message(message_payload) mock_response = MockResponse({}, 200) @@ -127,27 +127,25 @@ async def test_should_add_possible_conflicts_to_solr( with patch.object(worker, 'process_names_add', return_value=True): # mock process_possible_conflicts_delete to do nothing in order to isolate testing relevant to this test with patch.object(worker, 'process_possible_conflicts_delete', return_value=True): - # mock find_by_nr to do nothing in order to isolate testing relevant to this test - with patch.object(RequestDAO, 'find_by_nr', return_value=mock_nr): - await worker.cb_subscription_handler(mock_msg) + await worker.cb_subscription_handler(mock_msg) - if len(expected_conflicts_to_add_to_solr) > 0: - assert mock_solr_feeder_api_post.called == True - assert 'api/v1/feeds' in mock_solr_feeder_api_post.call_args[0][0] + if len(expected_conflicts_to_add_to_solr) > 0: + assert mock_solr_feeder_api_post.called == True + assert 'api/v1/feeds' in mock_solr_feeder_api_post.call_args[0][0] - post_json = mock_solr_feeder_api_post.call_args[1]['json'] - assert post_json['solr_core'] - assert post_json['solr_core'] == 'possible.conflicts' + post_json = mock_solr_feeder_api_post.call_args[1]['json'] + assert post_json['solr_core'] + assert post_json['solr_core'] == 'possible.conflicts' - request_json = post_json['request'] + request_json = post_json['request'] - for index, expect_name in enumerate(expected_conflicts_to_add_to_solr): - assert expect_name in request_json + for index, expect_name in enumerate(expected_conflicts_to_add_to_solr): + assert expect_name in request_json - for index, not_expect_name in enumerate(not_expected_conflicts_to_add_to_solr): - assert not_expect_name not in request_json - else: - assert mock_solr_feeder_api_post.called == False + for index, not_expect_name in enumerate(not_expected_conflicts_to_add_to_solr): + assert not_expect_name not in request_json + else: + assert mock_solr_feeder_api_post.called == False @pytest.mark.parametrize( @@ -206,16 +204,14 @@ async def test_should_delete_possible_conflict_from_solr( with patch.object(requests, 'post', return_value=mock_response) as mock_solr_feeder_api_post: # mock process_names_delete to do nothing in order to isolate testing relevant to this test with patch.object(worker, 'process_names_delete', return_value=True): - # mock find_by_nr to do nothing in order to isolate testing relevant to this test - with patch.object(RequestDAO, 'find_by_nr', return_value=mock_nr): - await worker.cb_subscription_handler(mock_msg) + await worker.cb_subscription_handler(mock_msg) - assert mock_solr_feeder_api_post.called == True - assert 'api/v1/feeds' in mock_solr_feeder_api_post.call_args[0][0] + assert mock_solr_feeder_api_post.called == True + assert 'api/v1/feeds' in mock_solr_feeder_api_post.call_args[0][0] - post_json = mock_solr_feeder_api_post.call_args[1]['json'] - assert post_json['solr_core'] - assert post_json['solr_core'] == 'possible.conflicts' + post_json = mock_solr_feeder_api_post.call_args[1]['json'] + assert post_json['solr_core'] + assert post_json['solr_core'] == 'possible.conflicts' - request_json = post_json['request'] - assert f'"delete": ["{mock_nr.nrNum}"]' in request_json + request_json = post_json['request'] + assert f'"delete": ["{mock_nr.nrNum}"]' in request_json