def test_observer_not_created_for_no_notifications_level(self, observed_item):
        settings = create_fake_settings()
        settings_handler = ObservationManager()

        settings_handler.update_observers(settings, DECISION_NEW)

        self.assertFalse(observed_item.called)
Exemplo n.º 2
0
 def test_get_organization_returns_organization_for_decision(self):
     expected_organization = OrganizationFactory.build(id=1)
     decision = DecisionFactory.build(id=2,
                                      organization=expected_organization)
     settings_handler = ObservationManager()
     actual_organization = settings_handler._get_organization(decision)
     self.assertEqual(expected_organization, actual_organization)
 def test_get_settings_returns_settings_for_user(self):
     settings_handler = ObservationManager()
     user = UserFactory.build(id=1)
     settings = settings_handler.get_settings(
           user=user,
           organization=OrganizationFactory.build()
     )
     self.assertEqual(user, settings.user)
 def test_get_settings_returns_settings_for_organization(self):
     settings_handler = ObservationManager()
     organization = OrganizationFactory.build(id=2)
     settings = settings_handler.get_settings(
           user=UserFactory.build(),
           organization=organization
     )
     self.assertEqual(organization, settings.organization)
Exemplo n.º 5
0
    def test_observer_not_created_for_no_notifications_level(
            self, observed_item):
        settings = create_fake_settings()
        settings_handler = ObservationManager()

        settings_handler.update_observers(settings, DECISION_NEW)

        self.assertFalse(observed_item.called)
    def test_feedback_changed_observer_not_added_for_feedback_added_notification_level(self, observed_item):
        settings = create_fake_settings(
             notification_level=FEEDBACK_ADDED_NOTIFICATIONS
        )

        settings_handler = ObservationManager()
        settings_handler.update_observers(settings, FEEDBACK_CHANGE)
        self.assertFalse(observed_item.called)
Exemplo n.º 7
0
    def test_feedback_changed_observer_not_added_for_feedback_added_notification_level(
            self, observed_item):
        settings = create_fake_settings(
            notification_level=FEEDBACK_ADDED_NOTIFICATIONS)

        settings_handler = ObservationManager()
        settings_handler.update_observers(settings, FEEDBACK_CHANGE)
        self.assertFalse(observed_item.called)
    def test_include_watchers_not_run_for_minor_edits(self, include_watchers):
        item = DecisionFactory.build(id=1)
        item = add_watchers(item)

        settings_handler = ObservationManager()

        settings_handler.send_notifications([], item, MINOR_CHANGE, {}, {}, "")
        self.assertFalse(include_watchers.called)
    def test_feedback_created_observer_not_created_for_main_items_notification_level(self, observed_item):
        settings = create_fake_settings(
             notification_level=MAIN_ITEMS_NOTIFICATIONS_ONLY
        )

        settings_handler = ObservationManager()
        settings_handler.update_observers(settings, FEEDBACK_NEW)
        self.assertFalse(observed_item.called)
Exemplo n.º 10
0
def send_decision_notifications(decision, users):
    headers = {'Message-ID' : decision.get_message_id()}
    headers.update(STANDARD_SENDING_HEADERS)
    extra_context = {"observed": decision}
    observation_manager = ObservationManager()
    observation_manager.send_notifications(
                    users, decision, DECISION_NEW, extra_context, headers,
                    from_email=decision.get_email())
Exemplo n.º 11
0
 def test_include_watchers_adds_watchers_for_decision(self):
     decision = DecisionFactory.build(id=1)
     decision = add_watchers(decision)
     settings_handler = ObservationManager()
     settings_handler.include_watchers(decision)
     self.assertSetEqual(
         set([watcher.user for watcher in decision.watchers.all()]),
         settings_handler.recipient_list)
Exemplo n.º 12
0
    def test_include_watchers_not_run_for_minor_edits(self, include_watchers):
        item = DecisionFactory.build(id=1)
        item = add_watchers(item)

        settings_handler = ObservationManager()

        settings_handler.send_notifications([], item, MINOR_CHANGE, {}, {}, "")
        self.assertFalse(include_watchers.called)
Exemplo n.º 13
0
    def test_decision_change_observer_not_created_for_main_items_notification_level(self, observed_item):
        settings = create_fake_settings(
            notification_level=MAIN_ITEMS_NOTIFICATIONS_ONLY
        )

        settings_handler = ObservationManager()
        settings_handler.update_observers(settings, DECISION_CHANGE)

        self.assertFalse(observed_item.called)
