Merge lp:~deadlight/canonical-identity-provider/form-error-states into lp:canonical-identity-provider/release

Proposed by Karl Williams
Status: Merged
Approved by: Maximiliano Bertacchini
Approved revision: no longer in the source branch.
Merged at revision: 1717
Proposed branch: lp:~deadlight/canonical-identity-provider/form-error-states
Merge into: lp:canonical-identity-provider/release
Diff against target: 207 lines (+37/-27)
9 files modified
src/identityprovider/fields.py (+6/-1)
src/identityprovider/forms.py (+6/-2)
src/identityprovider/tests/sso_server/test_home_page.py (+3/-1)
src/identityprovider/tests/sso_server/test_standalone_login.py (+2/-1)
src/webui/templates/account/edit.html (+1/-1)
src/webui/templates/registration/_create_account_form.html (+1/-1)
src/webui/templates/registration/_title.html (+2/-2)
src/webui/templates/vanilla/base.html (+9/-11)
src/webui/templates/vanilla/widgets/passwords.html (+7/-7)
To merge this branch: bzr merge lp:~deadlight/canonical-identity-provider/form-error-states
Reviewer Review Type Date Requested Status
Anthony Dillon (community) Approve
Maximiliano Bertacchini Approve
Review via email: mp+378530@code.launchpad.net

Commit message

Fixed the rendering of error states for the password fields (included modifying the password field generation code to take an optional HTML class parameter)

Changed the base template to move global error messages into the main strip, reducing vertical spacing.

Description of the change

Fixed the rendering of error states for the password fields (included modifying the password field generation code to take an optional HTML class parameter)

Changed the base template to move global error messages into the main strip, reducing vertical spacing.

QA:
Try and create an account but input non-matching passwords then also try a password which is too short

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

Nice! Looks good to me. But there are 3 related failing tests, which fortunately look trivial to fix :)

Also, it'd be great if passwords field errors in "My account" had the same rendering style. Have you considered that?

Thanks!

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

======================================================================
FAIL: identityprovider.tests.sso_server.test_standalone_login.StandaloneLoginTestCase.test_login
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/src/canonical-identity-provider/form-error-states/src/identityprovider/tests/sso_server/test_standalone_login.py", line 22, in test_login
    '<span class="trusted-rp-name">Ubuntu One</span> '
  File "/src/canonical-identity-provider/form-error-states/env/local/lib/python2.7/site-packages/django/test/testcases.py", line 393, in assertContains
    self.assertTrue(real_count != 0, msg_prefix + "Couldn't find %s in response" % text_repr)
  File "/usr/lib/python2.7/unittest/case.py", line 422, in assertTrue
    raise self.failureException(msg)
AssertionError: Couldn't find '<span class="trusted-rp-name">Ubuntu One</span> <span class="action-title">log in</span>' in response
======================================================================
FAIL: identityprovider.tests.sso_server.test_home_page.HomePageTestCase.test
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/src/canonical-identity-provider/form-error-states/src/identityprovider/tests/sso_server/test_home_page.py", line 22, in test
    '<span class="trusted-rp-name">Ubuntu One</span> '
  File "/src/canonical-identity-provider/form-error-states/env/local/lib/python2.7/site-packages/django/test/testcases.py", line 393, in assertContains
    self.assertTrue(real_count != 0, msg_prefix + "Couldn't find %s in response" % text_repr)
  File "/usr/lib/python2.7/unittest/case.py", line 422, in assertTrue
    raise self.failureException(msg)
AssertionError: Couldn't find '<span class="trusted-rp-name">Ubuntu One</span> <span class="action-title">log in</span>' in response
======================================================================
FAIL: identityprovider.tests.test_fields.PasswordFieldTestCase.test_widget_attrs
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/src/canonical-identity-provider/form-error-states/src/identityprovider/tests/test_fields.py", line 121, in test_widget_attrs
    self.assertEqual(self.field.widget.attrs, self.expected_attrs)
  File "/usr/lib/python2.7/unittest/case.py", line 513, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/usr/lib/python2.7/unittest/case.py", line 835, in assertDictEqual
    self.fail(self._formatMessage(msg, standardMsg))
  File "/usr/lib/python2.7/unittest/case.py", line 410, in fail
    raise self.failureException(msg)
