summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCarl Meyer <carl@oddbird.net>2011-04-20 17:58:37 +0000
committerCarl Meyer <carl@oddbird.net>2011-04-20 17:58:37 +0000
commit6bdaef26ec9cc9841b944e1d18b13185f7bbe2f5 (patch)
treeace55105ff4d3a10a976417f119757cc9b276b4e /tests
parentfda8a9a3902649fb70806f7def55851012047490 (diff)
Fixed #15866, #15850 -- Prevented get_model() and get_models() from returning not-installed models (by default). Thanks adsva for report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16053 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/admin_scripts/tests.py6
-rw-r--r--tests/regressiontests/app_loading/not_installed/__init__.py0
-rw-r--r--tests/regressiontests/app_loading/not_installed/models.py5
-rw-r--r--tests/regressiontests/app_loading/tests.py23
4 files changed, 32 insertions, 2 deletions
diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py
index 32183fad3e..a8c5e882f1 100644
--- a/tests/regressiontests/admin_scripts/tests.py
+++ b/tests/regressiontests/admin_scripts/tests.py
@@ -1023,7 +1023,11 @@ class ManageValidate(AdminScriptTestCase):
def test_app_with_import(self):
"manage.py validate does not raise errors when an app imports a base class that itself has an abstract base"
self.write_settings('settings.py',
- apps=['admin_scripts.app_with_import', 'django.contrib.comments'],
+ apps=['admin_scripts.app_with_import',
+ 'django.contrib.comments',
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sites'],
sdict={'DEBUG': True})
args = ['validate']
out, err = self.run_manage(args)
diff --git a/tests/regressiontests/app_loading/not_installed/__init__.py b/tests/regressiontests/app_loading/not_installed/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/regressiontests/app_loading/not_installed/__init__.py
diff --git a/tests/regressiontests/app_loading/not_installed/models.py b/tests/regressiontests/app_loading/not_installed/models.py
new file mode 100644
index 0000000000..615feefddb
--- /dev/null
+++ b/tests/regressiontests/app_loading/not_installed/models.py
@@ -0,0 +1,5 @@
+from django.db import models
+
+
+class NotInstalledModel(models.Model):
+ pass
diff --git a/tests/regressiontests/app_loading/tests.py b/tests/regressiontests/app_loading/tests.py
index 78e6519e35..6ee06c50c9 100644
--- a/tests/regressiontests/app_loading/tests.py
+++ b/tests/regressiontests/app_loading/tests.py
@@ -4,7 +4,7 @@ import sys
import time
from django.conf import Settings
-from django.db.models.loading import cache, load_app
+from django.db.models.loading import cache, load_app, get_model, get_models
from django.utils.unittest import TestCase
@@ -81,3 +81,24 @@ class EggLoadingTest(TestCase):
# Make sure the message is indicating the actual
# problem in the broken app.
self.assertTrue("modelz" in e.args[0])
+
+
+class GetModelsTest(TestCase):
+ def setUp(self):
+ import not_installed.models
+ self.not_installed_module = not_installed.models
+
+
+ def test_get_model_only_returns_installed_models(self):
+ self.assertEqual(
+ get_model("not_installed", "NotInstalledModel"), None)
+
+
+ def test_get_models_only_returns_installed_models(self):
+ self.assertFalse(
+ "NotInstalledModel" in
+ [m.__name__ for m in get_models()])
+
+
+ def test_get_models_with_app_label_only_returns_installed_models(self):
+ self.assertEqual(get_models(self.not_installed_module), [])