2013-12-31 23:23:42 +08:00
|
|
|
from __future__ import absolute_import, unicode_literals
|
2011-10-14 02:04:12 +08:00
|
|
|
|
2010-03-22 04:29:11 +08:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from django.core.management import call_command
|
2012-04-10 06:41:20 +08:00
|
|
|
from django.test import TestCase, TransactionTestCase
|
2014-01-20 10:45:21 +08:00
|
|
|
from django.test.utils import override_system_checks
|
2012-12-08 18:13:52 +08:00
|
|
|
from django.utils._os import upath
|
2010-03-22 04:29:11 +08:00
|
|
|
|
2012-04-10 06:41:20 +08:00
|
|
|
from .models import (ConcreteModel, ConcreteModelSubclass,
|
|
|
|
ConcreteModelSubclassProxy)
|
|
|
|
|
2011-10-14 02:04:12 +08:00
|
|
|
|
2010-03-25 21:14:01 +08:00
|
|
|
class ProxyModelInheritanceTests(TransactionTestCase):
|
2012-04-10 06:41:20 +08:00
|
|
|
"""
|
2013-09-03 23:51:34 +08:00
|
|
|
Proxy model inheritance across apps can result in migrate not creating the table
|
2012-04-10 06:41:20 +08:00
|
|
|
for the proxied model (as described in #12286). This test creates two dummy
|
2013-09-03 23:51:34 +08:00
|
|
|
apps and calls migrate, then verifies that the table has been created.
|
2012-04-10 06:41:20 +08:00
|
|
|
"""
|
2013-12-20 17:39:12 +08:00
|
|
|
available_apps = []
|
2013-06-04 14:09:29 +08:00
|
|
|
|
2010-03-22 04:29:11 +08:00
|
|
|
def setUp(self):
|
2010-11-02 13:31:19 +08:00
|
|
|
self.old_sys_path = sys.path[:]
|
2012-12-08 18:13:52 +08:00
|
|
|
sys.path.append(os.path.dirname(os.path.abspath(upath(__file__))))
|
2010-03-22 04:29:11 +08:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
sys.path = self.old_sys_path
|
|
|
|
|
2014-01-20 10:45:21 +08:00
|
|
|
# `auth` app is imported, but not installed in this test, so we need to
|
|
|
|
# exclude checks registered by this app.
|
|
|
|
@override_system_checks([])
|
2010-03-22 04:29:11 +08:00
|
|
|
def test_table_exists(self):
|
2013-12-23 17:37:34 +08:00
|
|
|
with self.modify_settings(INSTALLED_APPS={'append': ['app1', 'app2']}):
|
2013-12-20 05:33:46 +08:00
|
|
|
call_command('migrate', verbosity=0)
|
2013-12-31 23:23:42 +08:00
|
|
|
from app1.models import ProxyModel
|
|
|
|
from app2.models import NiceModel
|
2013-12-20 05:33:46 +08:00
|
|
|
self.assertEqual(NiceModel.objects.all().count(), 0)
|
|
|
|
self.assertEqual(ProxyModel.objects.all().count(), 0)
|
2012-04-10 06:41:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
class MultiTableInheritanceProxyTest(TestCase):
|
|
|
|
|
|
|
|
def test_model_subclass_proxy(self):
|
|
|
|
"""
|
|
|
|
Deleting an instance of a model proxying a multi-table inherited
|
|
|
|
subclass should cascade delete down the whole inheritance chain (see
|
|
|
|
#18083).
|
|
|
|
"""
|
|
|
|
instance = ConcreteModelSubclassProxy.objects.create()
|
|
|
|
instance.delete()
|
|
|
|
self.assertEqual(0, ConcreteModelSubclassProxy.objects.count())
|
|
|
|
self.assertEqual(0, ConcreteModelSubclass.objects.count())
|
|
|
|
self.assertEqual(0, ConcreteModel.objects.count())
|