Merge lp:~elopio/reminders-app/test_with_account into lp:reminders-app
- test_with_account
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Nicholas Skaggs |
Approved revision: | 124 |
Merged at revision: | 135 |
Proposed branch: | lp:~elopio/reminders-app/test_with_account |
Merge into: | lp:reminders-app |
Diff against target: |
246 lines (+180/-6) 3 files modified
tests/autopilot/reminders/credentials.py (+145/-0) tests/autopilot/reminders/tests/__init__.py (+7/-4) tests/autopilot/reminders/tests/test_reminders.py (+28/-2) |
To merge this branch: | bzr merge lp:~elopio/reminders-app/test_with_account |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Phone Apps Jenkins Bot | continuous-integration | Approve | |
Nicholas Skaggs (community) | Approve | ||
Víctor R. Ruiz | Needs Fixing | ||
Richard Huddie | Pending | ||
Julia Palandri | Pending | ||
Allan LeSage | Pending | ||
Alberto Mardegan | Pending | ||
Review via email: mp+218688@code.launchpad.net |
This proposal supersedes a proposal from 2014-04-25.
Commit message
Added helpers to create an evernote account in autopilot tests.
Description of the change
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal | # |
Alberto Mardegan (mardy) wrote : Posted in a previous version of this proposal | # |
Looks good!
Nicholas Skaggs (nskaggs) wrote : Posted in a previous version of this proposal | # |
Successfully run on flo device!
Nicholas Skaggs (nskaggs) wrote : Posted in a previous version of this proposal | # |
My desktop seems to fail in a similar way as to jenkins?
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal | # |
FAILED: Continuous integration, rev:122
http://
Executed test runs:
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Nicholas Skaggs (nskaggs) wrote : Posted in a previous version of this proposal | # |
It helps if you install the plugin. Works great locally here now.
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
FAILED: Continuous integration, rev:122
http://
Executed test runs:
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal | # |
FAILED: Continuous integration, rev:122
http://
Executed test runs:
UNSTABLE: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Nicholas Skaggs (nskaggs) wrote : | # |
Running with the generated debs above on my local box works properly..
Víctor R. Ruiz (vrruiz) wrote : | # |
Add docstrings, please :)
Nicholas Skaggs (nskaggs) wrote : | # |
We should also setup the environment properly. I'll try and propose a branch if I finish up some things before you get to it :-)
https:/
Leo Arias (elopio) wrote : | # |
> Add docstrings, please :)
I have added some more.
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal | # |
FAILED: Continuous integration, rev:122
http://
Executed test runs:
SUCCESS: http://
deb: http://
UNSTABLE: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
FAILED: Continuous integration, rev:123
http://
Executed test runs:
SUCCESS: http://
deb: http://
UNSTABLE: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
FAILED: Continuous integration, rev:124
http://
Executed test runs:
SUCCESS: http://
deb: http://
UNSTABLE: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Nicholas Skaggs (nskaggs) wrote : | # |
Just confirming I'm happy with the merge, as soon as Jenkins is ;-)
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
FAILED: Continuous integration, rev:124
http://
Executed test runs:
SUCCESS: http://
deb: http://
UNSTABLE: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
FAILED: Continuous integration, rev:124
http://
Executed test runs:
SUCCESS: http://
deb: http://
FAILURE: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
PASSED: Continuous integration, rev:124
http://
Executed test runs:
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) : | # |
Preview Diff
1 | === added file 'tests/autopilot/reminders/credentials.py' |
2 | --- tests/autopilot/reminders/credentials.py 1970-01-01 00:00:00 +0000 |
3 | +++ tests/autopilot/reminders/credentials.py 2014-05-08 23:52:52 +0000 |
4 | @@ -0,0 +1,145 @@ |
5 | +# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
6 | +# |
7 | +# Copyright (C) 2014 Canonical Ltd. |
8 | +# |
9 | +# This program is free software; you can redistribute it and/or modify |
10 | +# it under the terms of the GNU General Public License version 3, as published |
11 | +# by the Free Software Foundation. |
12 | +# |
13 | +# This program is distributed in the hope that it will be useful, |
14 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | +# GNU General Public License for more details. |
17 | +# |
18 | +# You should have received a copy of the GNU General Public License |
19 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | + |
21 | + |
22 | +import threading |
23 | + |
24 | +from gi.repository import Accounts, GLib, Signon |
25 | + |
26 | + |
27 | +class CredentialsException(Exception): |
28 | + """Exception for credentials problems.""" |
29 | + |
30 | + |
31 | +class AccountManager(object): |
32 | + """Manager for online accounts.""" |
33 | + |
34 | + def __init__(self): |
35 | + self._manager = Accounts.Manager() |
36 | + |
37 | + def _start_main_loop(self): |
38 | + self.error = None |
39 | + self._main_loop = GLib.MainLoop() |
40 | + self._main_loop_thread = threading.Thread( |
41 | + target=self._main_loop.run) |
42 | + self._main_loop_thread.start() |
43 | + |
44 | + def _join_main_loop(self): |
45 | + self._main_loop_thread.join() |
46 | + if self.error is not None: |
47 | + raise CredentialsException(self.error.message) |
48 | + |
49 | + def add_evernote_account(self, user_name, password, oauth_token): |
50 | + """Add an evernote account. |
51 | + |
52 | + :param user_name: The user name of the account. |
53 | + :param password: The password of the account. |
54 | + :param oauth_token: The oauth token of the account. |
55 | + |
56 | + """ |
57 | + self._start_main_loop() |
58 | + |
59 | + account = self._create_account() |
60 | + |
61 | + info = self._get_identity_info(user_name, password) |
62 | + |
63 | + identity = Signon.Identity.new() |
64 | + identity.store_credentials_with_info( |
65 | + info, self._set_credentials_id_to_account, |
66 | + {'account': account, 'oauth_token': oauth_token}) |
67 | + |
68 | + self._join_main_loop() |
69 | + |
70 | + self._enable_evernote_service(account) |
71 | + |
72 | + return account |
73 | + |
74 | + def _create_account(self): |
75 | + account = self._manager.create_account('evernote') |
76 | + account.set_enabled(True) |
77 | + account.store(self._on_account_created, None) |
78 | + return account |
79 | + |
80 | + def _on_account_created(self, account, error, _): |
81 | + if error: |
82 | + self.error = error |
83 | + self._main_loop.quit() |
84 | + |
85 | + def _get_identity_info(self, user_name, password): |
86 | + info = Signon.IdentityInfo.new() |
87 | + info.set_username(user_name) |
88 | + info.set_caption(user_name) |
89 | + info.set_secret(password, True) |
90 | + return info |
91 | + |
92 | + def _set_credentials_id_to_account( |
93 | + self, identity, id_, error, account_dict): |
94 | + if error: |
95 | + self.error = error |
96 | + self._main_loop.quit() |
97 | + |
98 | + account = account_dict.get('account') |
99 | + oauth_token = account_dict.get('oauth_token') |
100 | + account.set_variant('CredentialsId', GLib.Variant('u', id_)) |
101 | + account.store(self._process_session, oauth_token) |
102 | + |
103 | + def _process_session(self, account, error, oauth_token): |
104 | + if error: |
105 | + self.error = error |
106 | + self._main_loop.quit() |
107 | + |
108 | + account_service = Accounts.AccountService.new(account, None) |
109 | + auth_data = account_service.get_auth_data() |
110 | + identity = auth_data.get_credentials_id() |
111 | + method = auth_data.get_method() |
112 | + mechanism = auth_data.get_mechanism() |
113 | + session_data = auth_data.get_parameters() |
114 | + session_data['ProvidedTokens'] = GLib.Variant('a{sv}', { |
115 | + 'TokenSecret': GLib.Variant('s', 'dummy'), |
116 | + 'AccessToken': GLib.Variant('s', oauth_token), |
117 | + }) |
118 | + session = Signon.AuthSession.new(identity, method) |
119 | + session.process( |
120 | + session_data, mechanism, self._on_login_processed, None) |
121 | + |
122 | + def _on_login_processed(self, session, reply, error, userdata): |
123 | + if error: |
124 | + self.error = error |
125 | + |
126 | + self._main_loop.quit() |
127 | + |
128 | + def _enable_evernote_service(self, account): |
129 | + service = self._manager.get_service('evernote') |
130 | + account.select_service(service) |
131 | + account.set_enabled(True) |
132 | + account.store(self._on_account_created, None) |
133 | + |
134 | + def delete_account(self, account): |
135 | + """Delete an account. |
136 | + |
137 | + :param account: The account to delete. |
138 | + |
139 | + """ |
140 | + self._start_main_loop() |
141 | + account.delete() |
142 | + account.store(self._on_account_deleted, None) |
143 | + self._join_main_loop() |
144 | + |
145 | + def _on_account_deleted(self, account, error, userdata): |
146 | + if error: |
147 | + self.error = error |
148 | + |
149 | + self._main_loop.quit() |
150 | |
151 | === modified file 'tests/autopilot/reminders/tests/__init__.py' |
152 | --- tests/autopilot/reminders/tests/__init__.py 2014-05-08 21:09:52 +0000 |
153 | +++ tests/autopilot/reminders/tests/__init__.py 2014-05-08 23:52:52 +0000 |
154 | @@ -50,6 +50,8 @@ |
155 | installed_location_binary = '/usr/bin/reminders' |
156 | installed_location_qml = '/usr/share/reminders/qml/reminders.qml' |
157 | |
158 | + home_dir = None |
159 | + |
160 | def get_launcher_and_type(self): |
161 | if os.path.exists(self.local_location_binary): |
162 | launcher = self.launch_test_local |
163 | @@ -63,8 +65,9 @@ |
164 | return launcher, test_type |
165 | |
166 | def setUp(self): |
167 | - launcher, self.test_type = self.get_launcher_and_type() |
168 | - self.home_dir = self._patch_home() |
169 | + launcher, test_type = self.get_launcher_and_type() |
170 | + if self.home_dir is None: |
171 | + self.home_dir = self._patch_home(test_type) |
172 | self.pointing_device = Pointer(self.input_device_class.create()) |
173 | super(RemindersAppTestCase, self).setUp() |
174 | |
175 | @@ -80,7 +83,7 @@ |
176 | os.path.expanduser(os.path.join('~', '.Xauthority')), |
177 | os.path.join(directory, '.Xauthority')) |
178 | |
179 | - def _patch_home(self): |
180 | + def _patch_home(self, test_type): |
181 | """ mock /home for testing purposes to preserve user data |
182 | """ |
183 | temp_dir_fixture = fixtures.TempDir() |
184 | @@ -95,7 +98,7 @@ |
185 | |
186 | #click requires using initctl env (upstart), but the desktop can set |
187 | #an environment variable instead |
188 | - if self.test_type == 'click': |
189 | + if test_type == 'click': |
190 | self.useFixture(toolkit_fixtures.InitctlEnvironmentVariable( |
191 | HOME=temp_dir)) |
192 | else: |
193 | |
194 | === modified file 'tests/autopilot/reminders/tests/test_reminders.py' |
195 | --- tests/autopilot/reminders/tests/test_reminders.py 2014-04-24 19:33:26 +0000 |
196 | +++ tests/autopilot/reminders/tests/test_reminders.py 2014-05-08 23:52:52 +0000 |
197 | @@ -23,9 +23,10 @@ |
198 | from autopilot import platform |
199 | from autopilot.matchers import Eventually |
200 | from testtools.matchers import Equals |
201 | +from testtools import ExpectedException |
202 | |
203 | import reminders |
204 | -from reminders import fixture_setup, tests |
205 | +from reminders import credentials, fixture_setup, tests |
206 | |
207 | |
208 | logger = logging.getLogger(__name__) |
209 | @@ -40,7 +41,7 @@ |
210 | def test_go_to_account_settings(self): |
211 | """Test that the Go to account settings button calls url-dispatcher.""" |
212 | if platform.model() == 'Desktop': |
213 | - self.skipTest("URL dispatcher doesn't work on the desktop.") |
214 | + self.skipTest("URL dispatcher doesn't work on the desktop.") |
215 | url_dispatcher = fixture_setup.FakeURLDispatcher() |
216 | self.useFixture(url_dispatcher) |
217 | |
218 | @@ -56,3 +57,28 @@ |
219 | self.assertThat( |
220 | get_last_dispatch_url_call_parameter, |
221 | Eventually(Equals('settings:///system/online-accounts'))) |
222 | + |
223 | + |
224 | +class RemindersTestCaseWithAccount(tests.RemindersAppTestCase): |
225 | + |
226 | + def setUp(self): |
227 | + # We need to change the home dir before adding the account, otherwise |
228 | + # the account will not be found when the app is opened. |
229 | + _, test_type = self.get_launcher_and_type() |
230 | + self.home_dir = self._patch_home(test_type) |
231 | + self.add_evernote_account() |
232 | + super(RemindersTestCaseWithAccount, self).setUp() |
233 | + |
234 | + def add_evernote_account(self): |
235 | + account_manager = credentials.AccountManager() |
236 | + oauth_token = ( |
237 | + 'S=s1:U=8e6bf:E=14d08e375ff:C=145b1324a03:P=1cd:A=en-devtoken:' |
238 | + 'V=2:H=79b946c32b4515ee52b387f7b68baa69') |
239 | + account = account_manager.add_evernote_account( |
240 | + 'dummy', 'dummy', oauth_token) |
241 | + self.addCleanup(account_manager.delete_account, account) |
242 | + |
243 | + def test_open_application_with_account(self): |
244 | + """Test that the No account dialog is not visible.""" |
245 | + with ExpectedException(reminders.RemindersAppException): |
246 | + self.app.main_view.no_account_dialog |
FAILED: Continuous integration, rev:122 91.189. 93.70:8080/ job/reminders- app-ci/ 298/ 91.189. 93.70:8080/ job/generic- mediumtests- trusty/ 2477 91.189. 93.70:8080/ job/reminders- app-saucy- amd64-ci/ 298 91.189. 93.70:8080/ job/reminders- app-trusty- amd64-ci/ 298
http://
Executed test runs:
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild: 91.189. 93.70:8080/ job/reminders- app-ci/ 298/rebuild
http://