-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add checks and tests for manual OT emails (#4724)
* Add checks and tests for manual OT emails * Update test name * Add FeatureEntry entity for test --------- Co-authored-by: DanielRyanSmith <[email protected]>
- Loading branch information
1 parent
8197ba9
commit 871b13d
Showing
2 changed files
with
151 additions
and
2 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 |
---|---|---|
|
@@ -927,3 +927,138 @@ def test_fetch_webdx_feature_ids__exceptions(self, mock_list_features): | |
result = self.handler.get_template_data() | ||
|
||
self.assertEqual('Running FetchWebdxFeatureId() job failed.', result) | ||
|
||
|
||
class SendManualOTCreatedEmailTest(testing_config.CustomTestCase): | ||
|
||
def setUp(self): | ||
self.handler = maintenance_scripts.SendManualOTCreatedEmail() | ||
self.feature_1 = FeatureEntry( | ||
id=1, name='feature a', summary='sum', category=1) | ||
self.feature_1.put() | ||
self.ot_stage = Stage(id=111, | ||
feature_id=1, stage_type=150, ot_owner_email='[email protected]', | ||
ot_emails=['[email protected]'], ot_display_name='Example trial', | ||
ot_activation_date=date(2020, 1, 1)) | ||
self.ot_stage.put() | ||
self.ot_stage_id=self.ot_stage.key.integer_id() | ||
self.non_ot_stage = Stage(id=222, feature_id=1, stage_type=120) | ||
self.non_ot_stage.put() | ||
|
||
def tearDown(self): | ||
for kind in [Stage, FeatureEntry]: | ||
for entity in kind.query(): | ||
entity.key.delete() | ||
|
||
@mock.patch('framework.cloud_tasks_helpers.enqueue_task') | ||
def test_send__valid(self, mock_enqueue): | ||
"""An email is sent if the stage meets all requirements.""" | ||
result = self.handler.get_template_data(stage_id=self.ot_stage_id) | ||
self.assertEqual('Email task enqueued', result) | ||
mock_enqueue.assert_called_once() | ||
|
||
@mock.patch('framework.cloud_tasks_helpers.enqueue_task') | ||
def test_send__invalid_stage(self, mock_enqueue): | ||
"""No email is sent if the stage does not exist.""" | ||
result = self.handler.get_template_data(stage_id=12345) | ||
self.assertEqual('Stage 12345 not found', result) | ||
mock_enqueue.assert_not_called() | ||
|
||
@mock.patch('framework.cloud_tasks_helpers.enqueue_task') | ||
def test_send__non_ot_stage(self, mock_enqueue): | ||
"""No email is sent if the stage is not an OT stage.""" | ||
result = self.handler.get_template_data( | ||
stage_id=self.non_ot_stage.key.integer_id()) | ||
self.assertEqual('Stage 222 is not an origin trial stage', result) | ||
mock_enqueue.assert_not_called() | ||
|
||
@mock.patch('framework.cloud_tasks_helpers.enqueue_task') | ||
def test_send__no_contacts(self, mock_enqueue): | ||
"""No email is sent if the stage contains no OT contacts.""" | ||
self.ot_stage.ot_owner_email = None | ||
self.ot_stage.ot_emails = [] | ||
self.ot_stage.put() | ||
result = self.handler.get_template_data(stage_id=self.ot_stage_id) | ||
self.assertEqual('Stage 111 has no OT contacts set', result) | ||
mock_enqueue.assert_not_called() | ||
|
||
@mock.patch('framework.cloud_tasks_helpers.enqueue_task') | ||
def test_send__no_display_name(self, mock_enqueue): | ||
"""No email is sent if the stage does not have a display name.""" | ||
self.ot_stage.ot_display_name = None | ||
self.ot_stage.put() | ||
result = self.handler.get_template_data(stage_id=self.ot_stage_id) | ||
self.assertEqual('Stage 111 does not have ot_display_name set', result) | ||
mock_enqueue.assert_not_called() | ||
|
||
@mock.patch('framework.cloud_tasks_helpers.enqueue_task') | ||
def test_send__no_activation_date(self, mock_enqueue): | ||
"""No email is sent if the stage does not have a scheduled activation | ||
date.""" | ||
self.ot_stage.ot_activation_date = None | ||
self.ot_stage.put() | ||
result = self.handler.get_template_data(stage_id=self.ot_stage_id) | ||
self.assertEqual('Stage 111 does not have ot_activation_date set', result) | ||
mock_enqueue.assert_not_called() | ||
|
||
|
||
class SendManualOTActivatedEmailTest(testing_config.CustomTestCase): | ||
|
||
def setUp(self): | ||
self.handler = maintenance_scripts.SendManualOTActivatedEmail() | ||
self.feature_1 = FeatureEntry( | ||
id=1, name='feature a', summary='sum', category=1) | ||
self.feature_1.put() | ||
self.ot_stage = Stage(id=111, | ||
feature_id=1, stage_type=150, ot_owner_email='[email protected]', | ||
ot_emails=['[email protected]'], ot_display_name='Example trial') | ||
self.ot_stage.put() | ||
self.ot_stage_id=self.ot_stage.key.integer_id() | ||
self.non_ot_stage = Stage(id=222, feature_id=1, stage_type=120) | ||
self.non_ot_stage.put() | ||
|
||
def tearDown(self): | ||
for kind in [Stage, FeatureEntry]: | ||
for entity in kind.query(): | ||
entity.key.delete() | ||
|
||
@mock.patch('framework.cloud_tasks_helpers.enqueue_task') | ||
def test_send__valid(self, mock_enqueue): | ||
"""An email is sent if the stage meets all requirements.""" | ||
result = self.handler.get_template_data(stage_id=self.ot_stage_id) | ||
self.assertEqual('Email task enqueued', result) | ||
mock_enqueue.assert_called_once() | ||
|
||
@mock.patch('framework.cloud_tasks_helpers.enqueue_task') | ||
def test_send__invalid_stage(self, mock_enqueue): | ||
"""No email is sent if the stage does not exist.""" | ||
result = self.handler.get_template_data(stage_id=12345) | ||
self.assertEqual('Stage 12345 not found', result) | ||
mock_enqueue.assert_not_called() | ||
|
||
@mock.patch('framework.cloud_tasks_helpers.enqueue_task') | ||
def test_send__non_ot_stage(self, mock_enqueue): | ||
"""No email is sent if the stage is not an OT stage.""" | ||
result = self.handler.get_template_data( | ||
stage_id=self.non_ot_stage.key.integer_id()) | ||
self.assertEqual('Stage 222 is not an origin trial stage', result) | ||
mock_enqueue.assert_not_called() | ||
|
||
@mock.patch('framework.cloud_tasks_helpers.enqueue_task') | ||
def test_send__no_contacts(self, mock_enqueue): | ||
"""No email is sent if the stage contains no OT contacts.""" | ||
self.ot_stage.ot_owner_email = None | ||
self.ot_stage.ot_emails = [] | ||
self.ot_stage.put() | ||
result = self.handler.get_template_data(stage_id=self.ot_stage_id) | ||
self.assertEqual('Stage 111 has no OT contacts set', result) | ||
mock_enqueue.assert_not_called() | ||
|
||
@mock.patch('framework.cloud_tasks_helpers.enqueue_task') | ||
def test_send__no_display_name(self, mock_enqueue): | ||
"""No email is sent if the stage does not have a display name.""" | ||
self.ot_stage.ot_display_name = None | ||
self.ot_stage.put() | ||
result = self.handler.get_template_data(stage_id=self.ot_stage_id) | ||
self.assertEqual('Stage 111 does not have ot_display_name set', result) | ||
mock_enqueue.assert_not_called() |