Commits

Mikhail Korobov committed e432958

Fix #9.

Comments (0)

Files changed (6)

 * Anonymous contributor
 * Ilya Shalyapin
 * Joe Crobak
-* Ruslan Popov
+* Ruslan Popov
+* bigkevmcd
 CHANGES
 =======
 
+(dev)
+-----
+
+- WebtestUserBackend is inserted after AuthenticationMiddleware, not to
+  the end of middleware list (thanks bigkevmcd);
+- don't list python 2.5 as supported because WebOb dropped 2.5 support;
+- test running using tox.
+
 1.4.4 (2012-02-08)
 ------------------
 

django_webtest/__init__.py

 
     def _setup_auth_middleware(self):
         auth_middleware = 'django_webtest.middleware.WebtestUserMiddleware'
-        settings.MIDDLEWARE_CLASSES += [auth_middleware]
+        index = settings.MIDDLEWARE_CLASSES.index(
+           'django.contrib.auth.middleware.AuthenticationMiddleware')
+        settings.MIDDLEWARE_CLASSES.insert(index+1, auth_middleware)
 
     def _setup_auth_backend(self):
         backend_name = 'django_webtest.backends.WebtestUserBackend'

django_webtest_tests/settings.py

     'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
+    'testapp_tests.middleware.UserMiddleware',
 )
 
 ROOT_URLCONF = 'urls'

django_webtest_tests/testapp_tests/middleware.py

+# -*- coding: utf-8 -*-
+from __future__ import absolute_import
+
+class UserMiddleware(object):
+    def process_request(self, request):
+        request.user.processed = True

django_webtest_tests/testapp_tests/tests.py

         auth_middleware = 'django_webtest.middleware.WebtestUserMiddleware'
         assert auth_middleware in settings.MIDDLEWARE_CLASSES
         assert 'django_webtest.backends.WebtestUserBackend' in settings.AUTHENTICATION_BACKENDS
+
+        dependency_index = settings.MIDDLEWARE_CLASSES.index(
+            'django.contrib.auth.middleware.AuthenticationMiddleware')
+
         self.assertEqual(
             settings.MIDDLEWARE_CLASSES.index(auth_middleware),
-            len(settings.MIDDLEWARE_CLASSES)-1
+            dependency_index +1,
         )
 
+    def test_custom_middleware(self):
+        response = self.app.get('/template/index.html', user=self.user)
+        user = response.context['user']
+        self.assertTrue(user.processed)
+
+
     def test_standard_auth(self):
         resp = self._login(self.user.username, '123').follow()
         user = resp.context['user']
         assert 'django_webtest.middleware.WebtestUserMiddleware' not in settings.MIDDLEWARE_CLASSES
         assert 'django_webtest.backends.WebtestUserBackend' not in settings.AUTHENTICATION_BACKENDS
 
+
 class TestSession(WebTest):
 
     def test_session_not_set(self):
         response = self.app.get('/')
         self.assertEqual(response.status_int, 200)
         self.assertEquals({}, self.app.session)
-    
+
     def test_session_not_empty(self):
         response = self.app.get(reverse('set_session'))
         self.assertEquals('foo', self.app.session['test'])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.