Beispiel #1
0
 def setUp(self):
     subscribers.register(SubscribersTestModel1)
     subscribers.register(SubscribersTestModel2)
     self.email1 = SubscribersTestModel1.objects.create(subject="Foo 1")
     self.email2 = SubscribersTestModel2.objects.create(subject="Foo 2")
     self.subscriber1 = Subscriber.objects.subscribe(email="*****@*****.**")
     self.subscriber2 = Subscriber.objects.subscribe(email="*****@*****.**")
     # Create the emails.
     for email in (self.email1, self.email2):
         for subscriber in (self.subscriber1, self.subscriber2):
             subscribers.dispatch_email(email, subscriber)
Beispiel #2
0
 def testEmailsReceivedStatistic(self):
     response = self.client.get("/admin/subscribers/subscriber/")
     self.assertContains(response, "*****@*****.**")
     self.assertContains(response, "<td>0</td>")
     # Send the subscriber an email.
     email = SubscribersTestAdminModel1.objects.create(
         subject = "Foo bar 1",
     )
     subscribers.dispatch_email(email, self.subscriber)
     # Test that the email count is updated.
     response = self.client.get("/admin/subscribers/subscriber/")
     self.assertContains(response, "*****@*****.**")
     self.assertContains(response, "<td>1</td>")
Beispiel #3
0
 def assertViewOnSiteWorks(self, email):
     view_url = subscribers.get_adapter(email.__class__).get_view_url(email, self.subscriber1)
     # Test that is doesn't let you in if the email has not been sent.
     response = self.client.get(view_url)
     self.assertEqual(response.status_code, 404)
     # Test that an unsent email does not work.
     subscribers.dispatch_email(email, self.subscriber1)
     response = self.client.get(view_url)
     self.assertEqual(response.status_code, 404)
     # Test that the view URL is valid.
     subscribers.send_email_batch()
     response = self.client.get(view_url)
     self.assertEqual(response.status_code, 200)
     # Test that the txt version also works.
     response = self.client.get(view_url + "txt/")
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response["Content-Type"], "text/plain; charset=utf-8")
Beispiel #4
0
 def assertRecipientsStatisticWorks(self, model):
     model_slug = model.__name__.lower()
     email = model.objects.create(
         subject = "Foo bar 1",
     )
     response = self.client.get("/admin/auth/{model_slug}/".format(model_slug=model_slug))
     self.assertContains(response, "Foo bar 1")
     self.assertContains(response, "<td>0</td>")
     # Dispatch an email.
     subscriber = Subscriber.objects.create(
         email = "*****@*****.**",
     )
     subscribers.dispatch_email(email, subscriber)
     # Check that the statistics have updated.
     response = self.client.get("/admin/auth/{model_slug}/".format(model_slug=model_slug))
     self.assertContains(response, "Foo bar 1")
     self.assertContains(response, "<td>1</td>")
Beispiel #5
0
 def assertUnsubscribeWorkflowWorks(self, email):
     self.assertTrue(Subscriber.objects.get(id=self.subscriber1.id).is_subscribed)
     # Get the unsubscribe URL.
     unsubscribe_url = subscribers.get_adapter(email.__class__).get_unsubscribe_url(email, self.subscriber1)
     self.assertTrue(unsubscribe_url)  # Make sure the unsubscribe url is set.
     # Attempt to unsubscribe from an email that was never dispatched.
     self.assertEqual(self.client.get(unsubscribe_url).status_code, 404)
     # Dispatch the email.
     subscribers.dispatch_email(email, self.subscriber1)
     # Attempt to unsubscribe from an email that was never sent.
     self.assertEqual(self.client.get(unsubscribe_url).status_code, 404)
     # Send the emails.
     subscribers.send_email_batch()
     # Try to unsubscribe again.
     response = self.client.get(unsubscribe_url)
     self.assertEqual(response.status_code, 200)
     response = self.client.post(unsubscribe_url, follow=True)
     self.assertEqual(response.status_code, 200)
     self.assertTemplateUsed(response, "subscribers/unsubscribe_success.html")
     # See if the unsubscribe worked.
     self.assertFalse(Subscriber.objects.get(id=self.subscriber1.id).is_subscribed)
     # Re-subscribe the user.
     self.subscriber1 = Subscriber.objects.subscribe(email="*****@*****.**")