Пример #1
0
    def test_zero_limit(self):
        """
        If the limit is set to 0, then no email should be sent.

        """
        tier = self.create_tier(video_limit=0)
        tier_info = self.create_tier_info(tier)

        self.assertEqual(len(mail.outbox), 0)
        self.assertTrue(tier_info.video_count_when_warned is None)
        self.assertTrue(tier_info.video_limit_warning_sent is None)
        send_video_limit_warning()
        self.assertEqual(len(mail.outbox), 0)
        self.assertTrue(tier_info.video_count_when_warned is None)
        self.assertTrue(tier_info.video_limit_warning_sent is None)
Пример #2
0
    def test_no_limit(self):
        """
        If there is no video limit, then no email should be sent.

        """
        tier = self.create_tier(video_limit=None)
        tier_info = self.create_tier_info(tier)
        for i in xrange(7):
            self.create_video(name='video{0}'.format(i))

        self.assertEqual(len(mail.outbox), 0)
        self.assertTrue(tier_info.video_count_when_warned is None)
        self.assertTrue(tier_info.video_limit_warning_sent is None)
        send_video_limit_warning()
        self.assertEqual(len(mail.outbox), 0)
        self.assertTrue(tier_info.video_count_when_warned is None)
        self.assertTrue(tier_info.video_limit_warning_sent is None)
Пример #3
0
    def test_sent_recently(self):
        """
        If a warning email was sent recently, a new email shouldn't be sent.

        """
        last_sent = datetime.datetime.now()
        tier = self.create_tier(video_limit=10)
        tier_info = self.create_tier_info(tier,
                                          video_limit_warning_sent=last_sent)
        for i in xrange(7):
            self.create_video(name='video{0}'.format(i))

        self.assertEqual(len(mail.outbox), 0)
        self.assertTrue(tier_info.video_count_when_warned is None)
        send_video_limit_warning()
        self.assertEqual(len(mail.outbox), 0)
        self.assertTrue(tier_info.video_count_when_warned is None)
        self.assertEqual(tier_info.video_limit_warning_sent, last_sent)
Пример #4
0
    def test_initial_warning(self):
        """
        If the site is getting close to its video limit and the warning hasn't
        been sent before, it should be sent.

        """
        tier = self.create_tier(video_limit=10)
        tier_info = self.create_tier_info(tier)
        for i in xrange(7):
            self.create_video(name='video{0}'.format(i))

        self.assertEqual(len(mail.outbox), 0)
        self.assertTrue(tier_info.video_count_when_warned is None)
        self.assertTrue(tier_info.video_limit_warning_sent is None)
        send_video_limit_warning()
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(tier_info.video_count_when_warned, 7)
        self.assertTrue(tier_info.video_limit_warning_sent)
Пример #5
0
    def test_below_ratio(self):
        """
        If the site is below the warning ratio, the email shouldn't be sent,
        and any previous video counts should be forgotten.

        """
        last_sent = datetime.datetime.now() - datetime.timedelta(10)
        tier = self.create_tier(video_limit=10)
        tier_info = self.create_tier_info(tier,
                                          video_count_when_warned=7,
                                          video_limit_warning_sent=last_sent)
        for i in xrange(3):
            self.create_video(name='video{0}'.format(i))

        self.assertEqual(len(mail.outbox), 0)
        send_video_limit_warning()
        self.assertEqual(len(mail.outbox), 0)
        self.assertTrue(tier_info.video_count_when_warned is None)
        self.assertEqual(tier_info.video_limit_warning_sent, last_sent)
Пример #6
0
    def test_followup_warning__decrease(self):
        """
        If the site has fewer videos than when it was last warned, no email
        should be sent, and the new count should be recorded.

        """
        last_sent = datetime.datetime.now() - datetime.timedelta(10)
        tier = self.create_tier(video_limit=10)
        tier_info = self.create_tier_info(tier,
                                          video_count_when_warned=8,
                                          video_limit_warning_sent=last_sent)
        for i in xrange(7):
            self.create_video(name='video{0}'.format(i))

        self.assertEqual(len(mail.outbox), 0)
        send_video_limit_warning()
        self.assertEqual(len(mail.outbox), 0)
        self.assertEqual(tier_info.video_count_when_warned, 7)
        self.assertEqual(tier_info.video_limit_warning_sent, last_sent)
Пример #7
0
    def test_followup_warning(self):
        """
        If the site is getting closer to its video limit after an initial
        warning, an email should be sent.

        """
        last_sent = datetime.datetime.now() - datetime.timedelta(10)
        tier = self.create_tier(video_limit=10)
        tier_info = self.create_tier_info(tier,
                                          video_count_when_warned=7,
                                          video_limit_warning_sent=last_sent)
        for i in xrange(9):
            self.create_video(name='video{0}'.format(i))

        self.assertEqual(len(mail.outbox), 0)
        send_video_limit_warning()
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(tier_info.video_count_when_warned, 9)
        self.assertGreater(tier_info.video_limit_warning_sent, last_sent)
Пример #8
0
    def test_followup_warning__small_increase(self):
        """
        If the number of videos has increased (but not significantly) since
        the last warning, no email should be sent, and the old count should be
        preserved.

        """
        last_sent = datetime.datetime.now() - datetime.timedelta(10)
        tier = self.create_tier(video_limit=10)
        tier_info = self.create_tier_info(tier,
                                          video_count_when_warned=7,
                                          video_limit_warning_sent=last_sent)
        for i in xrange(8):
            self.create_video(name='video{0}'.format(i))

        self.assertEqual(len(mail.outbox), 0)
        send_video_limit_warning()
        self.assertEqual(len(mail.outbox), 0)
        self.assertEqual(tier_info.video_count_when_warned, 7)
        self.assertEqual(tier_info.video_limit_warning_sent, last_sent)
 def handle_noargs(self, **options):
     send_video_limit_warning()