AssertionError: {'autocomplete': 'off', 'placeholder': u'Password', 'class': 'disableAutoComplet [truncated]... != {'autocomplete': 'off', 'placeholder': u'Password', 'class': 'disableAutoComplet [truncated]...
  {'autocomplete': 'off',
- 'class': 'disableAutoComplete textType ',
? -

+ 'class': 'disableAutoComplete textType',
   'placeholder': u'Password'}

Ran 3272 tests in 80.238s
FAILED (failures=3)

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

This diff fixes the test failures.

https://pastebin.canonical.com/p/HfSGQ2z954/

It does not make the password field errors in My Account have consistent errors as suggested by Maxi.

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

Password fields with errors now look awesome :) Thanks!

Note there's still one test failure: identityprovider.tests.sso_server.test_home_page.HomePageTestCase.test.

+1 provided that tests pass (and an optional nitpick).

review: Approve
Revision history for this message
Karl Williams (deadlight) wrote :

Oh yes, my mistake. I was just running the webUI suite of tests.

Revision history for this message
Otto Co-Pilot (otto-copilot) wrote :
Revision history for this message
Otto Co-Pilot (otto-copilot) wrote :
Revision history for this message
Daniel Manrique (roadmr) wrote :

oh haha :)

src/identityprovider/forms.py:149:80: E501 line too long (94 > 79 characters)

Revision history for this message
Anthony Dillon (ya-bo-ng) wrote :

LGTM sorry I was late +1

review: Approve
Revision history for this message
Karl Williams (deadlight) wrote :

> oh haha :)
>
> src/identityprovider/forms.py:149:80: E501 line too long (94 > 79 characters)

