2013-12-31 15:23:42 +00:00
|
|
|
from __future__ import absolute_import, unicode_literals
|
2011-10-13 18:04:12 +00:00
|
|
|
|
2010-03-21 20:29:11 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
from django.core.management import call_command
|
2012-04-09 22:41:20 +00:00
|
|
|
from django.test import TestCase, TransactionTestCase
|
2014-10-21 18:54:32 +00:00
|
|
|
from django.test.utils import extend_sys_path
|
2012-12-08 10:13:52 +00:00
|
|
|
from django.utils._os import upath
|
2010-03-21 20:29:11 +00:00
|
|
|
|
2015-01-28 12:35:27 +00:00
|
|
|
from .models import (
|
|
|
|
ConcreteModel, ConcreteModelSubclass, ConcreteModelSubclassProxy,
|
2015-10-05 17:26:14 +00:00
|
|
|
ProxyModel,
|
2015-01-28 12:35:27 +00:00
|
|
|
)
|
2012-04-09 22:41:20 +00:00
|
|
|
|
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 test_table_exists(self):
|
2014-01-26 05:50:40 +00:00
|
|
|
with extend_sys_path(os.path.dirname(os.path.abspath(upath(__file__)))):
|
|
|
|
with self.modify_settings(INSTALLED_APPS={'append': ['app1', 'app2']}):
|
2014-12-26 18:56:08 +00:00
|
|
|
call_command('migrate', verbosity=0, run_syncdb=True)
|
2014-01-26 05:50:40 +00:00
|
|
|
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())
|
2015-10-05 17:26:14 +00: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())
|