@@ -84,23 +84,31 @@ def test_load_app(self):
84
84
class GetAppsTests (AppCacheTestCase ):
85
85
"""Tests for the get_apps function"""
86
86
87
- def test_get_apps (self ):
88
- """Test that the correct models modules are returned"""
89
- settings .INSTALLED_APPS = ('django.contrib.sites' ,
90
- 'django.contrib.contenttypes' ,
91
- 'django.contrib.auth' ,
92
- 'django.contrib.flatpages' ,)
87
+ def test_app_classes (self ):
88
+ """
89
+ Test that the correct models modules are returned for apps installed
90
+ via the APP_CLASSES setting
91
+ """
92
+ settings .APP_CLASSES = ('model_app.apps.MyApp' ,)
93
+ apps = cache .get_apps ()
94
+ self .assertTrue (cache .app_cache_ready ())
95
+ self .assertEquals (apps [0 ].__name__ , 'model_app.othermodels' )
96
+
97
+ def test_installed_apps (self ):
98
+ """
99
+ Test that the correct models modules are returned for apps installed
100
+ via the INSTALLED_APPS setting
101
+ """
102
+ settings .INSTALLED_APPS = ('model_app' ,)
93
103
apps = cache .get_apps ()
94
- self .assertEqual (len (apps ), 4 )
95
- self .assertTrue (apps [0 ], 'django.contrib.auth.models' )
96
- self .assertTrue (apps [1 ], 'django.contrib.flatpages.models' )
97
- self .assertTrue (apps [2 ], 'django.contrib.sites.models' )
98
- self .assertTrue (apps [3 ], 'django.contrib.contenttypes.models' )
99
104
self .assertTrue (cache .app_cache_ready ())
105
+ self .assertEquals (apps [0 ].__name__ , 'model_app.models' )
100
106
101
107
def test_empty_models (self ):
102
- """Test that modules that don't contain models are not returned"""
103
- settings .INSTALLED_APPS = ('django.contrib.csrf' ,)
108
+ """
109
+ Test that modules that don't contain models are not returned
110
+ """
111
+ settings .INSTALLED_APPS = ('nomodel_app' ,)
104
112
self .assertEqual (cache .get_apps (), [])
105
113
self .assertTrue (cache .app_cache_ready ())
106
114
@@ -116,21 +124,31 @@ def test_db_prefix_exception(self):
116
124
class GetAppTests (AppCacheTestCase ):
117
125
"""Tests for the get_app function"""
118
126
119
- def test_get_app (self ):
120
- """Test that the correct module is returned"""
121
- settings .INSTALLED_APPS = ('django.contrib.contenttypes' ,
122
- 'django.contrib.auth' ,)
123
- module = cache .get_app ('auth' )
124
- self .assertTrue (module , 'django.contrib.auth.models' )
125
- self .assertTrue (cache .app_cache_ready ())
127
+ def test_app_classes (self ):
128
+ """
129
+ Test that the correct module is returned when the app was installed
130
+ via the APP_CLASSES setting
131
+ """
132
+ settings .APP_CLASSES = ('model_app.apps.MyApp' ,)
133
+ rv = cache .get_app ('model_app' )
134
+ self .assertEquals (rv .__name__ , 'model_app.othermodels' )
135
+
136
+ def test_installed_apps (self ):
137
+ """
138
+ Test that the correct module is returned when the app was installed
139
+ via the INSTALLED_APPS setting
140
+ """
141
+ settings .INSTALLED_APPS = ('model_app' ,)
142
+ rv = cache .get_app ('model_app' )
143
+ self .assertEquals (rv .__name__ , 'model_app.models' )
126
144
127
145
def test_not_found_exception (self ):
128
146
"""
129
147
Test that an ImproperlyConfigured exception is raised if an app
130
148
could not be found
131
149
"""
132
150
self .assertRaises (ImproperlyConfigured , cache .get_app ,
133
- 'django.contrib.auth ' )
151
+ 'notarealapp ' )
134
152
self .assertTrue (cache .app_cache_ready ())
135
153
136
154
def test_emptyOK (self ):
@@ -143,16 +161,6 @@ def test_emptyOK(self):
143
161
self .failUnless (module is None )
144
162
self .assertTrue (cache .app_cache_ready ())
145
163
146
- def test_load_app_modules (self ):
147
- """
148
- Test that only apps that are listed in the INSTALLED_APPS setting
149
- are searched (unlike the get_apps function, which also searches
150
- apps that are loaded via load_app)
151
- """
152
- cache .load_app ('django.contrib.sites' )
153
- self .assertRaises (ImproperlyConfigured , cache .get_app , 'sites' )
154
- self .assertTrue (cache .app_cache_ready ())
155
-
156
164
class GetAppErrorsTests (AppCacheTestCase ):
157
165
"""Tests for the get_app_errors function"""
158
166
0 commit comments