... arrgh! Fixed.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/identityprovider/fields.py'
2--- src/identityprovider/fields.py 2018-02-09 20:56:16 +0000
3+++ src/identityprovider/fields.py 2020-02-07 08:47:17 +0000
4@@ -90,8 +90,13 @@
5
6 def __init__(self, *args, **kwargs):
7 placeholder = kwargs.pop('placeholder', default_password_placeholder)
8+ html_class = "disableAutoComplete textType"
9+ extra_class = kwargs.pop('extra_class', '')
10+ if extra_class:
11+ html_class += ' ' + extra_class
12+
13 attrs = {
14- 'class': 'disableAutoComplete textType',
15+ 'class': html_class,
16 'autocomplete': 'off',
17 'placeholder': placeholder,
18 }
19
20=== modified file 'src/identityprovider/forms.py'
21--- src/identityprovider/forms.py 2019-10-22 14:18:28 +0000
22+++ src/identityprovider/forms.py 2020-02-07 08:47:17 +0000
23@@ -146,14 +146,18 @@
24
25 validate_policy = get_password_validator(self.account)
26 if self.require_confirmation:
27- self.fields['oldpassword'] = PasswordField()
28+ self.fields['oldpassword'] = PasswordField(
29+ extra_class="p-form-validation__input")
30 self.fields['password'] = PasswordField(
31 placeholder=validate_policy.PASSWORD_POLICY_HELP_TEXT,
32 help_text=validate_policy.PASSWORD_POLICY_HELP_TEXT,
33 validators=[validate_policy],
34+ extra_class="p-form-validation__input"
35 )
36 self.fields['passwordconfirm'] = PasswordField(
37- placeholder=_('Retype password'))
38+ placeholder=_('Retype password'),
39+ extra_class="p-form-validation__input",
40+ )
41
42 def clean_oldpassword(self):
43 old_password = self.cleaned_data.get('oldpassword')
44
45=== modified file 'src/identityprovider/tests/sso_server/test_home_page.py'
46--- src/identityprovider/tests/sso_server/test_home_page.py 2018-12-12 16:18:18 +0000
47+++ src/identityprovider/tests/sso_server/test_home_page.py 2020-02-07 08:47:17 +0000
48@@ -1,3 +1,5 @@
49+# encoding: utf-8
50+
51 from identityprovider.fields import FIELD_REQUIRED
52 from identityprovider.models.openidmodels import OpenIDRPSummary
53 from identityprovider.tests.helpers import FunctionalTestCase
54@@ -19,7 +21,7 @@
55 response = self.client.get(self.base_url)
56 self.assertContains(
57 response,
58- '<span class="trusted-rp-name">Ubuntu One</span> '
59+ '<span class="trusted-rp-name">Ubuntu One</span> › '
60 '<span class="action-title">log in</span>')
61
62 # However, if the user is logged in, they are presented with some
63
64=== modified file 'src/identityprovider/tests/sso_server/test_standalone_login.py'
65--- src/identityprovider/tests/sso_server/test_standalone_login.py 2019-12-19 20:48:07 +0000
66+++ src/identityprovider/tests/sso_server/test_standalone_login.py 2020-02-07 08:47:17 +0000
67@@ -1,3 +1,4 @@
68+# encoding: utf-8
69 from django.urls import reverse
70
71 from identityprovider.models.account import Account
72@@ -19,7 +20,7 @@
73 response = self.client.get(self.base_url)
74 self.assertContains(
75 response,
76- '<span class="trusted-rp-name">Ubuntu One</span> '
77+ '<span class="trusted-rp-name">Ubuntu One</span> › '
78 '<span class="action-title">log in</span>')
79 self.assertIn("user_intention_create", response.content)
80
81
82=== modified file 'src/webui/templates/account/edit.html'
83--- src/webui/templates/account/edit.html 2020-01-22 12:52:26 +0000
84+++ src/webui/templates/account/edit.html 2020-02-07 08:47:17 +0000
85@@ -98,7 +98,7 @@
86
87 <div class="row">
88 <div class="col-8">
89- {% include "widgets/passwords.html" with edit_account_labels=1 fields=form %}
90+ {% include "vanilla/widgets/passwords.html" with edit_account_labels=1 fields=form %}
91 </div>
92 </div>
93 {% endif %}
94
95=== modified file 'src/webui/templates/registration/_create_account_form.html'
96--- src/webui/templates/registration/_create_account_form.html 2019-12-03 11:05:18 +0000
97+++ src/webui/templates/registration/_create_account_form.html 2020-02-07 08:47:17 +0000
98@@ -41,7 +41,7 @@
99 {{ create_form.username }}
100 </div>
101 {% endif %}
102- {% include "widgets/passwords.html" with fields=create_form %}
103+ {% include "vanilla/widgets/passwords.html" with fields=create_form %}
104
105 <div class="p-form-validation{% if create_form.accept_tos.errors %} is-error{% endif %} accept-tos-input">
106 {% if create_form.accept_tos.errors %}
107
108=== modified file 'src/webui/templates/registration/_title.html'
109--- src/webui/templates/registration/_title.html 2019-12-03 11:05:18 +0000
110+++ src/webui/templates/registration/_title.html 2020-02-07 08:47:17 +0000
111@@ -8,7 +8,7 @@
112 {% endif %}
113 <span class="action-title">{% blocktrans %}log in with Ubuntu One{% endblocktrans %}
114 {% else %}
115- <span class="trusted-rp-name">Ubuntu One</span> <span class="action-title">{% trans "log in" %}</span>
116+ <span class="trusted-rp-name">Ubuntu One</span> › <span class="action-title">{% trans "log in" %}</span>
117 {% endif %}
118 </h2>
119 <h2 class="p-heading--four title create-title u-no-margin--top">
120@@ -20,7 +20,7 @@
121 <span class="action-title">{% blocktrans %}create Ubuntu One account{% endblocktrans %}</span>
122 {% endif %}
123 {% else %}
124- <span class="trusted-rp-name">Ubuntu One</span> <span class="action-title">{% trans "create account" %}</span>
125+ <span class="trusted-rp-name">Ubuntu One</span> › <span class="action-title">{% trans "create account" %}</span>
126 {% endif %}
127 </h2>
128 <hr>
129
130=== modified file 'src/webui/templates/vanilla/base.html'
131--- src/webui/templates/vanilla/base.html 2020-01-22 12:52:26 +0000
132+++ src/webui/templates/vanilla/base.html 2020-02-07 08:47:17 +0000
133@@ -71,19 +71,17 @@
134 {% endblock %}
135 {% block messages %}
136 {% if messages %}
137- <section class="p-strip is-shallow">
138- {% for message in messages %}
139- <div class="row">
140- <div class="col-12">
141- <div class="p-notification">
142- <p class="p-notification__response">
143- {{ message }}
144- </p>
145- </div>
146+ {% for message in messages %}
147+ <div class="row">
148+ <div class="col-12">
149+ <div class="p-notification">
150+ <p class="p-notification__response">
151+ {{ message }}
152+ </p>
153 </div>
154 </div>
155- {% endfor %}
156- </section>
157+ </div>
158+ {% endfor %}
159 {% endif %}
160 {% endblock %}
161 {% block content %}{% endblock %}
162
163=== modified file 'src/webui/templates/vanilla/widgets/passwords.html'
164--- src/webui/templates/vanilla/widgets/passwords.html 2019-11-08 14:47:08 +0000
165+++ src/webui/templates/vanilla/widgets/passwords.html 2020-02-07 08:47:17 +0000
166@@ -3,7 +3,7 @@
167 <p>{% trans "To edit any details on this page, you must confirm your current password." %}</p>
168
169 {% if edit_account_labels %}
170-<div class="p-form-validation{% if fields.oldpassword.errors or fields.non_field_errors %} is-error{% endif %}">
171+<div class="p-form-validation{% if fields.oldpassword.errors %} is-error{% endif %}">
172 <label for="id_oldpassword">{% trans "Current password" %}</label>
173 {{ fields.oldpassword }}
174 {% if fields.oldpassword.errors %}
175@@ -15,9 +15,10 @@
176 {% endif %}
177 {% endif %}
178
179-{% if edit_account_labels %}
180 <div class="p-form-validation{% if fields.password.errors or fields.non_field_errors %} is-error{% endif %}">
181+ {% if edit_account_labels %}
182 <label for="id_password">{% trans "Choose password" %}</label>
183+ {% endif %}
184 {{ fields.password }}
185 {% if fields.password.errors %}
186 <p class="p-form-validation__message">
187@@ -25,16 +26,15 @@
188 </p>
189 {% endif %}
190 </div>
191-{% endif %}
192
193-{% if edit_account_labels %}
194 <div class="p-form-validation{% if fields.passwordconfirm.errors or fields.non_field_errors %} is-error{% endif %}">
195+ {% if edit_account_labels %}
196 <label for="id_passwordconfirm">{% trans "Re-type password" %}</label>
197+ {% endif %}
198 {{ fields.passwordconfirm }}
199- {% if fields.passwordconfirm.errors %}
200+ {% if fields.passwordconfirm.errors or fields.non_field_errors %}
201 <p class="p-form-validation__message">
202- <strong>Error:</strong> {{ fields.passwordconfirm.errors|first }}
203+ <strong>Error:</strong> {{ fields.passwordconfirm.errors|first }} {{ fields.non_field_errors|first }}
204 </p>
205 {% endif %}
206 </div>
207-{% endif %}