comparison email_list/tests/model_tests.py @ 71:e2868ad47a1e

For Django 1.4, using the new manage.py.
author Brian Neal <bgneal@gmail.com>
date Sat, 14 Apr 2012 16:40:29 -0500
parents madeira/email_list/tests/model_tests.py@13b2561c909d
children
comparison
equal deleted inserted replaced
70:f26cdda0ad8b 71:e2868ad47a1e
1 """
2 Model tests for the email_list application.
3
4 """
5 import datetime
6
7 from django.test import TestCase
8
9 from email_list.models import Subscriber
10
11
12 class SubscriberTestCase(TestCase):
13
14 def test_auto_save(self):
15
16 sub = Subscriber(name='', location='', email='test@example.com')
17 sub.save()
18
19 now = datetime.datetime.now()
20 self.assertTrue(now - sub.status_date < datetime.timedelta(seconds=2))
21
22 self.assertTrue(sub.status == 'A')
23 self.assertTrue(sub.is_active())
24 self.failIf(sub.is_pending())
25 self.failIf(sub.is_leaving())
26
27 def test_set_pending(self):
28
29 sub = Subscriber(name='', location='', email='test@example.com')
30 sub.set_pending()
31
32 now = datetime.datetime.now()
33 self.assertTrue(now - sub.status_date < datetime.timedelta(seconds=2))
34
35 self.assertTrue(sub.status == 'P')
36 self.failIf(sub.is_active())
37 self.assertTrue(sub.is_pending())
38 self.failIf(sub.is_leaving())
39
40 self.assertTrue(len(sub.key) == sub.key_length)
41
42 def test_set_active(self):
43
44 sub = Subscriber(name='', location='', email='test@example.com')
45 sub.set_active()
46
47 now = datetime.datetime.now()
48 self.assertTrue(now - sub.status_date < datetime.timedelta(seconds=2))
49
50 self.assertTrue(sub.status == 'A')
51 self.assertTrue(sub.is_active())
52 self.failIf(sub.is_pending())
53 self.failIf(sub.is_leaving())
54
55 def test_set_leaving(self):
56
57 sub = Subscriber(name='', location='', email='test@example.com')
58 sub.set_leaving()
59
60 now = datetime.datetime.now()
61 self.assertTrue(now - sub.status_date < datetime.timedelta(seconds=2))
62
63 self.assertTrue(sub.status == 'L')
64 self.failIf(sub.is_active())
65 self.failIf(sub.is_pending())
66 self.assertTrue(sub.is_leaving())
67
68 self.assertTrue(len(sub.key) == sub.key_length)
69
70 def test_gen_key(self):
71
72 sub = Subscriber(name='', location='', email='test@example.com')
73 sub.status_date = datetime.datetime.now()
74 sub.gen_key()
75 self.assertTrue(len(sub.key) == sub.key_length)
76