mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Merged regressiontests and modeltests into the test root.
This commit is contained in:
0
tests/model_inheritance_same_model_name/__init__.py
Normal file
0
tests/model_inheritance_same_model_name/__init__.py
Normal file
24
tests/model_inheritance_same_model_name/models.py
Normal file
24
tests/model_inheritance_same_model_name/models.py
Normal file
@@ -0,0 +1,24 @@
|
||||
"""
|
||||
XX. Model inheritance
|
||||
|
||||
Model inheritance across apps can result in models with the same name resulting
|
||||
in the need for an %(app_label)s format string. This app specifically tests
|
||||
this feature by redefining the Copy model from model_inheritance/models.py
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.db import models
|
||||
|
||||
from ..model_inheritance.models import NamedURL
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
|
||||
#
|
||||
# Abstract base classes with related models
|
||||
#
|
||||
@python_2_unicode_compatible
|
||||
class Copy(NamedURL):
|
||||
content = models.TextField()
|
||||
|
||||
def __str__(self):
|
||||
return self.content
|
||||
36
tests/model_inheritance_same_model_name/tests.py
Normal file
36
tests/model_inheritance_same_model_name/tests.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from ..model_inheritance.models import Title
|
||||
|
||||
|
||||
class InheritanceSameModelNameTests(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
# The Title model has distinct accessors for both
|
||||
# model_inheritance.Copy and model_inheritance_same_model_name.Copy
|
||||
# models.
|
||||
self.title = Title.objects.create(title='Lorem Ipsum')
|
||||
|
||||
def test_inheritance_related_name(self):
|
||||
from modeltests.model_inheritance.models import Copy
|
||||
self.assertEqual(
|
||||
self.title.attached_model_inheritance_copy_set.create(
|
||||
content='Save $ on V1agr@',
|
||||
url='http://v1agra.com/',
|
||||
title='V1agra is spam',
|
||||
), Copy.objects.get(content='Save $ on V1agr@'))
|
||||
|
||||
def test_inheritance_with_same_model_name(self):
|
||||
from modeltests.model_inheritance_same_model_name.models import Copy
|
||||
self.assertEqual(
|
||||
self.title.attached_model_inheritance_same_model_name_copy_set.create(
|
||||
content='The Web framework for perfectionists with deadlines.',
|
||||
url='http://www.djangoproject.com/',
|
||||
title='Django Rocks'
|
||||
), Copy.objects.get(content='The Web framework for perfectionists with deadlines.'))
|
||||
|
||||
def test_related_name_attribute_exists(self):
|
||||
# The Post model doesn't have an attribute called 'attached_%(app_label)s_%(class)s_set'.
|
||||
self.assertEqual(hasattr(self.title, 'attached_%(app_label)s_%(class)s_set'), False)
|
||||
Reference in New Issue
Block a user