Esempio n. 1
0
 def test_email_sent_on_sighting(self):
     """
     Test that emails are sent to user's watching a beer when a sighting is created
     """
     mail.outbox = []
     SightingFactory.create(user=self.user_2, beer=self.beer, venue=self.venue)
     self.assertEqual(len(mail.outbox), 1)
     for m in mail.outbox:
         self.assertEqual(m.to, [self.user.email])
Esempio n. 2
0
    def test_send_emails(self):
        """
        Tests the celery task specifically.
        Testing that emails are sent when a sighting is created with no regard
        to the method will be done separately.
        """
        user_1 = UserFactory.create()
        user_2 = UserFactory.create()
        user_3 = UserFactory.create()

        beer_1 = BeerFactory.create()
        beer_2 = BeerFactory.create()

        user_1_watched_1 = WatchedBeerFactory.create(user=user_1, beer=beer_1)
        user_2_watched_1 = WatchedBeerFactory.create(user=user_2, beer=beer_1)
        user_2_watched_1 = WatchedBeerFactory.create(user=user_2, beer=beer_2)

        beer_1_sighting = SightingFactory.create(user=user_3, beer=beer_1, venue=self.venue)
        beer_2_sighting = SightingFactory.create(user=user_3, beer=beer_2, venue=self.venue)

        mail.outbox = []
        send_watchlist_email.delay(beer_1_sighting.id)
        self.assertEqual(len(mail.outbox), 2)
        recipients = [m.to for m in mail.outbox]
        self.assertItemsEqual(recipients, [[user_1.email], [user_2.email]])

        mail.outbox = []
        send_watchlist_email.delay(beer_2_sighting.id)
        self.assertEqual(len(mail.outbox), 1)
        for m in mail.outbox:
            self.assertEqual(m.to, [user_2.email])

        user_1.send_watchlist_email = False
        user_1.save()
        mail.outbox = []
        send_watchlist_email.delay(beer_1_sighting.id)
        self.assertEqual(len(mail.outbox), 1)
        for m in mail.outbox:
            self.assertEqual(m.to, [user_2.email])
Esempio n. 3
0
    def test_no_self_notification(self):
        """
        Test that emails are not sent to the person who created the sighting.
        """
        user_1 = UserFactory.create()
        user_2 = UserFactory.create()
        user_3 = UserFactory.create()

        beer_1 = BeerFactory.create()

        user_1_watched_1 = WatchedBeerFactory.create(user=user_1, beer=beer_1)
        user_2_watched_1 = WatchedBeerFactory.create(user=user_2, beer=beer_1)

        beer_1_sighting = SightingFactory.create(user=user_1, beer=beer_1, venue=self.venue)

        mail.outbox = []
        send_watchlist_email.delay(beer_1_sighting.id)
        self.assertEqual(len(mail.outbox), 1)
        for m in mail.outbox:
            self.assertEqual(m.to, [user_2.email])