2013-07-29 17:19:04 +00:00
|
|
|
from __future__ import unicode_literals
|
2011-10-13 18:04:12 +00:00
|
|
|
|
2010-03-21 20:29:11 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from django.core.management import call_command
|
2012-04-09 22:41:20 +00:00
|
|
|
from django.test import TestCase, TransactionTestCase
|
2012-12-08 10:13:52 +00:00
|
|
|
from django.utils._os import upath
|
2010-03-21 20:29:11 +00:00
|
|
|
|
2012-04-09 22:41:20 +00:00
|
|
|
from .models import (ConcreteModel, ConcreteModelSubclass,
|
|
|
|
ConcreteModelSubclassProxy)
|
|
|
|
|
2011-10-13 18:04:12 +00:00
|
|
|
|
2010-03-25 13:14:01 +00:00
|
|
|
class ProxyModelInheritanceTests(TransactionTestCase):
|
2012-04-09 22:41:20 +00:00
|
|
|
"""
|
2013-09-03 15:51:34 +00:00
|
|
|
Proxy model inheritance across apps can result in migrate not creating the table
|
2012-04-09 22:41:20 +00:00
|
|
|
for the proxied model (as described in #12286). This test creates two dummy
|
2013-09-03 15:51:34 +00:00
|
|
|
apps and calls migrate, then verifies that the table has been created.
|
2012-04-09 22:41:20 +00:00
|
|
|
"""
|
2013-12-20 09:39:12 +00:00
|
|
|
available_apps = []
|
2013-06-04 06:09:29 +00:00
|
|
|
|
2010-03-21 20:29:11 +00:00
|
|
|
def setUp(self):
|
2010-11-02 05:31:19 +00:00
|
|
|
self.old_sys_path = sys.path[:]
|
2012-12-08 10:13:52 +00:00
|
|
|
sys.path.append(os.path.dirname(os.path.abspath(upath(__file__))))
|
2010-03-21 20:29:11 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
sys.path = self.old_sys_path
|
|
|
|
|
|
|
|
def test_table_exists(self):
|
2013-12-23 09:37:34 +00:00
|
|
|
with self.modify_settings(INSTALLED_APPS={'append': ['app1', 'app2']}):
|
2013-12-19 21:33:46 +00:00
|
|
|
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-09 22:41:20 +00: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())
|