def setUp(self): super(NotificationTestCase, self).setUp() self.env.config.set('notification', 'smtp_enabled', 'true') self.env.config.set('notification', 'always_notify_owner', 'true') self.env.config.set('notification', 'always_notify_reporter', 'true') self.env.config.set('notification', 'smtp_always_cc', '[email protected], [email protected]') self.env.config.set('notification', 'use_public_cc', 'true') self.env.config.set('notification', 'smtp_port', str(SMTP_TEST_PORT)) self.env.config.set('notification', 'smtp_server', 'localhost') self.notifier = RelationNotifyEmail(self.env)
def delete(self, relation_id, when=None): if when is None: when = datetime.now(utc) relation = Relation.load_by_relation_id(self.env, relation_id) source = relation.source destination = relation.destination relation_type = relation.type with self.env.db_transaction: cloned_relation = relation.clone() relation.delete() other_end = self.link_ends_map[relation_type] if other_end: reverted_relation = Relation(self.env, keys=dict( source=destination, destination=source, type=other_end, )) reverted_relation.delete() for listener in self.changing_listeners: listener.deleting_relation(cloned_relation, when) from bhrelations.notification import RelationNotifyEmail RelationNotifyEmail(self.env).notify(cloned_relation, deleted=when)
def add_relation(self, relation): self.validate(relation) with self.env.db_transaction: relation.insert() reverted_relation = self.get_reverted_relation(relation) if reverted_relation: reverted_relation.insert() for listener in self.changing_listeners: listener.adding_relation(relation) from bhrelations.notification import RelationNotifyEmail RelationNotifyEmail(self.env).notify(relation)
def test_recipients_of_both_related_tickets_get_notified(self): """To/Cc recipients""" ticket = self._insert_and_load_ticket( 'Foo', reporter= '"Joe User" < *****@*****.** >', owner='*****@*****.**', cc='[email protected], [email protected], ' '*****@*****.**' ) ticket2 = self._insert_and_load_ticket( 'Bar', reporter='"Bob User" < *****@*****.** >', owner='*****@*****.**', cc='[email protected], [email protected], ' '*****@*****.**') relation = self.relations_system.add( ticket, ticket2, "dependent") rn = RelationNotifyEmail(self.env) rn.notify(relation) recipients = self.smtpd.get_recipients() # checks there is no duplicate in the recipient list rcpts = [] for r in recipients: self.failIf(r in rcpts) rcpts.append(r) # checks that all cc recipients have been notified cc_list = self.env.config.get('notification', 'smtp_always_cc') cc_list = "%s, %s, %s" % (cc_list, ticket['cc'], ticket2['cc']) for r in cc_list.replace(',', ' ').split(): self.failIf(r not in recipients) # checks that both owners have been notified self.failIf(smtp_address(ticket['owner']) not in recipients) self.failIf(smtp_address(ticket2['owner']) not in recipients) # checks that both reporters have been notified self.failIf(smtp_address(ticket['reporter']) not in recipients) self.failIf(smtp_address(ticket2['reporter']) not in recipients)
def notify_relation_changed(self, relation): from bhrelations.notification import RelationNotifyEmail RelationNotifyEmail(self.env).notify(relation)
class NotificationTestCase(BaseRelationsTestCase): @classmethod def setUpClass(cls): cls.smtpd = CustomSMTPThreadedServer(SMTP_TEST_PORT) cls.smtpd.start() @classmethod def tearDownClass(cls): cls.smtpd.stop() def setUp(self): super(NotificationTestCase, self).setUp() self.env.config.set('notification', 'smtp_enabled', 'true') self.env.config.set('notification', 'always_notify_owner', 'true') self.env.config.set('notification', 'always_notify_reporter', 'true') self.env.config.set('notification', 'smtp_always_cc', '[email protected], [email protected]') self.env.config.set('notification', 'use_public_cc', 'true') self.env.config.set('notification', 'smtp_port', str(SMTP_TEST_PORT)) self.env.config.set('notification', 'smtp_server', 'localhost') self.notifier = RelationNotifyEmail(self.env) def tearDown(self): super(NotificationTestCase, self).tearDown() self.smtpd.cleanup() def test_recipients_of_both_related_tickets_get_notified(self): """To/Cc recipients""" ticket = self._insert_and_load_ticket( 'Foo', reporter= '"Joe User" < *****@*****.** >', owner='*****@*****.**', cc='[email protected], [email protected], ' '*****@*****.**' ) ticket2 = self._insert_and_load_ticket( 'Bar', reporter='"Bob User" < *****@*****.** >', owner='*****@*****.**', cc='[email protected], [email protected], ' '*****@*****.**') relation = self.add_relation(ticket, DEPENDENCY_OF, ticket2) self.notifier.notify(relation) recipients = self.smtpd.get_recipients() # checks there is no duplicate in the recipient list rcpts = [] for r in recipients: self.failIf(r in rcpts) rcpts.append(r) # checks that all cc recipients have been notified cc_list = self.env.config.get('notification', 'smtp_always_cc') cc_list = "%s, %s, %s" % (cc_list, ticket['cc'], ticket2['cc']) for r in cc_list.replace(',', ' ').split(): self.failIf(r not in recipients) # checks that both owners have been notified self.failIf(smtp_address(ticket['owner']) not in recipients) self.failIf(smtp_address(ticket2['owner']) not in recipients) # checks that both reporters have been notified self.failIf(smtp_address(ticket['reporter']) not in recipients) self.failIf(smtp_address(ticket2['reporter']) not in recipients) def test_no_recipient_results_in_no_notification(self): self.env.config.set('notification', 'smtp_always_cc', '') ticket = self._insert_and_load_ticket('Foo', reporter='anonymous') ticket2 = self._insert_and_load_ticket('Bar', reporter='anonymous') relation = self.add_relation(ticket, DEPENDENCY_OF, ticket2) self.notifier.notify(relation) sender = self.smtpd.get_sender() recipients = self.smtpd.get_recipients() message = self.smtpd.get_message() # checks that no message has been sent self.failIf(recipients) self.failIf(sender) self.failIf(message) def test_one_email_per_relation(self): ticket = self._insert_and_load_ticket('Foo', reporter='anonymous') ticket2 = self._insert_and_load_ticket('Bar', reporter='anonymous') relation = self.add_relation(ticket, DEPENDENCY_OF, ticket2) self.notifier.notify(relation) relations = self.env.db_direct_query( "SELECT * FROM bloodhound_relations") self.assertEqual(len(relations), 2) self.assertEqual(self.smtpd.messages_received(), 1) self.smtpd.cleanup() self.relations_system.delete(relation.get_relation_id()) relations = self.env.db_direct_query( "SELECT * FROM bloodhound_relations") self.assertEqual(len(relations), 0) self.assertEqual(self.smtpd.messages_received(), 1)
class NotificationTestCase(BaseRelationsTestCase): @classmethod def setUpClass(cls): cls.smtpd = CustomSMTPThreadedServer(SMTP_TEST_PORT) cls.smtpd.start() @classmethod def tearDownClass(cls): cls.smtpd.stop() def setUp(self): super(NotificationTestCase, self).setUp() self.env.config.set('notification', 'smtp_enabled', 'true') self.env.config.set('notification', 'always_notify_owner', 'true') self.env.config.set('notification', 'always_notify_reporter', 'true') self.env.config.set('notification', 'smtp_always_cc', '[email protected], [email protected]') self.env.config.set('notification', 'use_public_cc', 'true') self.env.config.set('notification', 'smtp_port', str(SMTP_TEST_PORT)) self.env.config.set('notification', 'smtp_server', 'localhost') self.notifier = RelationNotifyEmail(self.env) def tearDown(self): super(NotificationTestCase, self).tearDown() self.smtpd.cleanup() def test_recipients_of_both_related_tickets_get_notified(self): """To/Cc recipients""" ticket = self._insert_and_load_ticket( 'Foo', reporter='"Joe User" < *****@*****.** >', owner='*****@*****.**', cc='[email protected], [email protected], ' '*****@*****.**') ticket2 = self._insert_and_load_ticket( 'Bar', reporter='"Bob User" < *****@*****.** >', owner='*****@*****.**', cc='[email protected], [email protected], ' '*****@*****.**') relation = self.add_relation(ticket, DEPENDENCY_OF, ticket2) self.notifier.notify(relation) recipients = self.smtpd.get_recipients() # checks there is no duplicate in the recipient list rcpts = [] for r in recipients: self.failIf(r in rcpts) rcpts.append(r) # checks that all cc recipients have been notified cc_list = self.env.config.get('notification', 'smtp_always_cc') cc_list = "%s, %s, %s" % (cc_list, ticket['cc'], ticket2['cc']) for r in cc_list.replace(',', ' ').split(): self.failIf(r not in recipients) # checks that both owners have been notified self.failIf(smtp_address(ticket['owner']) not in recipients) self.failIf(smtp_address(ticket2['owner']) not in recipients) # checks that both reporters have been notified self.failIf(smtp_address(ticket['reporter']) not in recipients) self.failIf(smtp_address(ticket2['reporter']) not in recipients) def test_no_recipient_results_in_no_notification(self): self.env.config.set('notification', 'smtp_always_cc', '') ticket = self._insert_and_load_ticket('Foo', reporter='anonymous') ticket2 = self._insert_and_load_ticket('Bar', reporter='anonymous') relation = self.add_relation(ticket, DEPENDENCY_OF, ticket2) self.notifier.notify(relation) sender = self.smtpd.get_sender() recipients = self.smtpd.get_recipients() message = self.smtpd.get_message() # checks that no message has been sent self.failIf(recipients) self.failIf(sender) self.failIf(message) def test_one_email_per_relation(self): ticket = self._insert_and_load_ticket('Foo', reporter='anonymous') ticket2 = self._insert_and_load_ticket('Bar', reporter='anonymous') relation = self.add_relation(ticket, DEPENDENCY_OF, ticket2) self.notifier.notify(relation) relations = self.env.db_direct_query( "SELECT * FROM bloodhound_relations") self.assertEqual(len(relations), 2) self.assertEqual(self.smtpd.messages_received(), 1) self.smtpd.cleanup() self.relations_system.delete(relation.get_relation_id()) relations = self.env.db_direct_query( "SELECT * FROM bloodhound_relations") self.assertEqual(len(relations), 0) self.assertEqual(self.smtpd.messages_received(), 1)