2 from django.core import mail
3 from django.contrib.auth.models import User
4 from django.conf import settings
7 from test import TestCase
8 from models import Consumer
10 class ConsumerTest(TestCase):
11 fixtures = ['models.json']
14 self.consumer = Consumer()
15 self.consumer.name = "Piston Test Consumer"
16 self.consumer.description = "A test consumer for Piston."
17 self.consumer.user = User.objects.get(pk=3)
18 self.consumer.generate_random_codes()
20 def test_create_pending(self):
21 """ Ensure creating a pending Consumer sends proper emails """
22 # If it's pending we should have two messages in the outbox; one
23 # to the consumer and one to the site admins.
24 if len(settings.ADMINS):
25 self.assertEquals(len(mail.outbox), 2)
27 self.assertEquals(len(mail.outbox), 1)
29 expected = "Your API Consumer for example.com is awaiting approval."
30 self.assertEquals(mail.outbox[0].subject, expected)
32 def test_delete_consumer(self):
33 """ Ensure deleting a Consumer sends a cancel email """
35 # Clear out the outbox before we test for the cancel email.
38 # Delete the consumer, which should fire off the cancel email.
39 self.consumer.delete()
41 self.assertEquals(len(mail.outbox), 1)
42 expected = "Your API Consumer for example.com has been canceled."
43 self.assertEquals(mail.outbox[0].subject, expected)