PageRenderTime 30ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/modeltests/model_inheritance_same_model_name/tests.py

https://code.google.com/p/mango-py/
Python | 32 lines | 23 code | 5 blank | 4 comment | 0 complexity | edacac2b31d7636b40ca10a306d504ba MD5 | raw file
Possible License(s): BSD-3-Clause
  1. from django.test import TestCase
  2. from modeltests.model_inheritance.models import Title
  3. class InheritanceSameModelNameTests(TestCase):
  4. def setUp(self):
  5. # The Title model has distinct accessors for both
  6. # model_inheritance.Copy and model_inheritance_same_model_name.Copy
  7. # models.
  8. self.title = Title.objects.create(title='Lorem Ipsum')
  9. def test_inheritance_related_name(self):
  10. from modeltests.model_inheritance.models import Copy
  11. self.assertEqual(
  12. self.title.attached_model_inheritance_copy_set.create(
  13. content='Save $ on V1agr@',
  14. url='http://v1agra.com/',
  15. title='V1agra is spam',
  16. ), Copy.objects.get(content='Save $ on V1agr@'))
  17. def test_inheritance_with_same_model_name(self):
  18. from modeltests.model_inheritance_same_model_name.models import Copy
  19. self.assertEqual(
  20. self.title.attached_model_inheritance_same_model_name_copy_set.create(
  21. content='The Web framework for perfectionists with deadlines.',
  22. url='http://www.djangoproject.com/',
  23. title='Django Rocks'
  24. ), Copy.objects.get(content='The Web framework for perfectionists with deadlines.'))
  25. def test_related_name_attribute_exists(self):
  26. # The Post model doesn't have an attribute called 'attached_%(app_label)s_%(class)s_set'.
  27. self.assertEqual(hasattr(self.title, 'attached_%(app_label)s_%(class)s_set'), False)