Merge lp:~diegosarmentero/ubuntu-sso-client/not-validated-account into lp:ubuntu-sso-client

Proposed by Diego Sarmentero
Status: Merged
Approved by: Alejandro J. Cura
Approved revision: 823
Merged at revision: 821
Proposed branch: lp:~diegosarmentero/ubuntu-sso-client/not-validated-account
Merge into: lp:ubuntu-sso-client
Diff against target: 196 lines (+83/-39)
4 files modified
ubuntu_sso/main/__init__.py (+5/-5)
ubuntu_sso/main/tests/test_common.py (+68/-6)
ubuntu_sso/main/tests/test_linux.py (+0/-26)
ubuntu_sso/qt/controllers.py (+10/-2)
To merge this branch: bzr merge lp:~diegosarmentero/ubuntu-sso-client/not-validated-account
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) Approve
Manuel de la Peña (community) Approve
Review via email: mp+83055@code.launchpad.net

Commit message

Fixed: When logging in with an no-yet-validated account, there is no useful message (LP: #851885).

Description of the change

Fixed: When logging in with an no-yet-validated account, there is no useful message (LP: #851885).

To post a comment you must log in.
Revision history for this message
Alejandro J. Cura (alecu) wrote :

nNice branch!

Two small fixes needed:
Typo: "Test for SSOLoginRott" -> "Test for SSOLoginRoot"

CALL_SUCCESS is a constant, so the "if-else" in execute_fake_callback that checks the value of that constant does not make sense to me. (line 93-96 in the diff)
Perhaps it should be changed to just call result_cb, or made an instance attribute instead of a constant.

review: Needs Fixing
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

> nNice branch!
>
> Two small fixes needed:
> Typo: "Test for SSOLoginRott" -> "Test for SSOLoginRoot"
>
> CALL_SUCCESS is a constant, so the "if-else" in execute_fake_callback that
> checks the value of that constant does not make sense to me. (line 93-96 in
> the diff)
> Perhaps it should be changed to just call result_cb, or made an instance
> attribute instead of a constant.

Thanks for the review!

Fixed!

820. By Diego Sarmentero

Docstring fixed, unnecessary constant removed.

Revision history for this message
Manuel de la Peña (mandel) wrote :

Looks good.

review: Approve
Revision history for this message
Alejandro J. Cura (alecu) wrote :

I'm gettting this error, both with "run-tests" and "run-tests -qt":

    test_login_user_not_validated ... Exception in thread Thread-7:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 505, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/alecu/canonical/ubuntu-sso-client/review_not-validated-account/ubuntu_sso/main/linux.py", line 67, in _in_thread
    error_cb(app_name, except_to_errdict(e))
TypeError: errback() takes at most 2 arguments (3 given)

Traceback (most recent call last):
Failure: twisted.internet.defer.TimeoutError: <ubuntu_sso.main.tests.test_linux.SsoDbusTestCase testMethod=test_login_user_not_validated> (test_login_user_not_validated) still running at 2.0 secs
[ERROR]

review: Needs Fixing
821. By Diego Sarmentero

Removing redundant mocker test.

Revision history for this message
Alejandro J. Cura (alecu) wrote :

Removing the mocker based test that was replaced with the new test sounds like a good idea.

So, I think this is only stuff remaining:

== Python Lint Notices ==

ubuntu_sso/main/tests/test_common.py:
    49: [C0111, FakeProcessor] Missing docstring
    78: [W0201, SSOLoginRootTestCase.test_login_not_validated_email] Attribute 'fake_callback' defined outside __init__

review: Needs Fixing
822. By Diego Sarmentero

Fixing lint issues.

823. By Diego Sarmentero

merge

Revision history for this message
Alejandro J. Cura (alecu) wrote :

No more issues, thanks for working on this!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_sso/main/__init__.py'
2--- ubuntu_sso/main/__init__.py 2011-11-15 16:04:08 +0000
3+++ ubuntu_sso/main/__init__.py 2011-12-12 13:56:31 +0000
4@@ -1,9 +1,5 @@
5 # -*- coding: utf-8 -*-
6 #
7-# Author: Natalia Bidart <natalia.bidart@canonical.com>
8-# Author: Alejandro J. Cura <alecu@canonical.com>
9-# Author: Manuel de la Pena <manuel@canonical.com>
10-#
11 # Copyright 2011 Canonical Ltd.
12 #
13 # This program is free software: you can redistribute it and/or modify it
14@@ -110,7 +106,11 @@
15 error_cb(app_name,
16 except_to_errdict(failure.value)))
17 else:
18- not_validated_cb(app_name, email)
19+ error_dict = {
20+ 'errtype': 'UserNotValidated',
21+ 'message': email
22+ }
23+ not_validated_cb(app_name, error_dict)
24 thread_execute(f, app_name, success_cb, error_cb)
25
26 def validate_email(self, app_name, email, password, email_token,
27
28=== modified file 'ubuntu_sso/main/tests/test_common.py'
29--- ubuntu_sso/main/tests/test_common.py 2011-09-27 14:06:12 +0000
30+++ ubuntu_sso/main/tests/test_common.py 2011-12-12 13:56:31 +0000
31@@ -2,10 +2,6 @@
32 #
33 # test_main - tests for ubuntu_sso.main
34 #
35-# Author: Natalia Bidart <natalia.bidart@canonical.com>
36-# Author: Alejandro J. Cura <alecu@canonical.com>
37-# Author: Manuel de la Pena <manuel@canonical.com>
38-#
39 # Copyright 2009-2010 Canonical Ltd.
40 #
41 # This program is free software: you can redistribute it and/or modify it
42@@ -21,16 +17,81 @@
43 # with this program. If not, see <http://www.gnu.org/licenses/>.
44 """Tests share by diff platforms."""
45
46-from unittest import TestCase
47+from twisted.trial.unittest import TestCase
48+from twisted.internet.defer import inlineCallbacks
49
50 from mocker import MockerTestCase, MATCH
51
52+from ubuntu_sso import main
53 from ubuntu_sso.main import (
54 CredentialsManagement,
55 SSOLogin,
56+ SSOLoginRoot,
57 )
58
59
60+class FakeCallbacks(object):
61+
62+ """Fake callbacks class."""
63+
64+ def __init__(self):
65+ self.args = None
66+
67+ def result_cb(self, *args):
68+ """Fake result callbacks function."""
69+ self.args = args
70+
71+ def error_cb(self, *args):
72+ """Fake error callbacks function."""
73+ self.args = args
74+
75+
76+class FakeProcessor(object):
77+
78+ """Fake Processor."""
79+
80+ def __init__(self, *args, **kwargs):
81+ self.args = args
82+ self.kwargs = kwargs
83+ self.validated = True
84+
85+ def is_validated(self, credentials):
86+ """Fake is validated function for Account Processor."""
87+ return self.validated
88+
89+
90+def execute_fake_success_callback(function, app_name, success_cb, error_cb):
91+ """Fake execute callback function."""
92+ success_cb(app_name, object())
93+
94+
95+class SSOLoginRootTestCase(TestCase):
96+
97+ """Test for SSOLoginRoot."""
98+
99+ @inlineCallbacks
100+ def setUp(self):
101+ yield super(SSOLoginRootTestCase, self).setUp()
102+ self.root = SSOLoginRoot(FakeProcessor)
103+ self.patch(main, "thread_execute", execute_fake_success_callback)
104+
105+ def test_login_not_validated_email(self):
106+ """Test Login function with an email not validated."""
107+ fake_callback = FakeCallbacks()
108+ self.patch(self.root.processor, "validated", False)
109+ app_name = 'app_name'
110+ email = 'email@email.com'
111+ password = 'password'
112+ self.root.login(app_name, email, password,
113+ fake_callback.result_cb, fake_callback.error_cb,
114+ fake_callback.error_cb)
115+ self.assertEqual(fake_callback.args[0], 'app_name')
116+ self.assertEqual(fake_callback.args[1]['errtype'],
117+ 'UserNotValidated')
118+ self.assertEqual(fake_callback.args[1]['message'],
119+ email)
120+
121+
122 class SSOLoginMockedTestCase(MockerTestCase):
123 """Test that the call are relied correctly."""
124
125@@ -120,9 +181,10 @@
126 class CredentialsManagementMockedTestCase(MockerTestCase, TestCase):
127 """Test that the call are relied correctly."""
128
129+ @inlineCallbacks
130 def setUp(self):
131 """Setup tests."""
132- super(CredentialsManagementMockedTestCase, self).setUp()
133+ yield super(CredentialsManagementMockedTestCase, self).setUp()
134 self.root = self.mocker.mock()
135 self.cred = CredentialsManagement(None, None)
136 self.cred.root = self.root
137
138=== modified file 'ubuntu_sso/main/tests/test_linux.py'
139--- ubuntu_sso/main/tests/test_linux.py 2011-11-16 12:14:00 +0000
140+++ ubuntu_sso/main/tests/test_linux.py 2011-12-12 13:56:31 +0000
141@@ -238,32 +238,6 @@
142 client.login(APP_NAME, EMAIL, PASSWORD)
143 return d
144
145- def test_login_user_not_validated(self):
146- """Test that the login sends EmailNotValidated signal."""
147- d = defer.Deferred()
148- processor = self.create_mock_processor()
149- processor.login(EMAIL, PASSWORD, TOKEN_NAME)
150- self.mocker.result(TOKEN)
151- processor.is_validated(TOKEN)
152- self.mocker.result(False)
153- self.patch(ubuntu_sso.main.linux, "blocking", fake_ok_blocking)
154- self.mocker.replay()
155-
156- def verify(app_name, email):
157- """The actual test."""
158- self.assertEqual(app_name, APP_NAME)
159- self.assertEqual(email, EMAIL)
160- self.assertFalse(self.keyring_was_set, "Keyring should not be set")
161- d.callback("Ok")
162-
163- client = SSOLogin(self.mockbusname,
164- sso_login_processor_class=self.mockprocessorclass)
165- self.patch(client, "LoggedIn", d.errback)
166- self.patch(client, "LoginError", d.errback)
167- self.patch(client, "UserNotValidated", verify)
168- client.login(APP_NAME, EMAIL, PASSWORD)
169- return d
170-
171 def test_login_error_get_token_name(self):
172 """The login method fails as expected when get_token_name fails."""
173 d = defer.Deferred()
174
175=== modified file 'ubuntu_sso/qt/controllers.py'
176--- ubuntu_sso/qt/controllers.py 2011-11-11 20:34:57 +0000
177+++ ubuntu_sso/qt/controllers.py 2011-12-12 13:56:31 +0000
178@@ -233,8 +233,16 @@
179 # let the user know
180 logger.error('Got error when login %s, error: %s',
181 self.view.wizard().app_name, error)
182- self.message_box.critical(_build_general_error_message(error),
183- self.view)
184+ if isinstance(error, collections.Mapping) and \
185+ error.get('errtype', None) == 'UserNotValidated':
186+ self.view.setField('email_address', self.view.ui.email_edit.text())
187+ self.view.setField('password', self.view.ui.password_edit.text())
188+ app_name = self.view.wizard().app_name
189+ self.view.wizard().registrationIncomplete.emit(
190+ app_name, error['message'])
191+ else:
192+ self.message_box.critical(_build_general_error_message(error),
193+ self.view)
194
195 def on_logged_in(self, app_name, result):
196 """We managed to log in."""

Subscribers

People subscribed via source and target branches