Alex Marandon avatar Alex Marandon committed 409af9f

Test that middleware uses session locale

Comments (0)

Files changed (1)

localeurl/tests/tests.py

         self.assertEqual('/fr/test/', r2['Location'])
 
 
+    def test_check_session_enabled(self):
+        self.settings_manager.set(LOCALEURL_USE_SESSION=True)
+        reload(localeurl_settings)
+
+        r1 = self.request_factory.get('/test/')
+        r1.session = {'locale': 'fr'}
+        r2 = self.middleware.process_request(r1)
+        self.assertEqual(301, r2.status_code)
+        self.assertEqual('/fr/test/', r2['Location'])
+
+
 
 class DefaultPrefixMiddlewareTestCase(MiddlewareTestCase):
     def setUp(self):
         self.assertEqual('/en/test/?somevar=Mudan%E7as_recentes', r2['Location'])
 
 
+    def test_check_session_disabled(self):
+        self.settings_manager.set(LOCALEURL_USE_SESSION=False)
+        reload(localeurl_settings)
+
+        r1 = self.request_factory.get('/test/')
+        r1.session = {'locale': 'fr'}
+        r2 = self.middleware.process_request(r1)
+        self.assertEqual(301, r2.status_code)
+        self.assertEqual('/en/test/', r2['Location'])
+
+
+
+
 
 class NoDefaultPrefixMiddlewareTestCase(MiddlewareTestCase):
     def setUp(self):
         self.assertEqual('fr', r1.LANGUAGE_CODE)
         self.assertEqual('/test/foo/', r1.path_info)
 
+    def test_check_session_disabled(self):
+        self.settings_manager.set(LOCALEURL_USE_SESSION=False)
+        reload(localeurl_settings)
+
+        r1 = self.request_factory.get('/test/')
+        r1.session = {'locale': 'fr'}
+        r2 = self.middleware.process_request(r1)
+        self.assertEqual(None, r2)
+
 
 
 class TagsTestCase(LocaleurlTestCase):
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.