2013-07-30 01:19:04 +08:00
|
|
|
from __future__ import unicode_literals
|
2011-10-14 02:04:12 +08:00
|
|
|
|
2010-03-22 04:29:11 +08:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2013-12-16 18:52:05 +08:00
|
|
|
from django.core.apps import app_cache
|
2010-03-22 04:29:11 +08:00
|
|
|
from django.core.management import call_command
|
2012-04-10 06:41:20 +08:00
|
|
|
from django.test import TestCase, TransactionTestCase
|
2011-08-11 06:34:45 +08:00
|
|
|
from django.test.utils import override_settings
|
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
|
|
|
|
2013-12-20 05:33:46 +08:00
|
|
|
# Required for available_apps.
|
|
|
|
@override_settings(INSTALLED_APPS=['app1', 'app2'])
|
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-19 00:56:11 +08:00
|
|
|
available_apps = ['app1', 'app2']
|
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
|
|
|
|
|
|
|
|
def test_table_exists(self):
|
2013-12-20 05:33:46 +08:00
|
|
|
with app_cache._with_app('app1'), app_cache._with_app('app2'):
|
|
|
|
call_command('migrate', verbosity=0)
|
|
|
|
from .app1.models import ProxyModel
|
|
|
|
from .app2.models import NiceModel
|
|
|
|
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())
|