2010-03-27 15:54:31 +00:00
|
|
|
import pickle
|
2010-04-15 12:41:08 +00:00
|
|
|
import datetime
|
2010-03-27 15:54:31 +00:00
|
|
|
|
|
|
|
from django.test import TestCase
|
|
|
|
|
2010-04-15 12:41:08 +00:00
|
|
|
from models import Group, Event, Happening
|
2010-03-27 15:54:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PickleabilityTestCase(TestCase):
|
|
|
|
def assert_pickles(self, qs):
|
|
|
|
self.assertEqual(list(pickle.loads(pickle.dumps(qs))), list(qs))
|
|
|
|
|
|
|
|
def test_related_field(self):
|
|
|
|
g = Group.objects.create(name="Ponies Who Own Maybachs")
|
|
|
|
self.assert_pickles(Event.objects.filter(group=g.id))
|
2010-04-15 12:41:08 +00:00
|
|
|
|
|
|
|
def test_datetime_callable_default_all(self):
|
|
|
|
self.assert_pickles(Happening.objects.all())
|
|
|
|
|
|
|
|
def test_datetime_callable_default_filter(self):
|
|
|
|
self.assert_pickles(Happening.objects.filter(when=datetime.datetime.now()))
|
|
|
|
|
|
|
|
def test_lambda_as_default(self):
|
|
|
|
self.assert_pickles(Happening.objects.filter(name="test"))
|
|
|
|
|
2010-04-21 16:34:33 +00:00
|
|
|
def test_standalone_method_as_default(self):
|
|
|
|
self.assert_pickles(Happening.objects.filter(number1=1))
|
|
|
|
|
|
|
|
def test_staticmethod_as_default(self):
|
|
|
|
self.assert_pickles(Happening.objects.filter(number2=1))
|
|
|
|
|
|
|
|
def test_classmethod_as_default(self):
|
2010-04-21 18:07:23 +00:00
|
|
|
self.assert_pickles(Happening.objects.filter(number3=1))
|
2010-04-21 16:34:33 +00:00
|
|
|
|
|
|
|
def test_membermethod_as_default(self):
|
2010-04-21 18:07:23 +00:00
|
|
|
self.assert_pickles(Happening.objects.filter(number4=1))
|