PageRenderTime 21ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/regressiontests/queryset_pickle/tests.py

https://code.google.com/p/mango-py/
Python | 36 lines | 24 code | 12 blank | 0 comment | 0 complexity | 18e403488b3ff5fb8dc0064f20fe0fae MD5 | raw file
Possible License(s): BSD-3-Clause
  1. import pickle
  2. import datetime
  3. from django.test import TestCase
  4. from models import Group, Event, Happening
  5. class PickleabilityTestCase(TestCase):
  6. def assert_pickles(self, qs):
  7. self.assertEqual(list(pickle.loads(pickle.dumps(qs))), list(qs))
  8. def test_related_field(self):
  9. g = Group.objects.create(name="Ponies Who Own Maybachs")
  10. self.assert_pickles(Event.objects.filter(group=g.id))
  11. def test_datetime_callable_default_all(self):
  12. self.assert_pickles(Happening.objects.all())
  13. def test_datetime_callable_default_filter(self):
  14. self.assert_pickles(Happening.objects.filter(when=datetime.datetime.now()))
  15. def test_lambda_as_default(self):
  16. self.assert_pickles(Happening.objects.filter(name="test"))
  17. def test_standalone_method_as_default(self):
  18. self.assert_pickles(Happening.objects.filter(number1=1))
  19. def test_staticmethod_as_default(self):
  20. self.assert_pickles(Happening.objects.filter(number2=1))
  21. def test_classmethod_as_default(self):
  22. self.assert_pickles(Happening.objects.filter(number3=1))
  23. def test_membermethod_as_default(self):
  24. self.assert_pickles(Happening.objects.filter(number4=1))