| 1 | """ |
| 2 | XX. Proxy model inheritance |
| 3 | |
| 4 | Proxy model inheritance across apps can result in syncdb not creating the table |
| 5 | for the proxied model (as described in #12286). This test creates two dummy |
| 6 | apps and calls syncdb, then verifies that the table has been created. |
| 7 | """ |
| 8 | |
| 9 | import os |
| 10 | import sys |
| 11 | |
| 12 | from django.conf import settings, Settings |
| 13 | from django.core.management import call_command |
| 14 | from django.db.models.loading import load_app |
| 15 | from django.test import TestCase |
| 16 | |
| 17 | class ProxyModelInheritanceTests(TestCase): |
| 18 | |
| 19 | def setUp(self): |
| 20 | self.old_sys_path = sys.path |
| 21 | sys.path.append(os.path.dirname(os.path.abspath(__file__))) |
| 22 | self.old_installed_apps = settings.INSTALLED_APPS |
| 23 | settings.INSTALLED_APPS = ('app1', 'app2') |
| 24 | map(load_app, settings.INSTALLED_APPS) |
| 25 | call_command('syncdb') |
| 26 | from app1.models import ProxyModel |
| 27 | from app2.models import NiceModel |
| 28 | global ProxyModel, NiceModel |
| 29 | |
| 30 | def tearDown(self): |
| 31 | settings.INSTALLED_APPS = self.old_installed_apps |
| 32 | sys.path = self.old_sys_path |
| 33 | |
| 34 | def test_table_exists(self): |
| 35 | self.assertEquals(NiceModel.objects.all().count(), 0) |
| 36 | self.assertEquals(ProxyModel.objects.all().count(), 0) |