[pyramid] Fix login error message language 3.24
authorFlorent Cayré <florent.cayre@logilab.fr>
Mon, 14 Nov 2016 17:48:10 +0100
branch3.24
changeset 11816 6392f34fcdad
parent 11815 d63140bd4d6e
child 11817 48f6ebd33cb9
[pyramid] Fix login error message language Use http negotiation unless language is explicitly set for the site. Closes #16236485.
cubicweb/pyramid/login.py
cubicweb/pyramid/test/test_login.py
--- a/cubicweb/pyramid/login.py	Mon Nov 14 12:26:49 2016 +0100
+++ b/cubicweb/pyramid/login.py	Mon Nov 14 17:48:10 2016 +0100
@@ -47,6 +47,10 @@
             user = repo.authenticate_user(cnx, login, password=password)
             user_eid = user.eid
     except cubicweb.AuthenticationError:
+        if repo.vreg.config.get('language-mode') != '':
+            lang = request.cw_request.negotiated_language()
+            if lang is not None:
+                request.cw_request.set_language(lang)
         request.cw_request.set_message(request.cw_request._(
             "Authentication failed. Please check your credentials."))
         request.cw_request.post = dict(request.params)
--- a/cubicweb/pyramid/test/test_login.py	Mon Nov 14 12:26:49 2016 +0100
+++ b/cubicweb/pyramid/test/test_login.py	Mon Nov 14 17:48:10 2016 +0100
@@ -1,3 +1,6 @@
+from os.path import join
+from shutil import rmtree
+
 from cubicweb.pyramid.test import PyramidCWTest
 
 
@@ -41,9 +44,17 @@
         self.assertIsNotNone(cookies['pauth_tkt'].expires)
 
     def test_login_bad_password(self):
-        res = self.webapp.post('/login', {
-            '__login': self.admlogin, '__password': 'empty'}, status=403)
-        self.assertIn('Authentication failed', res.text)
+        self.config.i18ncompile(['en', 'fr'])
+        try:
+            self.config._gettext_init()
+            res = self.webapp.post(
+                '/login',
+                {'__login': self.admlogin, '__password': 'empty'},
+                headers={'Accept-Language': 'fr'},
+                status=403)
+        finally:
+            rmtree(join(self.config.apphome, 'i18n'))
+        self.assertIn(u"\xc9chec de l'authentification", res.text)
 
 
 if __name__ == '__main__':