Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)