Skip to content

Commit

Permalink
applied reviewed changes (#1199)
Browse files Browse the repository at this point in the history
  • Loading branch information
ozamani9 authored Dec 1, 2021
1 parent 5f556db commit 9f74d17
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
Development release segment: .devN
"""

__version__ = '0.2.0' # pylint: disable=invalid-name
__version__ = '0.3.0' # pylint: disable=invalid-name
13 changes: 8 additions & 5 deletions services/solr-names-updater/src/solr_names_updater/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
58 changes: 27 additions & 31 deletions services/solr-names-updater/tests/unit/test_names_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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(
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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(
Expand Down Expand Up @@ -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

0 comments on commit 9f74d17

Please sign in to comment.