Пример #1
0
    def test_it_sends_nag(self):
        cmd = Command(stdout=Mock())
        cmd.pause = Mock()  # don't pause for 1s

        found = cmd.handle_one_nag()
        self.assertTrue(found)

        self.profile.refresh_from_db()
        self.assertTrue(self.profile.next_nag_date > now())
        self.assertEqual(len(mail.outbox), 1)
Пример #2
0
    def test_it_sends_report(self):
        cmd = Command()
        cmd.stdout = Mock()  # silence output to stdout
        cmd.pause = Mock()  # don't pause for 1s

        found = cmd.handle_one_monthly_report()
        self.assertTrue(found)

        self.profile.refresh_from_db()
        self.assertTrue(self.profile.next_report_date > now())
        self.assertEqual(len(mail.outbox), 1)
Пример #3
0
    def test_it_sends_weekly_report(self):
        self.profile.reports = "weekly"
        self.profile.save()

        cmd = Command(stdout=Mock())
        cmd.pause = Mock()  # don't pause for 1s

        cmd.handle_one_report()

        email = mail.outbox[0]
        self.assertEqual(email.subject, "Weekly Report")
        self.assertIn("This is a weekly report", email.body)
        self.assertIn("This is a weekly report", email.alternatives[0][0])
Пример #4
0
    def test_it_sends_report(self):
        cmd = Command()
        cmd.stdout = Mock()  # silence output to stdout
        cmd.pause = Mock()  # don't pause for 1s

        found = cmd.handle_one_monthly_report()
        self.assertTrue(found)

        self.profile.refresh_from_db()
        self.assertTrue(self.profile.next_report_date > now())
        self.assertEqual(self.profile.next_report_date.day, 1)
        self.assertEqual(len(mail.outbox), 1)

        email = mail.outbox[0]
        self.assertTrue("List-Unsubscribe" in email.extra_headers)
Пример #5
0
    def test_it_sends_nag(self):
        cmd = Command(stdout=Mock())
        cmd.pause = Mock()  # don't pause for 1s

        found = cmd.handle_one_nag()
        self.assertTrue(found)

        self.profile.refresh_from_db()
        self.assertTrue(self.profile.next_nag_date > now())
        self.assertEqual(len(mail.outbox), 1)

        email = mail.outbox[0]
        html = email.alternatives[0][0]
        self.assertNotIn(str(self.check.code), email.body)
        self.assertNotIn(str(self.check.code), html)
Пример #6
0
    def test_it_sends_report(self):
        sent = Command().handle_one_run()
        self.assertEqual(sent, 1)

        # Alice's profile should have been updated
        self.profile.refresh_from_db()
        self.assertTrue(self.profile.next_report_date > now())
Пример #7
0
    def test_it_obeys_next_nag_date(self):
        self.profile.next_nag_date = now() + td(days=1)
        self.profile.save()

        # If next_nag_date is in future, a nag should not get sent.
        found = Command().handle_one_nag()
        self.assertFalse(found)
Пример #8
0
    def test_it_obeys_nag_period(self):
        self.profile.nag_period = td()
        self.profile.save()

        # If nag_period is 0 ("disabled"), a nag should not get sent.
        found = Command().handle_one_nag()
        self.assertFalse(found)
Пример #9
0
    def test_it_sends_nag(self):
        found = Command().handle_one_nag()
        self.assertTrue(found)

        self.profile.refresh_from_db()
        self.assertTrue(self.profile.next_nag_date > now())
        self.assertEqual(len(mail.outbox), 1)
Пример #10
0
    def test_it_requires_pinged_checks(self):
        self.check.delete()

        found = Command().handle_one_report()
        self.assertTrue(found)

        # No email should have been sent:
        self.assertEqual(len(mail.outbox), 0)
Пример #11
0
    def test_it_sends_monthly_report(self):
        cmd = Command(stdout=Mock())
        cmd.pause = Mock()  # don't pause for 1s

        found = cmd.handle_one_report()
        self.assertTrue(found)

        self.profile.refresh_from_db()
        self.assertTrue(self.profile.next_report_date > now())
        self.assertEqual(self.profile.next_report_date.day, 1)
        self.assertEqual(len(mail.outbox), 1)

        email = mail.outbox[0]
        self.assertTrue("List-Unsubscribe" in email.extra_headers)
        self.assertTrue("List-Unsubscribe-Post" in email.extra_headers)
        self.assertEqual(email.subject, "Monthly Report")
        self.assertIn("This is a monthly report", email.body)
        self.assertIn("This is a monthly report", email.alternatives[0][0])
Пример #12
0
    def test_it_fills_blank_next_report_date(self):
        self.profile.next_report_date = None
        self.profile.save()

        found = Command().handle_one_report()
        self.assertTrue(found)

        self.profile.refresh_from_db()
        self.assertEqual(self.profile.next_report_date.day, 1)
        self.assertEqual(len(mail.outbox), 0)
Пример #13
0
    def test_nags_require_down_checks(self):
        self.check.status = "up"
        self.check.save()

        found = Command().handle_one_nag()
        self.assertTrue(found)

        # No email should have been sent:
        self.assertEqual(len(mail.outbox), 0)

        # next_nag_date should now be unset
        self.profile.refresh_from_db()
        self.assertIsNone(self.profile.next_nag_date)
Пример #14
0
    def test_handle_one_run_sends_weekly_report(self):
        
        # Weekly report for alice
        # Set alice's join date to 7 days before
        seven_days_before = timezone.now() - timedelta(days=7)
        self.alice.date_joined = seven_days_before
        self.profile.report_duration = 7
        self.alice.save()
        self.profile.save()

        check = Check(user=self.alice, status="up", last_ping=timezone.now())
        check.save()

        result = Command().handle_one_run()
        self.assertEqual(result, 1)
Пример #15
0
    def test_it_obeys_reports_off(self):
        self.profile.reports = "off"
        self.profile.save()

        found = Command().handle_one_report()
        self.assertFalse(found)
Пример #16
0
    def test_it_obeys_next_report_date(self):
        self.profile.next_report_date = now() + td(days=1)
        self.profile.save()

        found = Command().handle_one_report()
        self.assertFalse(found)
Пример #17
0
    def test_it_obeys_next_report_date(self):
        self.profile.next_report_date = now() + td(days=1)
        self.profile.save()

        sent = Command().handle_one_run()
        self.assertEqual(sent, 0)
Пример #18
0
    def test_it_obeys_reports_allowed_flag(self):
        self.profile.reports_allowed = False
        self.profile.save()

        sent = Command().handle_one_run()
        self.assertEqual(sent, 0)
Пример #19
0
    def test_it_requires_pinged_checks(self):
        self.check.delete()

        sent = Command().handle_one_run()
        self.assertEqual(sent, 0)
Пример #20
0
    def test_it_obeys_reports_allowed_flag(self):
        self.profile.reports_allowed = False
        self.profile.save()

        found = Command().handle_one_monthly_report()
        self.assertFalse(found)