Beispiel #1
0
 def test_delete_today(self):
     SentNotification(notification_class=NOTIFICATION_CLASS,
                      date_sent=timezone.now()).save()
     SentNotification(notification_class=NOTIFICATION_CLASS,
                      date_sent=timezone.now() + timedelta(days=1)).save()
     out = StringIO()
     call_command('delnotifs', stdout=out)
     self.assertIn(MSG.format(num=1), out.getvalue())
Beispiel #2
0
 def setUp(self):
     SentNotification(notification_class=NOTIFICATION_CLASS,
                      date_sent=timezone.now() - timedelta(days=3)).save()
     SentNotification(notification_class=NOTIFICATION_CLASS,
                      date_sent=timezone.now() - timedelta(days=2)).save()
     SentNotification(notification_class=NOTIFICATION_CLASS,
                      date_sent=timezone.now() - timedelta(days=1)).save()
     SentNotification(notification_class=NOTIFICATION_CLASS,
                      date_sent=timezone.now()).save()
     SentNotification(notification_class=NOTIFICATION_CLASS,
                      date_sent=timezone.now()).save()
Beispiel #3
0
 def test_delete_today_start_arg(self):
     SentNotification(notification_class=NOTIFICATION_CLASS,
                      date_sent=timezone.now()).save()
     SentNotification(notification_class=NOTIFICATION_CLASS,
                      date_sent=timezone.now() + timedelta(days=1)).save()
     out = StringIO()
     today = timezone.now().replace(hour=0,
                                    minute=0,
                                    second=0,
                                    microsecond=0)
     call_command('delnotifs', stdout=out, start=str(today))
     self.assertIn(MSG.format(num=1), out.getvalue())
Beispiel #4
0
    def test_resend_error(self):
        notification = SentNotification()

        with patch.object(NotificationBase, '_send') as mocked__send:
            mocked__send.side_effect = Exception
            result = NotificationBase.resend(notification)
            self.assertFalse(result)
Beispiel #5
0
 def test_do_not_delete_tomorrow_end_arg(self):
     SentNotification(notification_class=NOTIFICATION_CLASS,
                      date_sent=timezone.now() + timedelta(days=1)).save()
     out = StringIO()
     two_days_later = timezone.now().replace(
         hour=0, minute=0, second=0, microsecond=0) + timedelta(days=2)
     call_command('delnotifs', stdout=out, end=str(two_days_later))
     self.assertIn(MSG.format(num=1), out.getvalue())
Beispiel #6
0
    def test_resend_error_raise(self):
        notification = SentNotification()

        with patch.object(NotificationBase, '_send') as mocked__send:
            mocked__send.side_effect = Exception
            self.assertRaises(Exception,
                              NotificationBase.resend,
                              notification,
                              raise_exception=True)
Beispiel #7
0
    def test_do_accept_bad_args(self):
        SentNotification(notification_class=NOTIFICATION_CLASS,
                         date_sent=self.today - timedelta(days=1)).save()

        with self.assertRaises(ValidationError):
            call_command('delnotifs', stdout=self.out, start='blargh')

        with self.assertRaises(ValidationError):
            call_command('delnotifs', stdout=self.out, start='01-01-2016')
Beispiel #8
0
    def test_resend(self):
        notification = SentNotification()

        with patch.object(NotificationBase, '_send') as mocked__send:
            result = NotificationBase.resend(notification)
            self.assertTrue(result)
Beispiel #9
0
 def test_resend(self):
     notification = SentNotification(notification_class='tests.notifications.MyNotification')
     with patch.object(MyNotification, 'resend') as mocked_resend:
         notification.resend()
         mocked_resend.assert_called_once_with(notification)
Beispiel #10
0
 def test_get_extra_data(self):
     notification = SentNotification(extra_data='{"something":["one","two"]}')
     self.assertDictEqual(notification.get_extra_data(), {'something': ['one', 'two']})
Beispiel #11
0
 def test_get_extra_data_none(self):
     notification = SentNotification()
     self.assertDictEqual(notification.get_extra_data(), {})
Beispiel #12
0
 def test_get_recipients(self):
     notification = SentNotification(recipients='[email protected],[email protected]')
     self.assertListEqual(notification.get_recipients(), ['*****@*****.**','*****@*****.**'])
Beispiel #13
0
 def test_str(self):
     notification = SentNotification(notification_class='tests.notifications.MyNotification')
     self.assertEqual(six.text_type(notification), 'tests.notifications.MyNotification')