Exemplo n.º 1
0
class DecisionNotificationTest(TestCase):
    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_edit_triggers_email(self):
        mail.outbox = []
        self.decision.description = "Make Cheese"
        self.decision.save()
        self.assertGreater(len(mail.outbox), 0)

    def test_minor_edit_triggers_no_email(self):
        mail.outbox = []
        self.decision.description = "Eat Cheese!"
        self.decision.minor_edit = True
        self.decision.save()
        self.assertEqual(len(mail.outbox), 0)
class DecisionNotificationTest(TestCase):
    def setUp(self):
        user = UserFactory()
        self.decision = DecisionFactory(author=user, description="Eat Cheese")
        watcher = UserFactory(email="*****@*****.**")
        notification.observe(self.decision, watcher, 'decision_change')

    def test_edit_triggers_email(self):
        mail.outbox = []
        self.decision.description = "Make Cheese"
        self.decision.save()
        self.assertGreater(len(mail.outbox), 0)

    def test_minor_edit_triggers_no_email(self):
        mail.outbox = []
        self.decision.description = "Eat Cheese!"
        self.decision.minor_edit = True
        self.decision.save()
        self.assertEqual(len(mail.outbox), 0)
Exemplo n.º 3
0
class DecisionNotificationTest(TestCase):
    def setUp(self):
        user = UserFactory()
        self.decision = DecisionFactory(author=user, description="Eat Cheese")
        watcher = UserFactory(email="*****@*****.**")
        notification.observe(self.decision, watcher, 'decision_change')

    def test_edit_triggers_email(self):
        mail.outbox = []
        self.decision.description = "Make Cheese"
        self.decision.save()
        self.assertGreater(len(mail.outbox), 0)

    def test_minor_edit_triggers_no_email(self):
        mail.outbox = []
        self.decision.description = "Eat Cheese!"
        self.decision.minor_edit = True
        self.decision.save()
        self.assertEqual(len(mail.outbox), 0)
Exemplo n.º 4
0
class DecisionLastModifiedTest(TestCase):
    """
    Tests updating of 'last_modified' date on Decision.
    """
    def setUp(self):
        self.user = UserFactory()
        self.decision = DecisionFactory()

        # Ensure value of "now" always increases by amount sufficient
        # to show up as a change, even if db resolution for datetime
        # is one second.
        def now_iter(start):
            t = start
            while True:
                t += datetime.timedelta(hours=1)
                yield t

        minimock.mock("timezone.now",
                      returns_iter=now_iter(timezone.now()),
                      tracker=None)

    def tearDown(self):
        minimock.restore()

    def last_modified(self):
        """
        Gets the last modified date of the test decision.
        """
        return Decision.objects.get(id=self.decision.id).last_modified

    def test_edit_decision_editor(self):
        orig_last_modified = self.last_modified()
        self.decision.editor = UserFactory()
        self.decision.save()
        self.assertEquals(orig_last_modified, self.last_modified())

    def test_edit_decision_description(self):
        orig_last_modified = self.last_modified()
        self.decision.description += "x"
        self.decision.save()
        self.assertTrue(orig_last_modified < self.last_modified())

    def test_add_feedback_triggers_update(self):
        orig_last_modified = self.last_modified()
        feedback = FeedbackFactory(decision=self.decision, author=self.user)
        self.assertTrue(orig_last_modified < self.last_modified())

    def test_add_comment_triggers_update(self):
        feedback = FeedbackFactory(decision=self.decision, author=self.user)
        orig_last_modified = self.last_modified()
        comment = CommentFactory(content_object=feedback, user=self.user)
        self.assertTrue(orig_last_modified < self.last_modified())

    def test_add_watcher_triggers_no_update(self):
        orig_last_modified = self.last_modified()
        notification.observe(self.decision, UserFactory(), 'decision_change')
        self.decision.save()
        self.assertTrue(orig_last_modified == self.last_modified())
