def check_notification_out(self, notification_name, user): """ Return True if user received notification """ # with queued notifications we can detect notification types easier if settings.PINAX_NOTIFICATIONS_QUEUE_ALL: self.assertTrue(NoticeQueueBatch.objects.all().count() > 0) user.noticesetting_set.get(notice_type__label=notification_name) # we're looking for specific notification type/user combination, which is probably # at the end for queued_batch in NoticeQueueBatch.objects.all(): notices = pickle.loads(base64.b64decode(queued_batch.pickled_data)) for user_id, label, extra_context, sender in notices: if label == notification_name and user_id == user.pk: return True # clear notifications queue send_all() return False else: send_all() # empty outbox:/ if not mail.outbox: return False msg = mail.outbox[-1] user.noticesetting_set.get(notice_type__label=notification_name) # unfortunatelly we can't use description check in subject, because subject is # generated from other template. # and notification.notice_type.description in msg.subject # last email should contain notification return user.email in msg.to
def check_notification_out(self, notification_name, user): """ Return True if user received notification """ # with queued notifications we can detect notification types easier if settings.PINAX_NOTIFICATIONS_QUEUE_ALL: self.assertTrue(NoticeQueueBatch.objects.all().count() > 0) user.noticesetting_set.get(notice_type__label=notification_name) # we're looking for specific notification type/user combination, which is probably # at the end for queued_batch in NoticeQueueBatch.objects.all(): notices = pickle.loads(base64.b64decode(queued_batch.pickled_data)) for user_id, label, extra_context, sender in notices: if label == notification_name and user_id == user.pk: return True # clear notifications queue send_all() return False else: send_all() # empty outbox:/ if not mail.outbox: return False msg = mail.outbox[-1] user.noticesetting_set.get(notice_type__label=notification_name) # unfortunatelly we can't use description check in subject, because subject is # generated from other template. # and notification.notice_type.description in msg.subject # last email should contain notification return user.email in msg.to
def test_send_all(self): users = [self.user, self.user2, self.user3] email_id = get_backend_id("email") ns = NoticeSetting.objects.create(user=self.user, notice_type=self.notice_type, medium=email_id, send=True) ns2 = NoticeSetting.objects.create(user=self.user2, notice_type=self.notice_type, medium=email_id, send=True) send(users, "label", queue=True) self.assertEqual(NoticeQueueBatch.objects.count(), 1) batch = NoticeQueueBatch.objects.all()[0] notices = pickle.loads(base64.b64decode(batch.pickled_data)) self.assertEqual(len(notices), 3) send_all() self.assertEqual(len(mail.outbox), 2) self.assertIn(self.user.email, mail.outbox[0].to) self.assertIn(self.user2.email, mail.outbox[1].to) self.assertNotIn(self.user3.email, mail.outbox[0].to) self.assertNotIn(self.user3.email, mail.outbox[1].to) ns.delete() ns2.delete()
def test_send_all(self): users = [self.user, self.user2, self.user3] email_id = get_backend_id("email") ns = NoticeSetting.objects.create( user=self.user, notice_type=self.notice_type, medium=email_id, send=True ) ns2 = NoticeSetting.objects.create( user=self.user2, notice_type=self.notice_type, medium=email_id, send=True ) send(users, "label", queue=True) self.assertEqual(NoticeQueueBatch.objects.count(), 1) batch = NoticeQueueBatch.objects.all()[0] notices = pickle.loads(base64.b64decode(batch.pickled_data)) self.assertEqual(len(notices), 3) send_all() self.assertEqual(len(mail.outbox), 2) self.assertIn(self.user.email, mail.outbox[0].to) self.assertIn(self.user2.email, mail.outbox[1].to) self.assertNotIn(self.user3.email, mail.outbox[0].to) self.assertNotIn(self.user3.email, mail.outbox[1].to) ns.delete() ns2.delete()
def clear_notifications_queue(self): send_all()
def clear_notifications_queue(self): send_all() mail.outbox = []
def clear_notifications_queue(self): send_all()
def handle(self, *args, **options): logging.basicConfig(level=logging.DEBUG, format="%(message)s") logging.getLogger('pinax').info("-" * 72) send_all(*args)
def handle(self, *args, **options): logging.basicConfig(level=logging.DEBUG, format="%(message)s") logging.info("-" * 72) send_all(*args)