diff -r 4e50391161c1 tests/regressiontests/app_loading/tests.py
a
|
b
|
|
4 | 4 | from unittest import TestCase |
5 | 5 | |
6 | 6 | from django.conf import Settings |
7 | | from django.db.models.loading import load_app |
| 7 | import django.db.models.loading |
8 | 8 | |
9 | 9 | __test__ = {"API_TESTS": """ |
10 | 10 | Test the globbing of INSTALLED_APPS. |
… |
… |
|
32 | 32 | def setUp(self): |
33 | 33 | self.old_path = sys.path |
34 | 34 | self.egg_dir = '%s/eggs' % os.path.dirname(__file__) |
| 35 | self.models_module = None |
35 | 36 | |
36 | 37 | def tearDown(self): |
37 | 38 | sys.path = self.old_path |
| 39 | if self.models_module is not None: |
| 40 | del django.db.models.loading.cache.app_store[self.models_module] |
| 41 | |
38 | 42 | |
39 | 43 | def test_egg1(self): |
40 | 44 | """Models module can be loaded from an app in an egg""" |
41 | 45 | egg_name = '%s/modelapp.egg' % self.egg_dir |
42 | 46 | sys.path.append(egg_name) |
43 | | models = load_app('app_with_models') |
| 47 | models = django.db.models.loading.load_app('app_with_models') |
44 | 48 | self.failIf(models is None) |
| 49 | self.models_module = models |
45 | 50 | |
46 | 51 | def test_egg2(self): |
47 | 52 | """Loading an app from an egg that has no models returns no models (and no error)""" |
48 | 53 | egg_name = '%s/nomodelapp.egg' % self.egg_dir |
49 | 54 | sys.path.append(egg_name) |
50 | | models = load_app('app_no_models') |
| 55 | models = django.db.models.loading.load_app('app_no_models') |
51 | 56 | self.failUnless(models is None) |
52 | 57 | |
53 | 58 | def test_egg3(self): |
54 | 59 | """Models module can be loaded from an app located under an egg's top-level package""" |
55 | 60 | egg_name = '%s/omelet.egg' % self.egg_dir |
56 | 61 | sys.path.append(egg_name) |
57 | | models = load_app('omelet.app_with_models') |
| 62 | models = django.db.models.loading.load_app('omelet.app_with_models') |
58 | 63 | self.failIf(models is None) |
| 64 | self.models_module = models |
59 | 65 | |
60 | 66 | def test_egg4(self): |
61 | 67 | """Loading an app with no models from under the top-level egg package generates no error""" |
62 | 68 | egg_name = '%s/omelet.egg' % self.egg_dir |
63 | 69 | sys.path.append(egg_name) |
64 | | models = load_app('omelet.app_no_models') |
| 70 | models = django.db.models.loading.load_app('omelet.app_no_models') |
65 | 71 | self.failUnless(models is None) |
66 | 72 | |
67 | 73 | def test_egg5(self): |
68 | 74 | """Loading an app from an egg that has an import error in its models module raises that error""" |
69 | 75 | egg_name = '%s/brokenapp.egg' % self.egg_dir |
70 | 76 | sys.path.append(egg_name) |
71 | | self.assertRaises(ImportError, load_app, 'broken_app') |
| 77 | self.assertRaises(ImportError, django.db.models.loading.load_app, 'broken_app') |
72 | 78 | try: |
73 | | load_app('broken_app') |
| 79 | django.db.models.loading.load_app('broken_app') |
74 | 80 | except ImportError, e: |
75 | 81 | # Make sure the message is indicating the actual |
76 | 82 | # problem in the broken app. |