Exemplo n.º 5
0
class DecisionLastModifiedTest(TestCase):
    """
    Tests updating of 'last_modified' date on Decision.
    """

    def setUp(self):
        self.user = UserFactory()
        self.decision = DecisionFactory()

        # Ensure value of "now" always increases by amount sufficient
        # to show up as a change, even if db resolution for datetime
        # is one second.
        def now_iter(start):
            t = start
            while True:
                t += datetime.timedelta(hours=1)
                yield t

        minimock.mock("timezone.now", returns_iter=now_iter(timezone.now()), tracker=None)

    def tearDown(self):
        minimock.restore()

    def last_modified(self):
        """
        Gets the last modified date of the test decision.
        """
        return Decision.objects.get(id=self.decision.id).last_modified

    def test_edit_decision_editor(self):
        orig_last_modified = self.last_modified()
        self.decision.editor = UserFactory()
        self.decision.save()
        self.assertEquals(orig_last_modified, self.last_modified())

    def test_edit_decision_description(self):
        orig_last_modified = self.last_modified()
        self.decision.description += "x"
        self.decision.save()
        self.assertTrue(orig_last_modified < self.last_modified())

    def test_add_feedback_triggers_update(self):
        orig_last_modified = self.last_modified()
        feedback = FeedbackFactory(decision=self.decision, author=self.user)
        self.assertTrue(orig_last_modified < self.last_modified())

    def test_add_comment_triggers_update(self):
        feedback = FeedbackFactory(decision=self.decision, author=self.user)
        orig_last_modified = self.last_modified()
        comment = CommentFactory(content_object=feedback, user=self.user)
        self.assertTrue(orig_last_modified < self.last_modified())

    def test_add_watcher_triggers_no_update(self):
        orig_last_modified = self.last_modified()
        notification.observe(self.decision, UserFactory(), "decision_change")
        self.decision.save()
        self.assertTrue(orig_last_modified == self.last_modified())
Exemplo n.º 6
0
class DecisionNotificationTest(TestCase):
    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_edit_triggers_email(self):
        mail.outbox = []
        self.decision.description = "Make Cheese"
        self.decision.save()
        self.assertGreater(len(mail.outbox), 0)

    def test_minor_edit_triggers_no_email(self):
        mail.outbox = []
        self.decision.description = "Eat Cheese!"
        self.decision.minor_edit = True
        self.decision.save()
        self.assertEqual(len(mail.outbox), 0)
Exemplo n.º 7
0
class DecisionLastModifiedTest(EconsensusFixtureTestCase):
    """
    Tests updating of 'last_modified' date on Decision.
    """
    def setUp(self):
        self.user = UserFactory()
        self.decision = DecisionFactory()

    def last_modified(self):
        """
        Gets the last modified date of the test decision.
        """
        return Decision.objects.get(id=self.decision.id).last_modified

    def test_edit_decision_editor(self):
        orig_last_modified = self.last_modified()
        self.decision.editor = UserFactory()
        self.decision.save()
        self.assertEquals(orig_last_modified, self.last_modified())

    def test_edit_decision_description(self):
        orig_last_modified = self.last_modified()
        self.decision.description += "x"
        self.decision.save()
        self.assertTrue(orig_last_modified < self.last_modified())

    def test_add_feedback_triggers_update(self):
        orig_last_modified = self.last_modified()
        FeedbackFactory(decision=self.decision, author=self.user)
        self.assertTrue(orig_last_modified < self.last_modified())

    def test_add_comment_triggers_update(self):
        feedback = FeedbackFactory(decision=self.decision, author=self.user)
        orig_last_modified = self.last_modified()
        comment = CommentFactory(content_object=feedback, user=self.user)
        self.send_comment_posted_signal(comment)
        self.assertTrue(orig_last_modified < self.last_modified())

    def test_add_watcher_triggers_no_update(self):
        orig_last_modified = self.last_modified()
        notification.observe(self.decision, UserFactory(), DECISION_CHANGE)
        self.decision.save()
        self.assertTrue(orig_last_modified == self.last_modified())
Exemplo n.º 8
0
class DecisionLastModifiedTest(EconsensusFixtureTestCase):
    """
    Tests updating of 'last_modified' date on Decision.
    """
    def setUp(self):
        self.user = UserFactory()
        self.decision = DecisionFactory()

    def last_modified(self):
        """
        Gets the last modified date of the test decision.
        """
        return Decision.objects.get(id=self.decision.id).last_modified

    def test_edit_decision_editor(self):
        orig_last_modified = self.last_modified()
        self.decision.editor = UserFactory()
        self.decision.save()
        self.assertEquals(orig_last_modified, self.last_modified())

    def test_edit_decision_description(self):
        orig_last_modified = self.last_modified()
        self.decision.description += "x"
        self.decision.save()
        self.assertTrue(orig_last_modified < self.last_modified())

    def test_add_feedback_triggers_update(self):
        orig_last_modified = self.last_modified()
        FeedbackFactory(decision=self.decision, author=self.user)
        self.assertTrue(orig_last_modified < self.last_modified())

    def test_add_comment_triggers_update(self):
        feedback = FeedbackFactory(decision=self.decision, author=self.user)
        orig_last_modified = self.last_modified()
        comment = CommentFactory(content_object=feedback, user=self.user)
        self.send_comment_posted_signal(comment)
        self.assertTrue(orig_last_modified < self.last_modified())

    def test_add_watcher_triggers_no_update(self):
        orig_last_modified = self.last_modified()
        notification.observe(self.decision, UserFactory(), DECISION_CHANGE)
        self.decision.save()
        self.assertTrue(orig_last_modified == self.last_modified())