diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/email_list/tests/model_tests.py	Sat Apr 14 16:40:29 2012 -0500
@@ -0,0 +1,76 @@
+"""
+Model tests for the email_list application.
+
+"""
+import datetime
+
+from django.test import TestCase
+
+from email_list.models import Subscriber
+
+
+class SubscriberTestCase(TestCase):
+
+    def test_auto_save(self):
+
+        sub = Subscriber(name='', location='', email='test@example.com')
+        sub.save()
+
+        now = datetime.datetime.now()
+        self.assertTrue(now - sub.status_date < datetime.timedelta(seconds=2))
+
+        self.assertTrue(sub.status == 'A')
+        self.assertTrue(sub.is_active())
+        self.failIf(sub.is_pending())
+        self.failIf(sub.is_leaving())
+
+    def test_set_pending(self):
+
+        sub = Subscriber(name='', location='', email='test@example.com')
+        sub.set_pending()
+
+        now = datetime.datetime.now()
+        self.assertTrue(now - sub.status_date < datetime.timedelta(seconds=2))
+
+        self.assertTrue(sub.status == 'P')
+        self.failIf(sub.is_active())
+        self.assertTrue(sub.is_pending())
+        self.failIf(sub.is_leaving())
+
+        self.assertTrue(len(sub.key) == sub.key_length)
+
+    def test_set_active(self):
+
+        sub = Subscriber(name='', location='', email='test@example.com')
+        sub.set_active()
+
+        now = datetime.datetime.now()
+        self.assertTrue(now - sub.status_date < datetime.timedelta(seconds=2))
+
+        self.assertTrue(sub.status == 'A')
+        self.assertTrue(sub.is_active())
+        self.failIf(sub.is_pending())
+        self.failIf(sub.is_leaving())
+
+    def test_set_leaving(self):
+
+        sub = Subscriber(name='', location='', email='test@example.com')
+        sub.set_leaving()
+
+        now = datetime.datetime.now()
+        self.assertTrue(now - sub.status_date < datetime.timedelta(seconds=2))
+
+        self.assertTrue(sub.status == 'L')
+        self.failIf(sub.is_active())
+        self.failIf(sub.is_pending())
+        self.assertTrue(sub.is_leaving())
+
+        self.assertTrue(len(sub.key) == sub.key_length)
+
+    def test_gen_key(self):
+
+        sub = Subscriber(name='', location='', email='test@example.com')
+        sub.status_date = datetime.datetime.now()
+        sub.gen_key()
+        self.assertTrue(len(sub.key) == sub.key_length)
+