- Added librarian as a submodule.
[wolnelektury.git] / apps / piston / tests.py
1 # Django imports
2 from django.core import mail
3 from django.contrib.auth.models import User
4 from django.conf import settings
5
6 # Piston imports
7 from test import TestCase
8 from models import Consumer
9
10 class ConsumerTest(TestCase):
11     fixtures = ['models.json']
12
13     def setUp(self):
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()
19
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)
26         else:
27             self.assertEquals(len(mail.outbox), 1)
28
29         expected = "Your API Consumer for example.com is awaiting approval."
30         self.assertEquals(mail.outbox[0].subject, expected)
31
32     def test_delete_consumer(self):
33         """ Ensure deleting a Consumer sends a cancel email """
34
35         # Clear out the outbox before we test for the cancel email.
36         mail.outbox = []
37
38         # Delete the consumer, which should fire off the cancel email.
39         self.consumer.delete()
40
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)
44