From 2b7bfaccf2d9b9f19595e8024620ee988d1305e7 Mon Sep 17 00:00:00 2001 From: Arthur Koziel Date: Wed, 11 Aug 2010 01:39:37 +0000 Subject: [soc2010/app-loading] load custom models if specified with models_path attribute git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/app-loading@13570 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/appcachetests/model_app/__init__.py | 8 ++++++++ tests/appcachetests/model_app/othermodels.py | 5 +++++ tests/appcachetests/runtests.py | 17 ++++++++++++----- 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 tests/appcachetests/model_app/othermodels.py (limited to 'tests') diff --git a/tests/appcachetests/model_app/__init__.py b/tests/appcachetests/model_app/__init__.py index e69de29bb2..214e438e38 100644 --- a/tests/appcachetests/model_app/__init__.py +++ b/tests/appcachetests/model_app/__init__.py @@ -0,0 +1,8 @@ +from django.core.apps import App + +class MyApp(App): + models_path = 'model_app.othermodels' + + def __repr__(self): + return '' % self.name + diff --git a/tests/appcachetests/model_app/othermodels.py b/tests/appcachetests/model_app/othermodels.py new file mode 100644 index 0000000000..ffb04e89c4 --- /dev/null +++ b/tests/appcachetests/model_app/othermodels.py @@ -0,0 +1,5 @@ +from django.db import models + +class Person(models.Model): + first_name = models.CharField(max_length=30) + last_name = models.CharField(max_length=30) diff --git a/tests/appcachetests/runtests.py b/tests/appcachetests/runtests.py index 83730cc4af..719e54f533 100644 --- a/tests/appcachetests/runtests.py +++ b/tests/appcachetests/runtests.py @@ -221,10 +221,9 @@ class LoadAppTests(AppCacheTestCase): app = cache.app_instances[0] self.assertEqual(len(cache.app_instances), 1) self.assertEqual(app.name, 'nomodel_app') - self.assertEqual(app.models_module, None) self.assertEqual(rv, None) - def test_load_app_custom(self): + def test_custom_app(self): """ Test that a custom app instance is created if the function gets passed a classname @@ -235,10 +234,18 @@ class LoadAppTests(AppCacheTestCase): self.assertEqual(len(cache.app_instances), 1) self.assertEqual(app.name, 'nomodel_app') self.assertTrue(isinstance(app, MyApp)) - self.assertEqual(app.models_module, None) self.assertEqual(rv, None) - def test_load_app_twice(self): + def test_custom_models_path(self): + """ + Test that custom models are imported correctly + """ + rv = cache.load_app('model_app.MyApp') + app = cache.app_instances[0] + self.assertEqual(app.models_module.__name__, 'model_app.othermodels') + self.assertEqual(rv.__name__, 'model_app.othermodels') + + def test_twice(self): """ Test that loading an app twice results in only one app instance """ @@ -248,7 +255,7 @@ class LoadAppTests(AppCacheTestCase): self.assertEqual(rv.__name__, 'model_app.models') self.assertEqual(rv2.__name__, 'model_app.models') - def test_load_app_importerror(self): + def test_importerror(self): """ Test that an ImportError exception is raised if a package cannot be imported -- cgit v1.2.1