Exemplo n.º 14
0
    def test_minor_change_observer_added_for_minor_changes_notification_level(self, observed_item):
        settings = NotificationSettingsFactory.build(
             notification_level=MINOR_CHANGES_NOTIFICATIONS
        )

        settings_handler = ObservationManager()
        settings_handler.update_observers(settings, MINOR_CHANGE)

        self.assertTrue(observed_item.called)
Exemplo n.º 15
0
    def test_comment_changed_observer_added_for_major_changes_notification_level(self, observed_item):
        settings = create_fake_settings(
             notification_level=FEEDBACK_MAJOR_CHANGES
        )

        settings_handler = ObservationManager()
        settings_handler.update_observers(settings, COMMENT_CHANGE)

        self.assertTrue(observed_item.called)
Exemplo n.º 16
0
 def test_get_organization_returns_organization_for_decision(self):
     expected_organization = OrganizationFactory.build(id=1)
     decision = DecisionFactory.build(
         id=2,
         organization=expected_organization
     )
     settings_handler = ObservationManager()
     actual_organization = settings_handler._get_organization(decision)
     self.assertEqual(expected_organization, actual_organization)
Exemplo n.º 17
0
    def test_minor_change_observer_not_added_for_major_changes_notification_level(
            self, observed_item):
        settings = create_fake_settings(
            notification_level=FEEDBACK_MAJOR_CHANGES)

        settings_handler = ObservationManager()
        settings_handler.update_observers(settings, MINOR_CHANGE)

        self.assertFalse(observed_item.called)
Exemplo n.º 18
0
 def test_get_settings_notification_level_deault_is_main_items_only(self):
     settings_handler = ObservationManager()
     settings = settings_handler.get_settings(
           user=UserFactory.build(),
           organization=OrganizationFactory.build()
     )
     self.assertEqual(
          FEEDBACK_MAJOR_CHANGES, settings.notification_level
     )
Exemplo n.º 19
0
    def test_comment_changed_observer_added_for_major_changes_notification_level(
            self, observed_item):
        settings = create_fake_settings(
            notification_level=FEEDBACK_MAJOR_CHANGES)

        settings_handler = ObservationManager()
        settings_handler.update_observers(settings, COMMENT_CHANGE)

        self.assertTrue(observed_item.called)
Exemplo n.º 20
0
 def test_include_watchers_adds_watchers_for_decision(self):
     decision = DecisionFactory.build(id=1)
     decision = add_watchers(decision)
     settings_handler = ObservationManager()
     settings_handler.include_watchers(decision)
     self.assertSetEqual(
         set([watcher.user for watcher in decision.watchers.all()]),
         settings_handler.recipient_list
     )
Exemplo n.º 21
0
    def test_minor_change_observer_not_added_for_major_changes_notification_level(self, observed_item):
        settings = create_fake_settings(
             notification_level=FEEDBACK_MAJOR_CHANGES
        )

        settings_handler = ObservationManager()
        settings_handler.update_observers(settings, MINOR_CHANGE)

        self.assertFalse(observed_item.called)
Exemplo n.º 22
0
    def test_minor_change_observer_added_for_minor_changes_notification_level(
            self, observed_item):
        settings = NotificationSettingsFactory.build(
            notification_level=MINOR_CHANGES_NOTIFICATIONS)

        settings_handler = ObservationManager()
        settings_handler.update_observers(settings, MINOR_CHANGE)

        self.assertTrue(observed_item.called)
Exemplo n.º 23
0
 def test_get_organization_returns_organization_for_comment(self):
     expected_organization = OrganizationFactory.build(id=1)
     decision = DecisionFactory.build(id=2,
                                      organization=expected_organization)
     feedback = FeedbackFactory.build(id=2, decision=decision)
     comment = CommentFactory.build()
     comment.content_object = feedback
     settings_handler = ObservationManager()
     actual_organization = settings_handler._get_organization(comment)
     self.assertEqual(expected_organization, actual_organization)
Exemplo n.º 24
0
 def _send_change_notifications(self, notification_type):
     headers = {'Message-ID': self.get_message_id()}
     headers.update(STANDARD_SENDING_HEADERS)
     org_users = self.organization.users.all()
     observation_manager = ObservationManager()
     observation_manager.send_notifications(org_users,
                                            self,
                                            notification_type,
                                            {"observed": self},
                                            headers=headers,
                                            from_email=self.get_email())
