2010-03-22 04:29:11 +08:00
|
|
|
import os
|
|
|
|
|
|
|
|
from django.core.management import call_command
|
2012-04-10 06:41:20 +08:00
|
|
|
from django.test import TestCase, TransactionTestCase
|
2014-10-22 02:54:32 +08:00
|
|
|
from django.test.utils import extend_sys_path
|
2010-03-22 04:29:11 +08:00
|
|
|
|
2015-01-28 20:35:27 +08:00
|
|
|
from .models import (
|
|
|
|
ConcreteModel,
|
|
|
|
ConcreteModelSubclass,
|
|
|
|
ConcreteModelSubclassProxy,
|
2015-10-06 01:26:14 +08:00
|
|
|
ProxyModel,
|
2015-01-28 20:35:27 +08:00
|
|
|
)
|
2012-04-10 06:41:20 +08:00
|
|
|
|
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
|
|
|
"""
|
2022-02-04 03:24:19 +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 test_table_exists(self):
|
2017-01-20 21:01:02 +08:00
|
|
|
with extend_sys_path(os.path.dirname(os.path.abspath(__file__))):
|
2014-01-26 13:50:40 +08:00
|
|
|
with self.modify_settings(INSTALLED_APPS={"append": ["app1", "app2"]}):
|
2014-12-27 02:56:08 +08:00
|
|
|
call_command("migrate", verbosity=0, run_syncdb=True)
|
2014-01-26 13:50:40 +08:00
|
|
|
from app1.models import ProxyModel
|
|
|
|
from app2.models import NiceModel
|
2022-02-04 03:24:19 +08:00
|
|
|
|
2014-01-26 13:50:40 +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())
|
2015-10-06 01:26:14 +08:00
|
|
|
|
|
|
|
def test_deletion_through_intermediate_proxy(self):
|
|
|
|
child = ConcreteModelSubclass.objects.create()
|
|
|
|
proxy = ProxyModel.objects.get(pk=child.pk)
|
|
|
|
proxy.delete()
|
|
|
|
self.assertFalse(ConcreteModel.objects.exists())
|
|
|
|
self.assertFalse(ConcreteModelSubclass.objects.exists())
|