Merge lp:~elopio/u1-test-utils/improve_login_from_redirect_error_message into lp:u1-test-utils

Proposed by Leo Arias
Status: Merged
Approved by: Natalia Bidart
Approved revision: 65
Merged at revision: 63
Proposed branch: lp:~elopio/u1-test-utils/improve_login_from_redirect_error_message
Merge into: lp:u1-test-utils
Diff against target: 84 lines (+63/-0)
2 files modified
u1testutils/sso/selftests/unit/test_sst_helpers.py (+40/-0)
u1testutils/sso/sst/pages.py (+23/-0)
To merge this branch: bzr merge lp:~elopio/u1-test-utils/improve_login_from_redirect_error_message
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Review via email: mp+162650@code.launchpad.net

Commit message

Added a suggestion for the most common cause of LogIn errors.

To post a comment you must log in.
64. By Leo Arias

Added the test for the suggestion.

65. By Leo Arias

Improved the suggestion condition.

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'u1testutils/sso/selftests/unit/test_sst_helpers.py'
2--- u1testutils/sso/selftests/unit/test_sst_helpers.py 1970-01-01 00:00:00 +0000
3+++ u1testutils/sso/selftests/unit/test_sst_helpers.py 2013-05-06 21:32:27 +0000
4@@ -0,0 +1,40 @@
5+# Copyright 2013 Canonical Ltd.
6+#
7+# This program is free software: you can redistribute it and/or modify it
8+# under the terms of the GNU Lesser General Public License version 3, as
9+# published by the Free Software Foundation.
10+#
11+# This program is distributed in the hope that it will be useful, but
12+# WITHOUT ANY WARRANTY; without even the implied warranties of
13+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14+# PURPOSE. See the GNU Lesser General Public License for more details.
15+#
16+# You should have received a copy of the GNU General Public License along
17+# with this program. If not, see <http://www.gnu.org/licenses/
18+
19+import mock
20+
21+import u1testutils.logging
22+from u1testutils.sso.sst import pages
23+
24+
25+class LogInFromRedirectTestCase(u1testutils.logging.LogHandlerTestCase):
26+
27+ def test_site_without_rpconfig(self):
28+ with mock.patch.object(pages.LogInFromRedirect, 'assert_page_is_open'):
29+ page = pages.LogInFromRedirect()
30+
31+ with mock.patch('sst.actions.get_elements') as mock_elements:
32+ mock_elements.return_value = []
33+ headings2 = ['Log in to Ubuntu Single Sign On', 'Are you new?']
34+ for heading in headings2:
35+ mock_heading_element = mock.Mock()
36+ mock_heading_element.text = heading
37+ mock_elements.return_value.append(mock_heading_element)
38+ with self.assertRaises(AssertionError):
39+ page.assert_headings2()
40+ self.assertLogLevelContains(
41+ 'ERROR',
42+ 'Please check that you are logging in from a server with '
43+ 'an rpconfig on SSO. Otherwise, the headings in the page '
44+ 'will not be the ones we expect.')
45
46=== modified file 'u1testutils/sso/sst/pages.py'
47--- u1testutils/sso/sst/pages.py 2013-05-01 14:56:05 +0000
48+++ u1testutils/sso/sst/pages.py 2013-05-06 21:32:27 +0000
49@@ -21,6 +21,9 @@
50 from u1testutils.sst import log_action
51
52
53+logger = logging.getLogger('User test')
54+
55+
56 class LogIn(u1testutils.sst.Page):
57 """Log in page of the Ubuntu Single Sign On website.
58
59@@ -107,6 +110,26 @@
60 self._click_create_new_account()
61 return CreateAccountFromRedirect()
62
63+ def assert_headings2(self):
64+ """Assert the h2 elements of the page.
65+
66+ This method wraps the one from the parent class in order to log
67+ suggestions about the most common environment errors that make it fail.
68+
69+ """
70+ try:
71+ super(LogInFromRedirect, self).assert_headings2()
72+ except AssertionError:
73+ heading2_without_rpconfig = 'Log in to Ubuntu Single Sign On'
74+ if heading2_without_rpconfig in self._get_elements_text('h2'):
75+ suggestion = (
76+ 'Please check that you are logging in from a server with '
77+ 'an rpconfig on SSO. Otherwise, the headings in the page '
78+ 'will not be the ones we expect.'
79+ )
80+ logger.error(suggestion)
81+ raise
82+
83
84 class PageWithAnonymousSubheader(u1testutils.sst.Page):
85

Subscribers

People subscribed via source and target branches

to all changes: