PageRenderTime 18ms CodeModel.GetById 8ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/modeltests/proxy_model_inheritance/tests.py

https://code.google.com/p/mango-py/
Python | 36 lines | 23 code | 6 blank | 7 comment | 0 complexity | 8f99aa76615311fe0f69bb421475e7f6 MD5 | raw file
 1"""
 2XX. Proxy model inheritance
 3
 4Proxy model inheritance across apps can result in syncdb not creating the table
 5for the proxied model (as described in #12286).  This test creates two dummy
 6apps and calls syncdb, then verifies that the table has been created.
 7"""
 8
 9import os
10import sys
11
12from django.conf import settings, Settings
13from django.core.management import call_command
14from django.db.models.loading import load_app
15from django.test import TransactionTestCase
16
17class ProxyModelInheritanceTests(TransactionTestCase):
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', verbosity=0)
26        global ProxyModel, NiceModel
27        from app1.models import ProxyModel
28        from app2.models import 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.assertEqual(NiceModel.objects.all().count(), 0)
36        self.assertEqual(ProxyModel.objects.all().count(), 0)