def testNotifyBulkChangeTask_SubscriberGetsEmail(self): """If a user subscription matches the issue, notify that user.""" task = notify.NotifyBulkChangeTask(request=None, response=None, services=self.services) params = { 'send_email': 1, 'issue_ids': '%d' % (self.issue1.issue_id), 'seq': 0, 'old_owner_ids': '1', 'commenter_id': 1 } mr = testing_helpers.MakeMonorailRequest(user_info={'user_id': 1}, params=params, method='POST', services=self.services) self.services.user.TestAddUser('*****@*****.**', 4) sq = tracker_bizobj.MakeSavedQuery( 1, 'all open issues', 2, '', subscription_mode='immediate', executes_in_project_ids=[self.issue1.project_id]) self.services.features.UpdateUserSavedQueries('cnxn', 4, [sq]) result = task.HandleRequest(mr) self.VerifyParams(result, params) tasks = self.taskqueue_stub.get_filtered_tasks( url=urls.OUTBOUND_EMAIL_TASK + '.do') self.assertEqual(2, len(tasks))
def testFormatBulkIssues_LinkOnly_Multiple(self): """A user may not see full notification details for some changed issue.""" self.issue1.summary = 'one summary' self.issue1.labels = ['Restrict-View-Google'] self.issue2.summary = 'two summary' task = notify.NotifyBulkChangeTask(request=None, response=None, services=self.services) users_by_id = {} commenter_view = None config = self.services.config.GetProjectConfig('cnxn', 12345) addrperm = notify_reasons.AddrPerm(False, '*****@*****.**', self.nonmember, notify_reasons.REPLY_NOT_ALLOWED, None) subject, body = task._FormatBulkIssues([self.issue1, self.issue2], users_by_id, commenter_view, 'localhost:8080', 'test comment', [], config, addrperm) self.assertIn('2 issues', subject) self.assertNotIn('summary', subject) self.assertNotIn('one summary', body) self.assertIn('two summary', body) self.assertNotIn('test comment', body)
def testNotifyBulkChangeTask_ProjectNotify(self): """We generate email tasks for project.issue_notify_address.""" self.project.issue_notify_address = '*****@*****.**' task = notify.NotifyBulkChangeTask(request=None, response=None, services=self.services) params = { 'send_email': 1, 'seq': 0, 'issue_ids': '%d' % (self.issue1.issue_id), 'old_owner_ids': '1', 'commenter_id': 1 } mr = testing_helpers.MakeMonorailRequest(user_info={'user_id': 1}, params=params, method='POST', services=self.services) result = task.HandleRequest(mr) self.VerifyParams(result, params) tasks = self.taskqueue_stub.get_filtered_tasks( url=urls.OUTBOUND_EMAIL_TASK + '.do') self.assertEqual(2, len(tasks)) self.assertItemsEqual(['*****@*****.**', '*****@*****.**'], result['notified']) for task in tasks: task_params = json.loads(task.payload) # obfuscated email for non-members if 'user' in task_params['to']: self.assertIn(u'\u2026', task_params['from_addr']) # Full email for members if 'member' in task_params['to']: self.assertNotIn(u'\u2026', task_params['from_addr'])
def testNotifyBulkChangeTask(self): issue2 = MakeTestIssue(project_id=12345, local_id=2, owner_id=2, reporter_id=1) issue2.cc_ids = [3] self.services.issue.TestAddIssue(issue2) task = notify.NotifyBulkChangeTask(request=None, response=None, services=self.services) params = { 'send_email': 1, 'seq': 0, 'issue_ids': '%d,%d' % (self.issue1.issue_id, issue2.issue_id), 'old_owner_ids': '1,1', 'commenter_id': 1 } mr = testing_helpers.MakeMonorailRequest(user_info={'user_id': 1}, params=params, method='POST', services=self.services) result = task.HandleRequest(mr) self.VerifyParams(result, params) tasks = self.taskqueue_stub.get_filtered_tasks( url=urls.OUTBOUND_EMAIL_TASK + '.do') self.assertEqual(2, len(tasks)) for task in tasks: task_params = json.loads(task.payload) # obfuscated email for non-members if 'user' in task_params['to']: self.assertIn(u'\u2026', task_params['from_addr']) # Full email for members if 'member' in task_params['to']: self.assertNotIn(u'\u2026', task_params['from_addr'])
def testNotifyBulkChangeTask_CCAndSubscriberListsIssueOnce(self): """If a user both CCs and subscribes, include issue only once.""" task = notify.NotifyBulkChangeTask(request=None, response=None, services=self.services) params = { 'send_email': 1, 'issue_ids': '%d' % (self.issue1.issue_id), 'seq': 0, 'old_owner_ids': '1', 'commenter_id': 1 } mr = testing_helpers.MakeMonorailRequest(user_info={'user_id': 1}, params=params, method='POST', services=self.services) self.services.user.TestAddUser('*****@*****.**', 4) self.issue1.cc_ids = [4] sq = tracker_bizobj.MakeSavedQuery( 1, 'all open issues', 2, '', subscription_mode='immediate', executes_in_project_ids=[self.issue1.project_id]) self.services.features.UpdateUserSavedQueries('cnxn', 4, [sq]) result = task.HandleRequest(mr) self.VerifyParams(result, params) tasks = self.taskqueue_stub.get_filtered_tasks( url=urls.OUTBOUND_EMAIL_TASK + '.do') self.assertEqual(2, len(tasks)) found = False for task in tasks: task_params = json.loads(task.payload) if task_params['to'] == '*****@*****.**': found = True body = task_params['body'] self.assertEqual(1, body.count('Issue %d' % self.issue1.local_id)) self.assertTrue(found)
def testFormatBulkIssues_Normal_Single(self): """A user may see full notification details for all changed issues.""" self.issue1.summary = 'one summary' task = notify.NotifyBulkChangeTask(request=None, response=None, services=self.services) users_by_id = {} commenter_view = None config = self.services.config.GetProjectConfig('cnxn', 12345) addrperm = notify_reasons.AddrPerm(False, '*****@*****.**', self.nonmember, notify_reasons.REPLY_NOT_ALLOWED, None) subject, body = task._FormatBulkIssues([self.issue1], users_by_id, commenter_view, 'localhost:8080', 'test comment', [], config, addrperm) self.assertIn('one summary', subject) self.assertIn('one summary', body) self.assertIn('test comment', body)
def testNotifyBulkChangeTask_spam(self): issue2 = MakeTestIssue(project_id=12345, local_id=2, owner_id=2, reporter_id=1, is_spam=True) self.services.issue.TestAddIssue(issue2) task = notify.NotifyBulkChangeTask(request=None, response=None, services=self.services) params = { 'send_email': 1, 'issue_ids': '%d,%d' % (self.issue1.issue_id, issue2.issue_id), 'seq': 0, 'old_owner_ids': '1,1', 'commenter_id': 1 } mr = testing_helpers.MakeMonorailRequest(user_info={'user_id': 1}, params=params, method='POST', services=self.services) result = task.HandleRequest(mr) self.assertEquals(1, len(result['notified']))