Exemplo n.º 25
0
def send_comment_notifications(comment, users):
    headers = {'Message-ID' : "comment-%s@%s" % (comment.id, Site.objects.get_current().domain)}
    headers.update(STANDARD_SENDING_HEADERS)
    headers.update({'In-Reply-To' : comment.content_object.get_message_id()})

    comment.content_object.decision.note_external_modification()

    observation_manager = ObservationManager()

    extra_context = dict({"observed": comment})
    observation_manager.send_notifications(users, comment, COMMENT_NEW, extra_context, headers, from_email=comment.content_object.decision.get_email())
Exemplo n.º 26
0
def send_decision_notifications(decision, users):
    headers = {'Message-ID': decision.get_message_id()}
    headers.update(STANDARD_SENDING_HEADERS)
    extra_context = {"observed": decision}
    observation_manager = ObservationManager()
    observation_manager.send_notifications(users,
                                           decision,
                                           DECISION_NEW,
                                           extra_context,
                                           headers,
                                           from_email=decision.get_email())
Exemplo n.º 27
0
 def test_include_watchers_adds_watchers_for_comments(self):
     decision = DecisionFactory.build(id=1)
     decision = add_watchers(decision)
     feedback = FeedbackFactory.build(id=2, decision=decision)
     comment = CommentFactory.build()
     comment.content_object = feedback
     settings_handler = ObservationManager()
     settings_handler.include_watchers(comment)
     self.assertSetEqual(
         set([watcher.user for watcher in decision.watchers.all()]),
         settings_handler.recipient_list)
Exemplo n.º 28
0
 def test_include_watchers_adds_watchers_for_comments(self):
     decision = DecisionFactory.build(id=1)
     decision = add_watchers(decision)
     feedback = FeedbackFactory.build(id=2, decision=decision)
     comment = CommentFactory.build()
     comment.content_object = feedback
     settings_handler = ObservationManager()
     settings_handler.include_watchers(comment)
     self.assertSetEqual(
             set([watcher.user for watcher in decision.watchers.all()]),
             settings_handler.recipient_list
     )
Exemplo n.º 29
0
 def test_get_organization_returns_organization_for_comment(self):
     expected_organization = OrganizationFactory.build(id=1)
     decision = DecisionFactory.build(
         id=2,
         organization=expected_organization
     )
     feedback = FeedbackFactory.build(id=2, decision=decision)
     comment = CommentFactory.build()
     comment.content_object = feedback
     settings_handler = ObservationManager()
     actual_organization = settings_handler._get_organization(comment)
     self.assertEqual(expected_organization, actual_organization)
Exemplo n.º 30
0
def decision_signal_handler(sender, **kwargs):
    """
    All users except the author will get a notification informing them of
    new content.
    All users are made observers of the decision.
    """
    instance = kwargs.get('instance')
    headers = {'Message-ID' : instance.get_message_id()}
    headers.update(STANDARD_SENDING_HEADERS)
    if kwargs.get('created', True):
        active_users = instance.organization.users.filter(is_active=True)
        extra_context = {"observed": instance}
        observation_manager = ObservationManager()
        observation_manager.send_notifications(active_users, instance, DECISION_NEW, extra_context, headers, from_email=instance.get_email())
Exemplo n.º 31
0
def feedback_signal_handler(sender, **kwargs):
    """
    All watchers of a decision will get a notification informing them of
    new feedback.
    All watchers become observers of the feedback.
    """
    instance = kwargs.get('instance')
    headers = {
        'Message-ID': instance.get_message_id(),
        'In-Reply-To': instance.decision.get_message_id(),
        'References': ' '.join((
            instance.decision.get_message_id(),
            instance.get_message_id()))
    }
    headers.update(STANDARD_SENDING_HEADERS)

    instance.decision.note_external_modification()

    observation_manager = ObservationManager()
    org_users = list(instance.decision.organization.users.filter(is_active=True))
    extra_context = dict({"observed": instance})

    if kwargs.get('created', True):
        # All watchers of parent get notified of new feedback.
        observation_manager.send_notifications(org_users, instance, FEEDBACK_NEW, extra_context, headers, from_email=instance.decision.get_email())
    else:
        # An edit by someone other than the author never counts as minor
        if instance.author != instance.editor or not instance.minor_edit:
            observation_manager.send_notifications(org_users, instance, FEEDBACK_CHANGE, extra_context, headers, from_email=instance.decision.get_email())
        else:
            observation_manager.send_notifications(org_users, instance, MINOR_CHANGE, extra_context, headers, from_email=instance.decision.get_email())
