bgneal@51: """ bgneal@51: Model tests for the email_list application. bgneal@51: bgneal@51: """ bgneal@51: import datetime bgneal@51: bgneal@51: from django.test import TestCase bgneal@51: bgneal@51: from email_list.models import Subscriber bgneal@51: bgneal@51: bgneal@51: class SubscriberTestCase(TestCase): bgneal@51: bgneal@51: def test_auto_save(self): bgneal@51: bgneal@51: sub = Subscriber(name='', location='', email='test@example.com') bgneal@51: sub.save() bgneal@51: bgneal@51: now = datetime.datetime.now() bgneal@51: self.assertTrue(now - sub.status_date < datetime.timedelta(seconds=2)) bgneal@51: bgneal@51: self.assertTrue(sub.status == 'A') bgneal@51: self.assertTrue(sub.is_active()) bgneal@167: self.assertFalse(sub.is_pending()) bgneal@167: self.assertFalse(sub.is_leaving()) bgneal@51: bgneal@51: def test_set_pending(self): bgneal@51: bgneal@51: sub = Subscriber(name='', location='', email='test@example.com') bgneal@51: sub.set_pending() bgneal@51: bgneal@51: now = datetime.datetime.now() bgneal@51: self.assertTrue(now - sub.status_date < datetime.timedelta(seconds=2)) bgneal@51: bgneal@51: self.assertTrue(sub.status == 'P') bgneal@167: self.assertFalse(sub.is_active()) bgneal@51: self.assertTrue(sub.is_pending()) bgneal@167: self.assertFalse(sub.is_leaving()) bgneal@51: bgneal@51: self.assertTrue(len(sub.key) == sub.key_length) bgneal@51: bgneal@51: def test_set_active(self): bgneal@51: bgneal@51: sub = Subscriber(name='', location='', email='test@example.com') bgneal@51: sub.set_active() bgneal@51: bgneal@51: now = datetime.datetime.now() bgneal@51: self.assertTrue(now - sub.status_date < datetime.timedelta(seconds=2)) bgneal@51: bgneal@51: self.assertTrue(sub.status == 'A') bgneal@51: self.assertTrue(sub.is_active()) bgneal@167: self.assertFalse(sub.is_pending()) bgneal@167: self.assertFalse(sub.is_leaving()) bgneal@51: bgneal@51: def test_set_leaving(self): bgneal@51: bgneal@51: sub = Subscriber(name='', location='', email='test@example.com') bgneal@51: sub.set_leaving() bgneal@51: bgneal@51: now = datetime.datetime.now() bgneal@51: self.assertTrue(now - sub.status_date < datetime.timedelta(seconds=2)) bgneal@51: bgneal@51: self.assertTrue(sub.status == 'L') bgneal@167: self.assertFalse(sub.is_active()) bgneal@167: self.assertFalse(sub.is_pending()) bgneal@51: self.assertTrue(sub.is_leaving()) bgneal@51: bgneal@51: self.assertTrue(len(sub.key) == sub.key_length) bgneal@51: bgneal@51: def test_gen_key(self): bgneal@51: bgneal@51: sub = Subscriber(name='', location='', email='test@example.com') bgneal@51: sub.status_date = datetime.datetime.now() bgneal@51: sub.gen_key() bgneal@51: self.assertTrue(len(sub.key) == sub.key_length) bgneal@51: