Author: arthurk Date: 2010-09-12 16:16:09 -0500 (Sun, 12 Sep 2010) New Revision: 13810
Added: django/branches/soc2010/app-loading/tests/appcachetests/model_app/apps.py django/branches/soc2010/app-loading/tests/appcachetests/nomodel_app/apps.py django/branches/soc2010/app-loading/tests/appcachetests/same_label/nomodel_app/apps.py Modified: django/branches/soc2010/app-loading/django/core/apps.py django/branches/soc2010/app-loading/tests/appcachetests/model_app/__init__.py django/branches/soc2010/app-loading/tests/appcachetests/nomodel_app/__init__.py django/branches/soc2010/app-loading/tests/appcachetests/runtests.py django/branches/soc2010/app-loading/tests/appcachetests/same_label/nomodel_app/__init__.py Log: [soc2010/app-loading] update tests Modified: django/branches/soc2010/app-loading/django/core/apps.py =================================================================== --- django/branches/soc2010/app-loading/django/core/apps.py 2010-09-12 20:52:49 UTC (rev 13809) +++ django/branches/soc2010/app-loading/django/core/apps.py 2010-09-12 21:16:09 UTC (rev 13810) @@ -46,11 +46,6 @@ # List of App instances app_instances = [], - # Normalized list of INSTALLED_APPS - # This stores the module name of settings.INSTALLED_APPS - # e.g. 'django.contrib.auth' for 'django.contrib.auth.AuthApp' - installed_apps = [], - # Mapping of app_labels to a dictionary of model names to model code. unbound_models = {}, @@ -142,14 +137,11 @@ app_instance.module = app_module app_instance.path = app_name self.app_instances.append(app_instance) - self.installed_apps.append(app_name) - # Check if the app instance specifies a path to models + # Check if the app instance specifies a path to a models module # if not, we use the models.py file from the package dir - try: - models_path = app_instance.models_path - except AttributeError: - models_path = '%s.models' % app_name + models_path = getattr(app_instance, 'models_path', + '%s.models' % app_name) try: models = import_module(models_path) @@ -178,9 +170,11 @@ return models def find_app(self, name): - "Returns the App instance that matches name" - if '.' in name: - name = name.rsplit('.', 1)[1] + """ + Returns the app instance that matches name + """ + #if '.' in name: + # name = name.rsplit('.', 1)[1] for app in self.app_instances: if app.name == name: return app Modified: django/branches/soc2010/app-loading/tests/appcachetests/model_app/__init__.py =================================================================== --- django/branches/soc2010/app-loading/tests/appcachetests/model_app/__init__.py 2010-09-12 20:52:49 UTC (rev 13809) +++ django/branches/soc2010/app-loading/tests/appcachetests/model_app/__init__.py 2010-09-12 21:16:09 UTC (rev 13810) @@ -1,12 +0,0 @@ -from django.core.apps import App - -class MyApp(App): - models_path = 'model_app.othermodels' - - def __repr__(self): - return '<MyApp: %s>' % self.name - -class MyOtherApp(MyApp): - def __init__(self, name): - super(MyOtherApp, self).__init__(name) - self.db_prefix = 'nomodel_app' Added: django/branches/soc2010/app-loading/tests/appcachetests/model_app/apps.py =================================================================== --- django/branches/soc2010/app-loading/tests/appcachetests/model_app/apps.py (rev 0) +++ django/branches/soc2010/app-loading/tests/appcachetests/model_app/apps.py 2010-09-12 21:16:09 UTC (rev 13810) @@ -0,0 +1,9 @@ +from django.core.apps import App + +class MyApp(App): + models_path = 'model_app.othermodels' + +class MyOtherApp(MyApp): + def __init__(self, name): + super(MyOtherApp, self).__init__(name) + self.db_prefix = 'nomodel_app' Modified: django/branches/soc2010/app-loading/tests/appcachetests/nomodel_app/__init__.py =================================================================== --- django/branches/soc2010/app-loading/tests/appcachetests/nomodel_app/__init__.py 2010-09-12 20:52:49 UTC (rev 13809) +++ django/branches/soc2010/app-loading/tests/appcachetests/nomodel_app/__init__.py 2010-09-12 21:16:09 UTC (rev 13810) @@ -1,6 +0,0 @@ -from django.core.apps import App - -class MyApp(App): - - def __repr__(self): - return '<MyApp: %s>' % self.name Added: django/branches/soc2010/app-loading/tests/appcachetests/nomodel_app/apps.py =================================================================== --- django/branches/soc2010/app-loading/tests/appcachetests/nomodel_app/apps.py (rev 0) +++ django/branches/soc2010/app-loading/tests/appcachetests/nomodel_app/apps.py 2010-09-12 21:16:09 UTC (rev 13810) @@ -0,0 +1,4 @@ +from django.core.apps import App + +class MyApp(App): + pass Modified: django/branches/soc2010/app-loading/tests/appcachetests/runtests.py =================================================================== --- django/branches/soc2010/app-loading/tests/appcachetests/runtests.py 2010-09-12 20:52:49 UTC (rev 13809) +++ django/branches/soc2010/app-loading/tests/appcachetests/runtests.py 2010-09-12 21:16:09 UTC (rev 13810) @@ -67,11 +67,15 @@ """ def test_not_initialized(self): - """Should return False if the AppCache hasn't been initialized""" + """ + Should return False if the AppCache hasn't been initialized + """ self.assertFalse(cache.app_cache_ready()) def test_load_app(self): - """Should return False after executing the load_app function""" + """ + Should return False after executing the load_app function + """ cache.load_app('nomodel_app') self.assertFalse(cache.app_cache_ready()) cache.load_app('nomodel_app', can_postpone=True) @@ -105,7 +109,8 @@ Test that an exception is raised if two app instances have the same db_prefix attribute """ - settings.APP_CLASSES = ('nomodel_app.MyApp', 'model_app.MyOtherApp',) + settings.APP_CLASSES = ('nomodel_app.apps.MyApp', + 'model_app.apps.MyOtherApp',) self.assertRaises(ImproperlyConfigured, cache.get_apps) class GetAppTests(AppCacheTestCase): @@ -254,43 +259,34 @@ self.assertEqual(app.models_module.__name__, 'model_app.models') self.assertEqual(rv.__name__, 'model_app.models') - def test_without_models(self): + def test_with_custom_models(self): """ - Test that an app instance is created when there are no models + Test that custom models are imported correctly, if the App specifies + an models_path attribute """ - rv = cache.load_app('nomodel_app') + from nomodel_app.apps import MyApp + rv = cache.load_app('model_app', can_postpone=False, app_class=MyApp) app = cache.app_instances[0] - self.assertEqual(len(cache.app_instances), 1) - self.assertEqual(app.name, 'nomodel_app') - self.assertEqual(rv, None) + self.assertEqual(app.models_module.__name__, 'model_app.models') + self.assertTrue(isinstance(app, MyApp)) + self.assertEqual(rv.__name__, 'model_app.models') - def test_custom_app(self): + def test_without_models(self): """ - Test that a custom app instance is created if the function - gets passed a custom app class + Test that an app instance is created even when there are + no models provided """ - from nomodel_app import MyApp - rv = cache.load_app('nomodel_app', False, MyApp) + rv = cache.load_app('nomodel_app') app = cache.app_instances[0] self.assertEqual(len(cache.app_instances), 1) self.assertEqual(app.name, 'nomodel_app') - self.assertTrue(isinstance(app, MyApp)) self.assertEqual(rv, None) - def test_custom_models_path(self): + def test_loading_the_same_app_twice(self): """ - Test that custom models are imported correctly + Test that loading the same app twice results in only one app instance + being created """ - from nomodel_app import MyApp - rv = cache.load_app('model_app', False, MyApp) - app = cache.app_instances[0] - self.assertEqual(app.models_module.__name__, 'model_app.models') - self.assertEqual(rv.__name__, 'model_app.models') - - def test_twice(self): - """ - Test that loading an app twice results in only one app instance - """ rv = cache.load_app('model_app') rv2 = cache.load_app('model_app') self.assertEqual(len(cache.app_instances), 1) @@ -304,16 +300,6 @@ """ self.assertRaises(ImportError, cache.load_app, 'garageland') - def test_installed_apps(self): - """ - Test that the installed_apps attribute is populated correctly - """ - settings.APP_CLASSES = ('nomodel_app.MyApp',) - settings.INSTALLED_APPS = ('model_app',) - # populate cache - cache.get_app_errors() - self.assertEqual(cache.installed_apps, ['nomodel_app', 'model_app',]) - class RegisterModelsTests(AppCacheTestCase): """Tests for the register_models function""" @@ -349,6 +335,32 @@ self.assertFalse(cache.app_cache_ready()) self.assertEquals(cache.unbound_models['model_app']['person'], Person) +class FindAppTests(AppCacheTestCase): + """Tests for the find_app function""" + + def test_seeded(self): + """ + Test that the correct app is returned when the cache is seeded + """ + from django.core.apps import App + settings.INSTALLED_APPS = ('model_app',) + cache.get_app_errors() + self.assertTrue(cache.app_cache_ready()) + rv = cache.find_app('model_app') + self.assertEquals(rv.name, 'model_app') + self.assertTrue(isinstance(rv, App)) + + def test_unseeded(self): + """ + Test that the correct app is returned when the cache is unseeded + """ + from django.core.apps import App + cache.load_app('model_app') + self.assertFalse(cache.app_cache_ready()) + rv = cache.find_app('model_app') + self.assertEquals(rv.name, 'model_app') + self.assertTrue(isinstance(rv, App)) + if __name__ == '__main__': unittest.main() Modified: django/branches/soc2010/app-loading/tests/appcachetests/same_label/nomodel_app/__init__.py =================================================================== --- django/branches/soc2010/app-loading/tests/appcachetests/same_label/nomodel_app/__init__.py 2010-09-12 20:52:49 UTC (rev 13809) +++ django/branches/soc2010/app-loading/tests/appcachetests/same_label/nomodel_app/__init__.py 2010-09-12 21:16:09 UTC (rev 13810) @@ -1,6 +0,0 @@ -from django.core.apps import App - -class MyApp(App): - - def __repr__(self): - return '<MyApp: %s>' % self.name Added: django/branches/soc2010/app-loading/tests/appcachetests/same_label/nomodel_app/apps.py =================================================================== --- django/branches/soc2010/app-loading/tests/appcachetests/same_label/nomodel_app/apps.py (rev 0) +++ django/branches/soc2010/app-loading/tests/appcachetests/same_label/nomodel_app/apps.py 2010-09-12 21:16:09 UTC (rev 13810) @@ -0,0 +1,4 @@ +from django.core.apps import App + +class MyApp(App): + pass -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-upda...@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.