parts/django/tests/modeltests/model_inheritance_same_model_name/tests.py
changeset 307 c6bca38c1cbf
equal deleted inserted replaced
306:5ff1fc726848 307:c6bca38c1cbf
       
     1 from django.test import TestCase
       
     2 from modeltests.model_inheritance.models import Title
       
     3 
       
     4 class 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.assertEquals(
       
    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.assertEquals(
       
    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)