2011-10-13 18:04:12 +00:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2010-03-21 20:29:11 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2011-07-13 09:35:51 +00:00
|
|
|
from django.conf import settings
|
2010-03-21 20:29:11 +00:00
|
|
|
from django.core.management import call_command
|
2012-03-14 08:40:35 +00:00
|
|
|
from django.db.models.loading import cache, load_app
|
2012-04-09 22:41:20 +00:00
|
|
|
from django.test import TestCase, TransactionTestCase
|
2011-08-10 22:34:45 +00:00
|
|
|
from django.test.utils import override_settings
|
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
|
|
|
|
2012-03-30 09:08:29 +00:00
|
|
|
@override_settings(INSTALLED_APPS=('app1', 'app2'))
|
2010-03-25 13:14:01 +00:00
|
|
|
class ProxyModelInheritanceTests(TransactionTestCase):
|
2012-04-09 22:41:20 +00:00
|
|
|
"""
|
|
|
|
Proxy model inheritance across apps can result in syncdb not creating the table
|
|
|
|
for the proxied model (as described in #12286). This test creates two dummy
|
|
|
|
apps and calls syncdb, then verifies that the table has been created.
|
|
|
|
"""
|
2010-03-21 20:29:11 +00:00
|
|
|
|
2013-06-04 06:09:29 +00:00
|
|
|
available_apps = []
|
|
|
|
|
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__))))
|
2012-08-15 10:02:50 +00:00
|
|
|
for app in settings.INSTALLED_APPS:
|
|
|
|
load_app(app)
|
2010-03-21 20:29:11 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
sys.path = self.old_sys_path
|
2012-03-14 08:40:35 +00:00
|
|
|
del cache.app_store[cache.app_labels['app1']]
|
|
|
|
del cache.app_store[cache.app_labels['app2']]
|
|
|
|
del cache.app_labels['app1']
|
|
|
|
del cache.app_labels['app2']
|
|
|
|
del cache.app_models['app1']
|
|
|
|
del cache.app_models['app2']
|
2010-03-21 20:29:11 +00:00
|
|
|
|
|
|
|
def test_table_exists(self):
|
2013-06-04 06:09:29 +00:00
|
|
|
try:
|
|
|
|
cache.set_available_apps(settings.INSTALLED_APPS)
|
|
|
|
call_command('syncdb', verbosity=0)
|
|
|
|
finally:
|
|
|
|
cache.unset_available_apps()
|
2011-10-13 18:04:12 +00:00
|
|
|
from .app1.models import ProxyModel
|
|
|
|
from .app2.models import NiceModel
|
2011-03-03 15:04:39 +00:00
|
|
|
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())
|