diff --git a/matchmaker/views/external_api.py b/matchmaker/views/external_api.py index f2cd6320e7..629ca4ba88 100644 --- a/matchmaker/views/external_api.py +++ b/matchmaker/views/external_api.py @@ -79,14 +79,7 @@ def mme_match_proxy(request, originating_node_name): patient_data=query_patient_data, origin_request_host=originating_node_name, ) - try: - _generate_notification_for_incoming_match(results, incoming_query, originating_node_name, query_patient_data) - except Exception as e: - logger.error('Unable to create notification for incoming MME match request for {} matches{}: {}'.format( - len(results), - ' ({})'.format(', '.join(sorted([result.get('patient', {}).get('id') for result in results]))) if results else '', - str(e)), - ) + _safe_generate_notification_for_incoming_match(results, incoming_query, originating_node_name, query_patient_data) return create_json_response({ 'results': sorted(results, key=lambda result: result['score']['patient'], reverse=True), @@ -94,7 +87,7 @@ def mme_match_proxy(request, originating_node_name): }) -def _generate_notification_for_incoming_match(results, incoming_query, incoming_request_node, incoming_patient): +def _safe_generate_notification_for_incoming_match(results, incoming_query, incoming_request_node, incoming_patient): """ Generate a SLACK notifcation to say that a VALID match request came in and the following results were sent back. If Slack is not supported, a message is not sent, but details persisted. diff --git a/matchmaker/views/external_api_tests.py b/matchmaker/views/external_api_tests.py index 0956b5ee8d..491cb4458f 100644 --- a/matchmaker/views/external_api_tests.py +++ b/matchmaker/views/external_api_tests.py @@ -399,9 +399,9 @@ def test_mme_match_proxy_phenotype_only(self, mock_post_to_slack, mock_email): mock.call().send(), ]) - @mock.patch('matchmaker.views.external_api.logger') + @mock.patch('seqr.utils.communication_utils.logger') @mock.patch('matchmaker.views.external_api.EmailMessage') - @mock.patch('matchmaker.views.external_api.safe_post_to_slack') + @mock.patch('seqr.utils.communication_utils._post_to_slack') def test_mme_match_proxy_no_results(self, mock_post_to_slack, mock_email, mock_logger): url = '/api/matchmaker/v1/match' request_body = { @@ -424,11 +424,12 @@ def test_mme_match_proxy_no_results(self, mock_post_to_slack, mock_email, mock_l self.assertEqual(incoming_query_q.count(), 1) self.assertIsNone(incoming_query_q.first().patient_id) - mock_post_to_slack.assert_called_with( - 'matchmaker_matches', - """A match request for 12345 came in from Test Institute today. + slack_message = """A match request for 12345 came in from Test Institute today. The contact information given was: test@test.com. We didn't find any individuals in matchbox that matched that query well, *so no results were sent back*.""" + mock_post_to_slack.assert_called_with( + 'matchmaker_matches', + slack_message ) mock_email.assert_not_called() @@ -440,6 +441,6 @@ def test_mme_match_proxy_no_results(self, mock_post_to_slack, mock_email, mock_l self.assertListEqual(response.json()['results'], []) self.assertEqual(MatchmakerIncomingQuery.objects.filter(institution='Test Institute').count(), 2) mock_logger.error.assert_called_with( - 'Unable to create notification for incoming MME match request for 0 matches: Slack connection error') + f'Slack error: Slack connection error: Original message in channel (matchmaker_matches) - {slack_message}')