Пример #1
0
class TestTargettedPigeons(TestCase):

    def setUp(self):
        self.users, self.staff, _, _ = create_fixtures(create_message=False)
        self.news = BobsNews(subject='Propaganda daily', body='Bob is a great guy.')
        self.news.save()
        self.moderated_news = ModeratedNews(subject='Propaganda daily', body='Bob is not a great guy.')
        self.moderated_news.save()
        self.bob = User.objects.get(first_name__iexact='bob')
 
    def test_send_to(self):
        """ Test that we can send a pigeon to a specific user """
        pigeonpost_queue.send(sender=self.news, render_email_method='email_news',
                send_to=self.bob) 
        process_queue()

        messages = Outbox.objects.all()
        self.assertEqual(len(messages),1)
        self.assertEqual(messages[0].user, self.bob)

    def test_send_to_method(self):
        """ Test that we can send a pigeon to a specific user """
        pigeonpost_queue.send(sender=self.news, render_email_method='email_news',
                send_to_method='get_everyone_called_bob') 
        process_queue()

        messages = Outbox.objects.all()
        self.assertEqual(len(messages),1)
        self.assertEqual(messages[0].user, self.bob)

    def test_no_recipients(self):
        """ Test that the pigeon is processed correctly when there are no recipients """
        # Remove Bob
        User.objects.filter(username='******').delete()
        # Then try to send custom news to Bob
        pigeonpost_queue.send(sender=self.news, render_email_method='email_news',
                send_to_method='get_everyone_called_bob') 
        process_queue()

        messages = Outbox.objects.all()
        self.assertEqual(len(messages),0)

        pigeon = Pigeon.objects.get(source_id=self.news.id)
        self.assertEqual(pigeon.to_send, False)

    def test_no_method_or_target(self):
        """ Test that the pigeon is processed correctly when there are no recipients """
        # Then try to send custom news to Bob
        pigeonpost_queue.send(sender=self.moderated_news, render_email_method='email_moderators')
        process_queue()
        messages = Outbox.objects.all()
        self.assertEqual(len(messages),2)
Пример #2
0
 def setUp(self):
     self.users, self.staff, _, _ = create_fixtures(create_message=False)
     self.news = BobsNews(subject='Propaganda daily', body='Bob is a great guy.')
     self.news.save()
     self.moderated_news = ModeratedNews(subject='Propaganda daily', body='Bob is not a great guy.')
     self.moderated_news.save()
     self.bob = User.objects.get(first_name__iexact='bob')