-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Notify feature owners for accuracy emails (#4528)
* Send feature accuracy emails to owners only * nit
Showing
2 changed files
with
129 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
from internals.core_models import FeatureEntry, MilestoneSet, Stage | ||
from internals.review_models import Gate, Vote | ||
from internals import reminders | ||
from internals.user_models import UserPref | ||
|
||
from google.cloud import ndb # type: ignore | ||
|
||
|
@@ -110,27 +111,56 @@ def setUp(self): | |
|
||
self.feature_template.put() | ||
|
||
self.owner_user_pref = UserPref( | ||
email='[email protected]', | ||
notify_as_starrer=False) | ||
self.owner_user_pref.put() | ||
owner_user_pref_1 = UserPref( | ||
email='[email protected]', | ||
notify_as_starrer=False) | ||
owner_user_pref_1.put() | ||
owner_user_pref_2 = UserPref( | ||
email='[email protected]', | ||
notify_as_starrer=False) | ||
owner_user_pref_2.put() | ||
|
||
self.maxDiff = None | ||
|
||
def tearDown(self) -> None: | ||
kinds: list[ndb.Model] = [FeatureEntry, Stage] | ||
kinds: list[ndb.Model] = [FeatureEntry, Stage, UserPref] | ||
for kind in kinds: | ||
for entity in kind.query(): | ||
entity.key.delete() | ||
|
||
def test_choose_email_recipients__normal(self): | ||
"""Normal reminders go to feature participants.""" | ||
"""Normal reminders go to feature owners.""" | ||
actual = reminders.choose_email_recipients( | ||
self.feature_template, False) | ||
self.feature_template, False, False) | ||
expected = ['[email protected]', | ||
] | ||
self.assertEqual(set(actual), set(expected)) | ||
|
||
def test_choose_email_recipients__owners_bounced(self): | ||
"""Normal reminders go to feature participants when owners' emails | ||
are bounced.""" | ||
self.owner_user_pref.bounced = True | ||
self.owner_user_pref.put() | ||
|
||
actual = reminders.choose_email_recipients( | ||
self.feature_template, False, False) | ||
expected = ['[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
] | ||
self.assertEqual(set(actual), set(expected)) | ||
|
||
@mock.patch('settings.PROD', True) | ||
def test_choose_email_recipients__escalated(self): | ||
"""Escalated reminders go to feature participants and lists.""" | ||
actual = reminders.choose_email_recipients( | ||
self.feature_template, True) | ||
self.feature_template, True, False) | ||
expected = ['[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
|
@@ -140,15 +170,50 @@ def test_choose_email_recipients__escalated(self): | |
] | ||
self.assertEqual(set(actual), set(expected)) | ||
|
||
def test_choose_email_recipients__normal_accuracy_email(self): | ||
"""Normal accuracy emails go to feature owners.""" | ||
actual = reminders.choose_email_recipients( | ||
self.feature_template, False, True) | ||
expected = ['[email protected]', | ||
] | ||
self.assertEqual(set(actual), set(expected)) | ||
|
||
def test_choose_email_recipients__normal_accuracy_email_when_owners_bounced(self): | ||
"""Normal accuracy emails go to feature participants when owners' emails | ||
are bounced.""" | ||
self.owner_user_pref.bounced = True | ||
self.owner_user_pref.put() | ||
|
||
actual = reminders.choose_email_recipients( | ||
self.feature_template, False, True) | ||
expected = ['[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
] | ||
self.assertEqual(set(actual), set(expected)) | ||
|
||
@mock.patch('settings.PROD', True) | ||
def test_choose_email_recipients_escalated_accuracy_email(self): | ||
"""Escalated accuracy emails go to feature owners.""" | ||
actual = reminders.choose_email_recipients( | ||
self.feature_template, True, True) | ||
expected = ['[email protected]', | ||
] | ||
self.assertEqual(set(actual), set(expected)) | ||
|
||
def test_build_email_tasks_feature_accuracy(self): | ||
with test_app.app_context(): | ||
handler = reminders.FeatureAccuracyHandler() | ||
actual = reminders.build_email_tasks( | ||
[(self.feature_template, 100)], | ||
'Action requested - Verify %s', | ||
handler.EMAIL_TEMPLATE_PATH, | ||
self.current_milestone_info, | ||
handler.should_escalate_notification) | ||
[(self.feature_template, 100)], | ||
'Action requested - Verify %s', | ||
handler.EMAIL_TEMPLATE_PATH, | ||
self.current_milestone_info, | ||
handler.should_escalate_notification, | ||
handler.is_accuracy_email, | ||
) | ||
|
||
self.assertEqual(1, len(actual)) | ||
task = actual[0] | ||
|
@@ -163,11 +228,13 @@ def test_build_email_tasks_feature_accuracy__enterprise(self): | |
with test_app.app_context(): | ||
handler = reminders.FeatureAccuracyHandler() | ||
actual = reminders.build_email_tasks( | ||
[(self.feature_template, 110)], | ||
'Action requested - Verify %s', | ||
handler.EMAIL_TEMPLATE_PATH, | ||
self.current_milestone_info, | ||
handler.should_escalate_notification) | ||
[(self.feature_template, 110)], | ||
'Action requested - Verify %s', | ||
handler.EMAIL_TEMPLATE_PATH, | ||
self.current_milestone_info, | ||
handler.should_escalate_notification, | ||
handler.is_accuracy_email, | ||
) | ||
|
||
self.assertEqual(1, len(actual)) | ||
task = actual[0] | ||
|
@@ -186,13 +253,15 @@ def test_build_email_tasks_feature_accuracy__escalated(self): | |
with test_app.app_context(): | ||
handler = reminders.FeatureAccuracyHandler() | ||
actual = reminders.build_email_tasks( | ||
[(self.feature_template, 100)], | ||
'Action requested - Verify %s', | ||
handler.EMAIL_TEMPLATE_PATH, | ||
self.current_milestone_info, | ||
handler.should_escalate_notification) | ||
[(self.feature_template, 100)], | ||
'Action requested - Verify %s', | ||
handler.EMAIL_TEMPLATE_PATH, | ||
self.current_milestone_info, | ||
handler.should_escalate_notification, | ||
handler.is_accuracy_email, | ||
) | ||
|
||
self.assertEqual(5, len(actual)) | ||
self.assertEqual(1, len(actual)) | ||
task = actual[0] | ||
self.assertEqual( | ||
'Escalation request - Verify feature one', task['subject']) | ||
|
@@ -205,9 +274,13 @@ def test_build_email_tasks_prepublication(self): | |
with test_app.app_context(): | ||
handler = reminders.PrepublicationHandler() | ||
actual = reminders.build_email_tasks( | ||
[(self.feature_template, 100)], 'Action requested - Verify %s', | ||
handler.EMAIL_TEMPLATE_PATH, | ||
self.current_milestone_info, handler.should_escalate_notification) | ||
[(self.feature_template, 100)], | ||
'Action requested - Verify %s', | ||
handler.EMAIL_TEMPLATE_PATH, | ||
self.current_milestone_info, | ||
handler.should_escalate_notification, | ||
handler.is_accuracy_email, | ||
) | ||
self.assertEqual(1, len(actual)) | ||
task = actual[0] | ||
self.assertEqual('[email protected]', task['to']) | ||
|
@@ -222,13 +295,24 @@ class FeatureAccuracyHandlerTest(testing_config.CustomTestCase): | |
def setUp(self): | ||
self.feature_1, self.feature_2, self.feature_3 = make_test_features() | ||
self.handler = reminders.FeatureAccuracyHandler() | ||
self.owner_user_pref_1 = UserPref( | ||
email='[email protected]', | ||
notify_as_starrer=False) | ||
self.owner_user_pref_1.put() | ||
self.owner_user_pref_2 = UserPref( | ||
email='[email protected]', | ||
notify_as_starrer=False) | ||
self.owner_user_pref_2.put() | ||
|
||
def tearDown(self): | ||
self.feature_1.key.delete() | ||
self.feature_2.key.delete() | ||
self.feature_3.key.delete() | ||
for stage in Stage.query(): | ||
stage.key.delete() | ||
self.owner_user_pref_1.key.delete() | ||
self.owner_user_pref_2.key.delete() | ||
|
||
|
||
@mock.patch('requests.get') | ||
def test_determine_features_to_notify__no_features(self, mock_get): | ||
|
@@ -281,11 +365,8 @@ def test_determine_features_to_notify__escalated(self, mock_get): | |
with test_app.app_context(): | ||
result = self.handler.get_template_data() | ||
# More email tasks should be created to notify extended contributors. | ||
expected_message = ('5 email(s) sent or logged.\n' | ||
expected_message = ('2 email(s) sent or logged.\n' | ||
'Recipients:\n' | ||
'[email protected]\n' | ||
'[email protected]\n' | ||
'[email protected]\n' | ||
'[email protected]\n' | ||
'[email protected]') | ||
expected = {'message': expected_message} | ||
|