summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2013-12-18 17:56:11 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-12-22 11:39:17 +0100
commitf25fa9d8590c7759c1ec7ffecf1d67be81237674 (patch)
treec0a4a40a5371ad8e0d1c1af8c04295e874170041 /tests
parent439b364e1e81371bd87488beed35ce051be8aaaa (diff)
Deprecated load_app().
Adjusted several tests that used it to add apps to the app cache and then attempted to remove them by manipulating attributes directly. Also renamed invalid_models to invalid_models_tests to avoid clashing application labels between the outer and the inner invalid_models applications.
Diffstat (limited to 'tests')
-rw-r--r--tests/admin_scripts/tests.py2
-rw-r--r--tests/app_loading/tests.py35
-rw-r--r--tests/invalid_models_tests/__init__.py (renamed from tests/invalid_models/__init__.py)0
-rw-r--r--tests/invalid_models_tests/invalid_models/__init__.py (renamed from tests/invalid_models/invalid_models/__init__.py)0
-rw-r--r--tests/invalid_models_tests/invalid_models/models.py (renamed from tests/invalid_models/invalid_models/models.py)0
-rw-r--r--tests/invalid_models_tests/tests.py (renamed from tests/invalid_models/tests.py)15
-rw-r--r--tests/migrations/test_writer.py10
-rw-r--r--tests/proxy_model_inheritance/tests.py21
-rwxr-xr-xtests/runtests.py3
9 files changed, 33 insertions, 53 deletions
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
index db0b8d6030..3f9a336c16 100644
--- a/tests/admin_scripts/tests.py
+++ b/tests/admin_scripts/tests.py
@@ -1094,7 +1094,7 @@ class ManageValidate(AdminScriptTestCase):
self.assertOutput(err, 'ImportError')
def test_complex_app(self):
- "manage.py validate does not raise an ImportError validating a complex app with nested calls to load_app"
+ "manage.py validate does not raise an ImportError validating a complex app"
self.write_settings('settings.py',
apps=['admin_scripts.complex_app', 'admin_scripts.simple_app'],
sdict={'DEBUG': True})
diff --git a/tests/app_loading/tests.py b/tests/app_loading/tests.py
index 45f6cd6c31..bb71ad84a2 100644
--- a/tests/app_loading/tests.py
+++ b/tests/app_loading/tests.py
@@ -8,6 +8,7 @@ from django.core.apps import app_cache
from django.core.apps.cache import AppCache
from django.test.utils import override_settings
from django.utils._os import upath
+from django.utils import six
class EggLoadingTest(TestCase):
@@ -31,45 +32,41 @@ class EggLoadingTest(TestCase):
"""Models module can be loaded from an app in an egg"""
egg_name = '%s/modelapp.egg' % self.egg_dir
sys.path.append(egg_name)
- models = app_cache.load_app('app_with_models')
- self.assertFalse(models is None)
+ with app_cache._with_app('app_with_models'):
+ models_module = app_cache.get_app_config('app_with_models').models_module
+ self.assertIsNotNone(models_module)
def test_egg2(self):
"""Loading an app from an egg that has no models returns no models (and no error)"""
egg_name = '%s/nomodelapp.egg' % self.egg_dir
sys.path.append(egg_name)
- models = app_cache.load_app('app_no_models')
- self.assertTrue(models is None)
+ with app_cache._with_app('app_no_models'):
+ models_module = app_cache.get_app_config('app_no_models').models_module
+ self.assertIsNone(models_module)
def test_egg3(self):
"""Models module can be loaded from an app located under an egg's top-level package"""
egg_name = '%s/omelet.egg' % self.egg_dir
sys.path.append(egg_name)
- models = app_cache.load_app('omelet.app_with_models')
- self.assertFalse(models is None)
+ with app_cache._with_app('omelet.app_with_models'):
+ models_module = app_cache.get_app_config('app_with_models').models_module
+ self.assertIsNotNone(models_module)
def test_egg4(self):
"""Loading an app with no models from under the top-level egg package generates no error"""
egg_name = '%s/omelet.egg' % self.egg_dir
sys.path.append(egg_name)
- models = app_cache.load_app('omelet.app_no_models')
- self.assertTrue(models is None)
+ with app_cache._with_app('omelet.app_no_models'):
+ models_module = app_cache.get_app_config('app_no_models').models_module
+ self.assertIsNone(models_module)
def test_egg5(self):
"""Loading an app from an egg that has an import error in its models module raises that error"""
egg_name = '%s/brokenapp.egg' % self.egg_dir
sys.path.append(egg_name)
- self.assertRaises(ImportError, app_cache.load_app, 'broken_app')
- raised = None
- try:
- app_cache.load_app('broken_app')
- except ImportError as e:
- raised = e
-
- # Make sure the message is indicating the actual
- # problem in the broken app.
- self.assertTrue(raised is not None)
- self.assertTrue("modelz" in raised.args[0])
+ with six.assertRaisesRegex(self, ImportError, 'modelz'):
+ with app_cache._with_app('broken_app'):
+ app_cache.get_app_config('omelet.app_no_models').models_module
def test_missing_app(self):
"""
diff --git a/tests/invalid_models/__init__.py b/tests/invalid_models_tests/__init__.py
index e69de29bb2..e69de29bb2 100644
--- a/tests/invalid_models/__init__.py
+++ b/tests/invalid_models_tests/__init__.py
diff --git a/tests/invalid_models/invalid_models/__init__.py b/tests/invalid_models_tests/invalid_models/__init__.py
index e69de29bb2..e69de29bb2 100644
--- a/tests/invalid_models/invalid_models/__init__.py
+++ b/tests/invalid_models_tests/invalid_models/__init__.py
diff --git a/tests/invalid_models/invalid_models/models.py b/tests/invalid_models_tests/invalid_models/models.py
index 0c991dcf13..0c991dcf13 100644
--- a/tests/invalid_models/invalid_models/models.py
+++ b/tests/invalid_models_tests/invalid_models/models.py
diff --git a/tests/invalid_models/tests.py b/tests/invalid_models_tests/tests.py
index 10d8fa47a7..4e0cef546b 100644
--- a/tests/invalid_models/tests.py
+++ b/tests/invalid_models_tests/tests.py
@@ -18,14 +18,7 @@ class InvalidModelTestCase(unittest.TestCase):
self.stdout = StringIO()
sys.stdout = self.stdout
- # The models need to be removed after the test in order to prevent bad
- # interactions with the flush operation in other tests.
- self._old_models = app_cache.app_configs['invalid_models'].models.copy()
-
def tearDown(self):
- app_cache.app_configs['invalid_models'].models = self._old_models
- app_cache.all_models['invalid_models'] = self._old_models
- app_cache._get_models_cache = {}
sys.stdout = self.old_stdout
# Technically, this isn't an override -- TEST_SWAPPED_MODEL must be
@@ -38,12 +31,10 @@ class InvalidModelTestCase(unittest.TestCase):
TEST_SWAPPED_MODEL_BAD_MODEL='not_an_app.Target',
)
def test_invalid_models(self):
- try:
- module = app_cache.load_app("invalid_models.invalid_models")
- except Exception:
- self.fail('Unable to load invalid model module')
+ with app_cache._with_app("invalid_models_tests.invalid_models"):
+ module = app_cache.get_app_config("invalid_models").models_module
+ get_validation_errors(self.stdout, module)
- get_validation_errors(self.stdout, module)
self.stdout.seek(0)
error_log = self.stdout.read()
actual = error_log.split('\n')
diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py
index 76fe5b5a9e..f921f9f03c 100644
--- a/tests/migrations/test_writer.py
+++ b/tests/migrations/test_writer.py
@@ -124,8 +124,8 @@ class WriterTests(TestCase):
with override_settings(INSTALLED_APPS=test_apps):
for app in test_apps:
- app_cache.load_app(app)
- migration = migrations.Migration('0001_initial', app.split('.')[-1])
- expected_path = os.path.join(base_dir, *(app.split('.') + ['migrations', '0001_initial.py']))
- writer = MigrationWriter(migration)
- self.assertEqual(writer.path, expected_path)
+ with app_cache._with_app(app):
+ migration = migrations.Migration('0001_initial', app.split('.')[-1])
+ expected_path = os.path.join(base_dir, *(app.split('.') + ['migrations', '0001_initial.py']))
+ writer = MigrationWriter(migration)
+ self.assertEqual(writer.path, expected_path)
diff --git a/tests/proxy_model_inheritance/tests.py b/tests/proxy_model_inheritance/tests.py
index 601fdc5b42..01a2ddfef6 100644
--- a/tests/proxy_model_inheritance/tests.py
+++ b/tests/proxy_model_inheritance/tests.py
@@ -3,7 +3,6 @@ from __future__ import unicode_literals
import os
import sys
-from django.conf import settings
from django.core.apps import app_cache
from django.core.management import call_command
from django.test import TestCase, TransactionTestCase
@@ -21,28 +20,21 @@ class ProxyModelInheritanceTests(TransactionTestCase):
for the proxied model (as described in #12286). This test creates two dummy
apps and calls migrate, then verifies that the table has been created.
"""
-
- available_apps = []
+ available_apps = ['app1', 'app2']
def setUp(self):
self.old_sys_path = sys.path[:]
sys.path.append(os.path.dirname(os.path.abspath(upath(__file__))))
- for app in settings.INSTALLED_APPS:
- app_cache.load_app(app)
+ self._with_app1 = app_cache._begin_with_app('app1')
+ self._with_app2 = app_cache._begin_with_app('app2')
def tearDown(self):
+ app_cache._end_with_app(self._with_app1)
+ app_cache._end_with_app(self._with_app2)
sys.path = self.old_sys_path
- del app_cache.app_configs['app1']
- del app_cache.app_configs['app2']
- del app_cache.all_models['app1']
- del app_cache.all_models['app2']
def test_table_exists(self):
- try:
- app_cache.set_available_apps(settings.INSTALLED_APPS)
- call_command('migrate', verbosity=0)
- finally:
- app_cache.unset_available_apps()
+ call_command('migrate', verbosity=0)
from .app1.models import ProxyModel
from .app2.models import NiceModel
self.assertEqual(NiceModel.objects.all().count(), 0)
@@ -56,7 +48,6 @@ class MultiTableInheritanceProxyTest(TestCase):
Deleting an instance of a model proxying a multi-table inherited
subclass should cascade delete down the whole inheritance chain (see
#18083).
-
"""
instance = ConcreteModelSubclassProxy.objects.create()
instance.delete()
diff --git a/tests/runtests.py b/tests/runtests.py
index 77cf005267..64d363a095 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -164,7 +164,8 @@ def setup(verbosity, test_labels):
if module_found_in_labels:
if verbosity >= 2:
print("Importing application %s" % module_name)
- app_cache.load_app(module_label)
+ # HACK.
+ app_cache._begin_with_app(module_label)
if module_label not in settings.INSTALLED_APPS:
settings.INSTALLED_APPS.append(module_label)