Exemplo n.º 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())
Exemplo n.º 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()
Exemplo n.º 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())
Exemplo n.º 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)
Exemplo n.º 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())
Exemplo n.º 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)
Exemplo n.º 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')
Exemplo n.º 8
0
    def test_resend(self):
        notification = SentNotification()

        with patch.object(NotificationBase, '_send') as mocked__send:
            result = NotificationBase.resend(notification)
            self.assertTrue(result)
Exemplo n.º 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)
Exemplo n.º 10
0
 def test_get_extra_data(self):
     notification = SentNotification(extra_data='{"something":["one","two"]}')
     self.assertDictEqual(notification.get_extra_data(), {'something': ['one', 'two']})
Exemplo n.º 11
0
 def test_get_extra_data_none(self):
     notification = SentNotification()
     self.assertDictEqual(notification.get_extra_data(), {})
Exemplo n.º 12
0
 def test_get_recipients(self):
     notification = SentNotification(recipients='[email protected],[email protected]')
     self.assertListEqual(notification.get_recipients(), ['*****@*****.**','*****@*****.**'])
Exemplo n.º 13
0
 def test_str(self):
     notification = SentNotification(notification_class='tests.notifications.MyNotification')
     self.assertEqual(six.text_type(notification), 'tests.notifications.MyNotification')