Ticket #17667: 17667.diff

File 17667.diff, 2.6 KB (added by Anssi Kääriäinen, 13 years ago)
  • django/db/models/loading.py

    diff --git a/django/db/models/loading.py b/django/db/models/loading.py
    index c344686..9bdbe50 100644
    a b class AppCache(object):  
    8181        Loads the app with the provided fully qualified name, and returns the
    8282        model module.
    8383        """
     84        app_module = import_module(app_name)
    8485        self.handled[app_name] = None
    8586        self.nesting_level += 1
    86         app_module = import_module(app_name)
    8787        try:
    8888            models = import_module('.models', app_name)
    8989        except ImportError:
  • tests/regressiontests/app_loading/tests.py

    diff --git a/tests/regressiontests/app_loading/tests.py b/tests/regressiontests/app_loading/tests.py
    index 5173338..6702822 100644
    a b import sys  
    66import time
    77
    88from django.conf import Settings
    9 from django.db.models.loading import cache, load_app, get_model, get_models
     9from django.db.models.loading import cache, load_app, get_model, get_models, AppCache
     10from django.test.utils import override_settings
    1011from django.utils.unittest import TestCase
    1112
    1213class EggLoadingTest(TestCase):
    class EggLoadingTest(TestCase):  
    5960        egg_name = '%s/brokenapp.egg' % self.egg_dir
    6061        sys.path.append(egg_name)
    6162        self.assertRaises(ImportError, load_app, 'broken_app')
     63        raised = None
    6264        try:
    6365            load_app('broken_app')
    6466        except ImportError, e:
    65             # Make sure the message is indicating the actual
    66             # problem in the broken app.
    67             self.assertTrue("modelz" in e.args[0])
     67            raised = e
     68        # Make sure the message is indicating the actual
     69        # problem in the broken app.
     70        self.assertTrue(raised is not None)
     71        self.assertTrue("modelz" in raised.args[0])
     72   
     73    def test_missing_app(self):
     74        """
     75        Test that repeated app loading doesn't succeed in case there is an
     76        error. Refs #17667.
     77        """
     78        try:
     79            # AppCache is a Borg, so we can instantiate one and change its loaded to False
     80            # to force the following code to actually try to populate the cache.
     81            a = AppCache()
     82            a.loaded = False
     83            with override_settings(INSTALLED_APPS=('notexists',)):
     84                self.assertRaises(ImportError, get_model, 'notexists', 'nomodel', seed_cache=True)
     85                self.assertRaises(ImportError, get_model, 'notexists', 'nomodel', seed_cache=True)
     86        finally:
     87            a.loaded = True
    6888
    6989
    7090class GetModelsTest(TestCase):
Back to Top