@@ -67,11 +67,15 @@ class AppCacheReadyTests(AppCacheTestCase):
67
67
"""
68
68
69
69
def test_not_initialized (self ):
70
- """Should return False if the AppCache hasn't been initialized"""
70
+ """
71
+ Should return False if the AppCache hasn't been initialized
72
+ """
71
73
self .assertFalse (cache .app_cache_ready ())
72
74
73
75
def test_load_app (self ):
74
- """Should return False after executing the load_app function"""
76
+ """
77
+ Should return False after executing the load_app function
78
+ """
75
79
cache .load_app ('nomodel_app' )
76
80
self .assertFalse (cache .app_cache_ready ())
77
81
cache .load_app ('nomodel_app' , can_postpone = True )
@@ -105,7 +109,8 @@ def test_db_prefix_exception(self):
105
109
Test that an exception is raised if two app instances
106
110
have the same db_prefix attribute
107
111
"""
108
- settings .APP_CLASSES = ('nomodel_app.MyApp' , 'model_app.MyOtherApp' ,)
112
+ settings .APP_CLASSES = ('nomodel_app.apps.MyApp' ,
113
+ 'model_app.apps.MyOtherApp' ,)
109
114
self .assertRaises (ImproperlyConfigured , cache .get_apps )
110
115
111
116
class GetAppTests (AppCacheTestCase ):
@@ -254,42 +259,33 @@ def test_with_models(self):
254
259
self .assertEqual (app .models_module .__name__ , 'model_app.models' )
255
260
self .assertEqual (rv .__name__ , 'model_app.models' )
256
261
257
- def test_without_models (self ):
262
+ def test_with_custom_models (self ):
258
263
"""
259
- Test that an app instance is created when there are no models
264
+ Test that custom models are imported correctly, if the App specifies
265
+ an models_path attribute
260
266
"""
261
- rv = cache .load_app ('nomodel_app' )
267
+ from nomodel_app .apps import MyApp
268
+ rv = cache .load_app ('model_app' , can_postpone = False , app_class = MyApp )
262
269
app = cache .app_instances [0 ]
263
- self .assertEqual (len ( cache . app_instances ), 1 )
264
- self .assertEqual ( app . name , 'nomodel_app' )
265
- self .assertEqual (rv , None )
270
+ self .assertEqual (app . models_module . __name__ , 'model_app.models' )
271
+ self .assertTrue ( isinstance ( app , MyApp ) )
272
+ self .assertEqual (rv . __name__ , 'model_app.models' )
266
273
267
- def test_custom_app (self ):
274
+ def test_without_models (self ):
268
275
"""
269
- Test that a custom app instance is created if the function
270
- gets passed a custom app class
276
+ Test that an app instance is created even when there are
277
+ no models provided
271
278
"""
272
- from nomodel_app import MyApp
273
- rv = cache .load_app ('nomodel_app' , False , MyApp )
279
+ rv = cache .load_app ('nomodel_app' )
274
280
app = cache .app_instances [0 ]
275
281
self .assertEqual (len (cache .app_instances ), 1 )
276
282
self .assertEqual (app .name , 'nomodel_app' )
277
- self .assertTrue (isinstance (app , MyApp ))
278
283
self .assertEqual (rv , None )
279
284
280
- def test_custom_models_path (self ):
281
- """
282
- Test that custom models are imported correctly
283
- """
284
- from nomodel_app import MyApp
285
- rv = cache .load_app ('model_app' , False , MyApp )
286
- app = cache .app_instances [0 ]
287
- self .assertEqual (app .models_module .__name__ , 'model_app.models' )
288
- self .assertEqual (rv .__name__ , 'model_app.models' )
289
-
290
- def test_twice (self ):
285
+ def test_loading_the_same_app_twice (self ):
291
286
"""
292
- Test that loading an app twice results in only one app instance
287
+ Test that loading the same app twice results in only one app instance
288
+ being created
293
289
"""
294
290
rv = cache .load_app ('model_app' )
295
291
rv2 = cache .load_app ('model_app' )
@@ -304,16 +300,6 @@ def test_importerror(self):
304
300
"""
305
301
self .assertRaises (ImportError , cache .load_app , 'garageland' )
306
302
307
- def test_installed_apps (self ):
308
- """
309
- Test that the installed_apps attribute is populated correctly
310
- """
311
- settings .APP_CLASSES = ('nomodel_app.MyApp' ,)
312
- settings .INSTALLED_APPS = ('model_app' ,)
313
- # populate cache
314
- cache .get_app_errors ()
315
- self .assertEqual (cache .installed_apps , ['nomodel_app' , 'model_app' ,])
316
-
317
303
class RegisterModelsTests (AppCacheTestCase ):
318
304
"""Tests for the register_models function"""
319
305
@@ -349,6 +335,32 @@ def test_unseeded_cache(self):
349
335
self .assertFalse (cache .app_cache_ready ())
350
336
self .assertEquals (cache .unbound_models ['model_app' ]['person' ], Person )
351
337
338
+ class FindAppTests (AppCacheTestCase ):
339
+ """Tests for the find_app function"""
340
+
341
+ def test_seeded (self ):
342
+ """
343
+ Test that the correct app is returned when the cache is seeded
344
+ """
345
+ from django .core .apps import App
346
+ settings .INSTALLED_APPS = ('model_app' ,)
347
+ cache .get_app_errors ()
348
+ self .assertTrue (cache .app_cache_ready ())
349
+ rv = cache .find_app ('model_app' )
350
+ self .assertEquals (rv .name , 'model_app' )
351
+ self .assertTrue (isinstance (rv , App ))
352
+
353
+ def test_unseeded (self ):
354
+ """
355
+ Test that the correct app is returned when the cache is unseeded
356
+ """
357
+ from django .core .apps import App
358
+ cache .load_app ('model_app' )
359
+ self .assertFalse (cache .app_cache_ready ())
360
+ rv = cache .find_app ('model_app' )
361
+ self .assertEquals (rv .name , 'model_app' )
362
+ self .assertTrue (isinstance (rv , App ))
363
+
352
364
if __name__ == '__main__' :
353
365
unittest .main ()
354
366
0 commit comments