PageRenderTime 344ms CodeModel.GetById 171ms app.highlight 3ms RepoModel.GetById 168ms app.codeStats 1ms

/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
 1from django.test import TestCase
 2from modeltests.model_inheritance.models import Title
 3
 4class InheritanceSameModelNameTests(TestCase):
 5
 6    def setUp(self):
 7        # The Title model has distinct accessors for both
 8        # model_inheritance.Copy and model_inheritance_same_model_name.Copy
 9        # models.
10        self.title = Title.objects.create(title='Lorem Ipsum')
11
12    def test_inheritance_related_name(self):
13        from modeltests.model_inheritance.models import Copy
14        self.assertEqual(
15            self.title.attached_model_inheritance_copy_set.create(
16                content='Save $ on V1agr@',
17                url='http://v1agra.com/',
18                title='V1agra is spam',
19            ), Copy.objects.get(content='Save $ on V1agr@'))
20
21    def test_inheritance_with_same_model_name(self):
22        from modeltests.model_inheritance_same_model_name.models import Copy
23        self.assertEqual(
24            self.title.attached_model_inheritance_same_model_name_copy_set.create(
25                content='The Web framework for perfectionists with deadlines.',
26                url='http://www.djangoproject.com/',
27                title='Django Rocks'
28            ), Copy.objects.get(content='The Web framework for perfectionists with deadlines.'))
29
30    def test_related_name_attribute_exists(self):
31        # The Post model doesn't have an attribute called 'attached_%(app_label)s_%(class)s_set'.
32        self.assertEqual(hasattr(self.title, 'attached_%(app_label)s_%(class)s_set'), False)