Merge lp:~roadmr/canonical-identity-provider/fix-non-ascii-in-custom-tags into lp:canonical-identity-provider/release

Proposed by Daniel Manrique
Status: Merged
Approved by: Daniel Manrique
Approved revision: no longer in the source branch.
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: lp:~roadmr/canonical-identity-provider/fix-non-ascii-in-custom-tags
Merge into: lp:canonical-identity-provider/release
Diff against target: 39 lines (+20/-0)
2 files modified
src/webui/templatetags/faq.py (+2/-0)
src/webui/tests/test_templatetags.py (+18/-0)
To merge this branch: bzr merge lp:~roadmr/canonical-identity-provider/fix-non-ascii-in-custom-tags
Reviewer Review Type Date Requested Status
Maximiliano Bertacchini Approve
Review via email: mp+347532@code.launchpad.net

Commit message

Make faq_title tag non-ascii-aware and add tests for it

Description of the change

Make faq_title tag non-ascii-aware and add tests for it"

To post a comment you must log in.
Revision history for this message
Maximiliano Bertacchini (maxiberta) wrote :

I've just applied this on local trunk but still get a 500 error with `curl --head -H "Accept-Language: es" localhost:8000/+faq`. Am I missing something?

Revision history for this message
Maximiliano Bertacchini (maxiberta) wrote :

Indeed, I was missing `make start-db`, sorry! Anyways, I'm unable to reproduce the crash on trunk now :/

Revision history for this message
Daniel Manrique (roadmr) wrote :

Yay :)

I can imagine that running it from trunk is not properly using translations. Try:

$ curl --silent -H "Accept-Language: es" http://localhost:8000/+faq |grep FAQ
    <title>FAQ - Ubuntu One</title>
    We have a Two Factor Authentication specific FAQ at <a href="https://help.ubuntu.com/community/SSO/FAQs/2FA">help.ubuntu.com/community/SSO/FAQs/2FA</a>
        Ubuntu One FAQ

the title in particular should read "Preguntas frecuentes (FAQ) - Ubuntu One" if it were picking up the translations.

Revision history for this message
Daniel Manrique (roadmr) wrote :

Actually -

1- run "make compilemessages"
2- stop then restart the server (ctrl-c and then "make run")
3-

$ curl --silent -H "Accept-Language: es" http://localhost:8000/+faq |grep FAQ
 u&#39;Preguntas frecuentes (FAQ) - Ubuntu One&#39;,
          <td>LEAKED_PASSWORD_FAQ_URL</td>
          <td>TWOFACTOR_FAQ_URL</td>
          <td class="code"><pre>&#39;https://help.ubuntu.com/community/SSO/FAQs/2FA&#39;</pre></td>

so that is using the translated versions. Now, check the http code:

$ curl --silent -H "Accept-Language: es" http://localhost:8000/+faq --head
HTTP/1.1 500 Internal Server Error
Server: gunicorn/19.3.0
Date: Wed, 06 Jun 2018 18:05:00 GMT
Connection: close
Content-Length: 198536
x-xss-protection: 1; mode=block
Content-Language: es
x-content-type-options: nosniff
Vary: Accept-Language, Cookie
X-Frame-Options: SAMEORIGIN
Content-Type: text/html

Yay, it crashes. Now, apply the patch from this merge and try again:

 curl --silent -H "Accept-Language: es" http://localhost:8000/+faq --head
HTTP/1.1 200 OK

Revision history for this message
Maximiliano Bertacchini (maxiberta) wrote :

Thanks! I'm now able to reproduce and can confirm this fixes the issue :D

review: Approve
Revision history for this message
Otto Co-Pilot (otto-copilot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/webui/templatetags/faq.py'
2--- src/webui/templatetags/faq.py 2018-05-11 21:29:24 +0000
3+++ src/webui/templatetags/faq.py 2018-06-06 15:26:43 +0000
4@@ -1,3 +1,5 @@
5+from __future__ import unicode_literals
6+
7 from django import template
8 from django.utils.html import format_html
9 from django.utils.text import slugify
10
11=== modified file 'src/webui/tests/test_templatetags.py'
12--- src/webui/tests/test_templatetags.py 2017-02-26 01:17:04 +0000
13+++ src/webui/tests/test_templatetags.py 2018-06-06 15:26:43 +0000
14@@ -1,3 +1,4 @@
15+# -*- coding: UTF-8 -*-
16 # Copyright 2013-2017 Canonical Ltd. This software is licensed under the
17 # GNU Affero General Public License version 3 (see the file LICENSE).
18
19@@ -129,3 +130,20 @@
20 result = Template(
21 "{% load url_with_token %}" + case['in']).render(ctx)
22 self.assertEqual(case['out_token'] % {'token': token}, result)
23+
24+
25+class FaqTestCase(TestCase):
26+
27+ def test_simple(self):
28+ result = Template(
29+ "{% load faq %}"
30+ "{% faq_title 'foo bar' %}").render(Context())
31+
32+ self.assertIn(">foo bar<", result)
33+
34+ def test_non_ascii(self):
35+ result = Template(
36+ "{% load faq %}"
37+ "{% faq_title '¿Qué es Ubuntu One 单一登录?' %}").render(Context())
38+
39+ self.assertIn(">¿Qué es Ubuntu One 单一登录?<", result)