Ticket #12286: proxy_model_inheritance_test.diff

File proxy_model_inheritance_test.diff, 2.7 KB (added by flyingfred0, 15 years ago)
  • tests/modeltests/proxy_model_inheritance/app1/models.py

     
     1from app2.models import NiceModel
     2
     3class ProxyModel(NiceModel):
     4    class Meta:
     5        proxy = True
  • tests/modeltests/proxy_model_inheritance/app2/models.py

     
     1from django.db import models
     2
     3class NiceModel(models.Model):
     4    pass
  • tests/modeltests/proxy_model_inheritance/tests.py

     
     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 TestCase
     16
     17class 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)
Back to Top