示例#1
0
 def test_new_feedback_notification(self):
     """
     When new feedback is added to a decision notifcations
     should be sent to all users watching the decision.
     """
     org = self.bettysorg
     [
         NotificationSettingsFactory(
             user=user,
             organization=org,
             notification_level=FEEDBACK_ADDED_NOTIFICATIONS)
         for user in org.users.all()
     ]
     decision = self.make_decision(organization=org)
     mail.outbox = []
     all_members = decision.organization.users.all().exclude(
         username=self.user.username)
     self.login(all_members[0].username)
     self.create_feedback_through_browser(decision.id)
     outbox = getattr(mail, 'outbox')
     outbox_to = [to for to_list in outbox for to in to_list.to]
     user_list = [
         user_object.email
         for user_object in decision.organization.users.exclude(
             is_active=False)
     ]
     self.assertItemsEqual(user_list, outbox_to)
示例#2
0
 def test_new_comment_notification(self):
     """
     When a new comment is added to feedback notifcations
     should be sent to all users watching the decision.
     """
     [
         NotificationSettingsFactory(
             user=user,
             organization=self.bettysorg,
             notification_level=FEEDBACK_MAJOR_CHANGES)
         for user in self.bettysorg.users.all()
     ]
     decision = self.make_decision(organization=self.bettysorg)
     feedback = self.make_feedback(decision=decision)
     mail.outbox = []
     feedback_type = ContentType.objects.get(app_label="publicweb",
                                             model="feedback")
     comment = self.make_comment(user=self.user,
                                 content_object=feedback,
                                 object_pk=feedback.id,
                                 content_type=feedback_type,
                                 submit_date=timezone.now(),
                                 site=Site.objects.get_current())
     outbox = getattr(mail, 'outbox')
     outbox_to = [to for to_list in outbox for to in to_list.to]
     all_members = comment.content_object.decision.organization.users.exclude(
         is_active=False)
     user_list = [user_object.email for user_object in all_members]
     self.assertItemsEqual(user_list, outbox_to)
示例#3
0
 def setUp(self):
     user = UserFactory()
     self.decision = DecisionFactory(author=user, description="Eat Cheese")
     watcher = UserFactory(email="*****@*****.**")
     organization = self.decision.organization
     self.settings = NotificationSettingsFactory(
         user=watcher,
         organization=organization,
         notification_level=FEEDBACK_ADDED_NOTIFICATIONS)
     OrganizationUserFactory(user=watcher, organization=organization)
    def test_send_notifications_for_main_items_sends_correct_messages(self):
        initial_count = len(mail.outbox)

        number_of_users = 3

        organization = OrganizationFactory()
        decision = DecisionFactory(organization=organization)
        decision = add_watchers(decision)

        user1, user2, user3 = UserFactory.create_batch(number_of_users,
                                                       email="*****@*****.**")

        NotificationSettingsFactory(user=user1,
                                    organization=organization,
                                    notification_level=NO_NOTIFICATIONS),
        NotificationSettingsFactory(
            user=user2,
            organization=organization,
            notification_level=MAIN_ITEMS_NOTIFICATIONS_ONLY),
        NotificationSettingsFactory(
            user=user3,
            organization=organization,
            notification_level=MINOR_CHANGES_NOTIFICATIONS),

        settings_handler = ObservationManager()

        recipients = [user1, user2, user3]

        settings_handler.send_notifications(
            recipients, decision, DECISION_NEW, {"observed": decision}, {
                'Message-ID': decision.get_message_id(),
                'Precedence': 'bulk',
                'Auto-Submitted': 'auto-generated'
            }, "*****@*****.**")

        final_count = len(mail.outbox)
        expected_number_messages_sent = len(
            decision.watchers.all()) + number_of_users - 1
        actual_number_messages_sent = final_count - initial_count

        self.assertEqual(expected_number_messages_sent,
                         actual_number_messages_sent)
示例#5
0
 def setUp(self):
     mail.outbox = []
     self.user = UserFactory(email="*****@*****.**")
     decision = DecisionFactory(author=self.user)
     feedbackAuthor = UserFactory(email="*****@*****.**")
     self.feedback = FeedbackFactory(decision=decision,
                                     description="Not so fast",
                                     author=feedbackAuthor,
                                     editor=feedbackAuthor)
     organization = decision.organization
     self.settings = NotificationSettingsFactory(
         user=self.user,
         organization=organization,
         notification_level=FEEDBACK_MAJOR_CHANGES)
     OrganizationUserFactory(user=self.user, organization=organization)