Exemplo n.º 32
0
def decision_signal_handler(sender, **kwargs):
    """
    All users except the author will get a notification informing them of
    new content.
    All users are made observers of the decision.
    """
    instance = kwargs.get('instance')
    headers = {'Message-ID': instance.get_message_id()}
    headers.update(STANDARD_SENDING_HEADERS)
    if kwargs.get('created', True):
        active_users = instance.organization.users.filter(is_active=True)
        extra_context = {"observed": instance}
        observation_manager = ObservationManager()
        observation_manager.send_notifications(active_users,
                                               instance,
                                               DECISION_NEW,
                                               extra_context,
                                               headers,
                                               from_email=instance.get_email())
Exemplo n.º 33
0
    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)
Exemplo n.º 34
0
def feedback_signal_handler(sender, **kwargs):
    """
    All watchers of a decision will get a notification informing them of
    new feedback.
    All watchers become observers of the feedback.
    """
    instance = kwargs.get('instance')
    headers = {
        'Message-ID':
        instance.get_message_id(),
        'In-Reply-To':
        instance.decision.get_message_id(),
        'References':
        ' '.join(
            (instance.decision.get_message_id(), instance.get_message_id()))
    }
    headers.update(STANDARD_SENDING_HEADERS)

    instance.decision.note_external_modification()

    observation_manager = ObservationManager()
    org_users = list(
        instance.decision.organization.users.filter(is_active=True))
    extra_context = dict({"observed": instance})

    if kwargs.get('created', True):
        # All watchers of parent get notified of new feedback.
        observation_manager.send_notifications(
            org_users,
            instance,
            FEEDBACK_NEW,
            extra_context,
            headers,
            from_email=instance.decision.get_email())
    else:
        # An edit by someone other than the author never counts as minor
        if instance.author != instance.editor or not instance.minor_edit:
            observation_manager.send_notifications(
                org_users,
                instance,
                FEEDBACK_CHANGE,
                extra_context,
                headers,
                from_email=instance.decision.get_email())
        else:
            observation_manager.send_notifications(
                org_users,
                instance,
                MINOR_CHANGE,
                extra_context,
                headers,
                from_email=instance.decision.get_email())
Exemplo n.º 35
0
def send_comment_notifications(comment, users):
    headers = {
        'Message-ID':
        "comment-%s@%s" % (comment.id, Site.objects.get_current().domain)
    }
    headers.update(STANDARD_SENDING_HEADERS)
    headers.update({'In-Reply-To': comment.content_object.get_message_id()})

    comment.content_object.decision.note_external_modification()

    observation_manager = ObservationManager()

    extra_context = dict({"observed": comment})
    observation_manager.send_notifications(
        users,
        comment,
        COMMENT_NEW,
        extra_context,
        headers,
        from_email=comment.content_object.decision.get_email())
Exemplo n.º 36
0
    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)
Exemplo n.º 37
0
 def _send_change_notifications(self, notification_type):
     headers = {'Message-ID': self.get_message_id()}
     headers.update(STANDARD_SENDING_HEADERS)
     org_users = self.organization.users.all()
     observation_manager = ObservationManager()
     observation_manager.send_notifications(org_users, self, notification_type, {"observed": self}, headers=headers, from_email=self.get_email())
Exemplo n.º 38
0
 def test_get_settings_notification_level_deault_is_main_items_only(self):
     settings_handler = ObservationManager()
     settings = settings_handler.get_settings(
         user=UserFactory.build(), organization=OrganizationFactory.build())
     self.assertEqual(FEEDBACK_MAJOR_CHANGES, settings.notification_level)
Exemplo n.º 39
0
 def test_get_settings_returns_settings_for_organization(self):
     settings_handler = ObservationManager()
     organization = OrganizationFactory.build(id=2)
     settings = settings_handler.get_settings(user=UserFactory.build(),
                                              organization=organization)
     self.assertEqual(organization, settings.organization)
Exemplo n.º 40
0
 def test_get_settings_returns_settings_for_user(self):
     settings_handler = ObservationManager()
     user = UserFactory.build(id=1)
     settings = settings_handler.get_settings(
         user=user, organization=OrganizationFactory.build())
     self.assertEqual(user, settings.user)