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