comparison email_list/tests/test_models.py @ 130:3062c547bb90

For Django 1.6: new test discovery plus reverse now does urlquote(). My base64 keys were padded with '=' and these got quoted when doing a reverse to generate the URL. So changed the test to look for a quoted version of the key. This will change the URLs sent to users, but I believe it will all be taken care of by Django.
author Brian Neal <bgneal@gmail.com>
date Tue, 24 Dec 2013 16:47:27 -0600
parents email_list/tests/model_tests.py@e2868ad47a1e
children 1b5b9be17764
comparison
equal deleted inserted replaced
129:fa4ef22f3f24 130:3062c547bb90
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