Anonymous avatar Anonymous committed 99afb3c

Fixed the tests for sending emails to account for cases when emails are not sent.

Comments (0)

Files changed (1)

 from django.core import mail
 from django.contrib.auth.models import User
 from django.conf import settings
+from django.template import loader, TemplateDoesNotExist
 
 # Piston imports
 from test import TestCase
         self.consumer.user = User.objects.get(pk=3)
         self.consumer.generate_random_codes()
 
+    def _pre_test_email(self):
+        template = "piston/mails/consumer_%s.txt" % self.consumer.status
+        try:
+            loader.render_to_string(template, {
+                'consumer': self.consumer,
+                'user': self.consumer.user
+            })
+            return True
+        except TemplateDoesNotExist:
+            """
+            They haven't set up the templates, which means they might not want
+            these emails sent.
+            """
+            return False
+
     def test_create_pending(self):
         """ Ensure creating a pending Consumer sends proper emails """
-        # If it's pending we should have two messages in the outbox; one 
+        # Verify if the emails can be sent
+        if not self._pre_test_email():
+            return
+
+        # If it's pending we should have two messages in the outbox; one
         # to the consumer and one to the site admins.
         if len(settings.ADMINS):
             self.assertEquals(len(mail.outbox), 2)
         mail.outbox = []
 
         # Delete the consumer, which should fire off the cancel email.
-        self.consumer.delete() 
-        
+        self.consumer.delete()
+
+        # Verify if the emails can be sent
+        if not self._pre_test_email():
+            return
+
         self.assertEquals(len(mail.outbox), 1)
         expected = "Your API Consumer for example.com has been canceled."
         self.assertEquals(mail.outbox[0].subject, expected)
-
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.