annotate email_list/tests/model_tests.py @ 93:388be986392e

For Django 1.5: The adminmedia template tags library was removed. Doesn't look like I was using it anyway.
author Brian Neal <bgneal@gmail.com>
date Wed, 28 Aug 2013 18:32:57 -0500
parents e2868ad47a1e
children
rev   line source
bgneal@51 1 """
bgneal@51 2 Model tests for the email_list application.
bgneal@51 3
bgneal@51 4 """
bgneal@51 5 import datetime
bgneal@51 6
bgneal@51 7 from django.test import TestCase
bgneal@51 8
bgneal@51 9 from email_list.models import Subscriber
bgneal@51 10
bgneal@51 11
bgneal@51 12 class SubscriberTestCase(TestCase):
bgneal@51 13
bgneal@51 14 def test_auto_save(self):
bgneal@51 15
bgneal@51 16 sub = Subscriber(name='', location='', email='test@example.com')
bgneal@51 17 sub.save()
bgneal@51 18
bgneal@51 19 now = datetime.datetime.now()
bgneal@51 20 self.assertTrue(now - sub.status_date < datetime.timedelta(seconds=2))
bgneal@51 21
bgneal@51 22 self.assertTrue(sub.status == 'A')
bgneal@51 23 self.assertTrue(sub.is_active())
bgneal@51 24 self.failIf(sub.is_pending())
bgneal@51 25 self.failIf(sub.is_leaving())
bgneal@51 26
bgneal@51 27 def test_set_pending(self):
bgneal@51 28
bgneal@51 29 sub = Subscriber(name='', location='', email='test@example.com')
bgneal@51 30 sub.set_pending()
bgneal@51 31
bgneal@51 32 now = datetime.datetime.now()
bgneal@51 33 self.assertTrue(now - sub.status_date < datetime.timedelta(seconds=2))
bgneal@51 34
bgneal@51 35 self.assertTrue(sub.status == 'P')
bgneal@51 36 self.failIf(sub.is_active())
bgneal@51 37 self.assertTrue(sub.is_pending())
bgneal@51 38 self.failIf(sub.is_leaving())
bgneal@51 39
bgneal@51 40 self.assertTrue(len(sub.key) == sub.key_length)
bgneal@51 41
bgneal@51 42 def test_set_active(self):
bgneal@51 43
bgneal@51 44 sub = Subscriber(name='', location='', email='test@example.com')
bgneal@51 45 sub.set_active()
bgneal@51 46
bgneal@51 47 now = datetime.datetime.now()
bgneal@51 48 self.assertTrue(now - sub.status_date < datetime.timedelta(seconds=2))
bgneal@51 49
bgneal@51 50 self.assertTrue(sub.status == 'A')
bgneal@51 51 self.assertTrue(sub.is_active())
bgneal@51 52 self.failIf(sub.is_pending())
bgneal@51 53 self.failIf(sub.is_leaving())
bgneal@51 54
bgneal@51 55 def test_set_leaving(self):
bgneal@51 56
bgneal@51 57 sub = Subscriber(name='', location='', email='test@example.com')
bgneal@51 58 sub.set_leaving()
bgneal@51 59
bgneal@51 60 now = datetime.datetime.now()
bgneal@51 61 self.assertTrue(now - sub.status_date < datetime.timedelta(seconds=2))
bgneal@51 62
bgneal@51 63 self.assertTrue(sub.status == 'L')
bgneal@51 64 self.failIf(sub.is_active())
bgneal@51 65 self.failIf(sub.is_pending())
bgneal@51 66 self.assertTrue(sub.is_leaving())
bgneal@51 67
bgneal@51 68 self.assertTrue(len(sub.key) == sub.key_length)
bgneal@51 69
bgneal@51 70 def test_gen_key(self):
bgneal@51 71
bgneal@51 72 sub = Subscriber(name='', location='', email='test@example.com')
bgneal@51 73 sub.status_date = datetime.datetime.now()
bgneal@51 74 sub.gen_key()
bgneal@51 75 self.assertTrue(len(sub.key) == sub.key_length)
bgneal@51 76