Merge lp:~elopio/reminders-app/test_with_account into lp:reminders-app

Proposed by Leo Arias
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
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.

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Alberto Mardegan (mardy) wrote : Posted in a previous version of this proposal

Looks good!

review: Approve
Revision history for this message
Nicholas Skaggs (nskaggs) wrote : Posted in a previous version of this proposal

Successfully run on flo device!

Revision history for this message
Nicholas Skaggs (nskaggs) wrote : Posted in a previous version of this proposal

My desktop seems to fail in a similar way as to jenkins?

http://paste.ubuntu.com/7410848/

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Nicholas Skaggs (nskaggs) wrote : Posted in a previous version of this proposal

It helps if you install the plugin. Works great locally here now.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

Running with the generated debs above on my local box works properly..

Revision history for this message
Víctor R. Ruiz (vrruiz) wrote :

Add docstrings, please :)

review: Needs Fixing
Revision history for this message
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://bugs.launchpad.net/ubuntu-filemanager-app/+bug/1316746

review: Needs Fixing
123. By Leo Arias

Refactor and add docstrings.

Revision history for this message
Leo Arias (elopio) wrote :

> Add docstrings, please :)

I have added some more.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
124. By Leo Arias

Merged with trunk. Moved the home patch before creating the account.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

Just confirming I'm happy with the merge, as soon as Jenkins is ;-)

review: Approve
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'tests/autopilot/reminders/credentials.py'
--- tests/autopilot/reminders/credentials.py 1970-01-01 00:00:00 +0000
+++ tests/autopilot/reminders/credentials.py 2014-05-08 23:52:52 +0000
@@ -0,0 +1,145 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2#
3# Copyright (C) 2014 Canonical Ltd.
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 3, as published
7# by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17
18import threading
19
20from gi.repository import Accounts, GLib, Signon
21
22
23class CredentialsException(Exception):
24 """Exception for credentials problems."""
25
26
27class AccountManager(object):
28 """Manager for online accounts."""
29
30 def __init__(self):
31 self._manager = Accounts.Manager()
32
33 def _start_main_loop(self):
34 self.error = None
35 self._main_loop = GLib.MainLoop()
36 self._main_loop_thread = threading.Thread(
37 target=self._main_loop.run)
38 self._main_loop_thread.start()
39
40 def _join_main_loop(self):
41 self._main_loop_thread.join()
42 if self.error is not None:
43 raise CredentialsException(self.error.message)
44
45 def add_evernote_account(self, user_name, password, oauth_token):
46 """Add an evernote account.
47
48 :param user_name: The user name of the account.
49 :param password: The password of the account.
50 :param oauth_token: The oauth token of the account.
51
52 """
53 self._start_main_loop()
54
55 account = self._create_account()
56
57 info = self._get_identity_info(user_name, password)
58
59 identity = Signon.Identity.new()
60 identity.store_credentials_with_info(
61 info, self._set_credentials_id_to_account,
62 {'account': account, 'oauth_token': oauth_token})
63
64 self._join_main_loop()
65
66 self._enable_evernote_service(account)
67
68 return account
69
70 def _create_account(self):
71 account = self._manager.create_account('evernote')
72 account.set_enabled(True)
73 account.store(self._on_account_created, None)
74 return account
75
76 def _on_account_created(self, account, error, _):
77 if error:
78 self.error = error
79 self._main_loop.quit()
80
81 def _get_identity_info(self, user_name, password):
82 info = Signon.IdentityInfo.new()
83 info.set_username(user_name)
84 info.set_caption(user_name)
85 info.set_secret(password, True)
86 return info
87
88 def _set_credentials_id_to_account(
89 self, identity, id_, error, account_dict):
90 if error:
91 self.error = error
92 self._main_loop.quit()
93
94 account = account_dict.get('account')
95 oauth_token = account_dict.get('oauth_token')
96 account.set_variant('CredentialsId', GLib.Variant('u', id_))
97 account.store(self._process_session, oauth_token)
98
99 def _process_session(self, account, error, oauth_token):
100 if error:
101 self.error = error
102 self._main_loop.quit()
103
104 account_service = Accounts.AccountService.new(account, None)
105 auth_data = account_service.get_auth_data()
106 identity = auth_data.get_credentials_id()
107 method = auth_data.get_method()
108 mechanism = auth_data.get_mechanism()
109 session_data = auth_data.get_parameters()
110 session_data['ProvidedTokens'] = GLib.Variant('a{sv}', {
111 'TokenSecret': GLib.Variant('s', 'dummy'),
112 'AccessToken': GLib.Variant('s', oauth_token),
113 })
114 session = Signon.AuthSession.new(identity, method)
115 session.process(
116 session_data, mechanism, self._on_login_processed, None)
117
118 def _on_login_processed(self, session, reply, error, userdata):
119 if error:
120 self.error = error
121
122 self._main_loop.quit()
123
124 def _enable_evernote_service(self, account):
125 service = self._manager.get_service('evernote')
126 account.select_service(service)
127 account.set_enabled(True)
128 account.store(self._on_account_created, None)
129
130 def delete_account(self, account):
131 """Delete an account.
132
133 :param account: The account to delete.
134
135 """
136 self._start_main_loop()
137 account.delete()
138 account.store(self._on_account_deleted, None)
139 self._join_main_loop()
140
141 def _on_account_deleted(self, account, error, userdata):
142 if error:
143 self.error = error
144
145 self._main_loop.quit()
0146
=== modified file 'tests/autopilot/reminders/tests/__init__.py'
--- tests/autopilot/reminders/tests/__init__.py 2014-05-08 21:09:52 +0000
+++ tests/autopilot/reminders/tests/__init__.py 2014-05-08 23:52:52 +0000
@@ -50,6 +50,8 @@
50 installed_location_binary = '/usr/bin/reminders'50 installed_location_binary = '/usr/bin/reminders'
51 installed_location_qml = '/usr/share/reminders/qml/reminders.qml'51 installed_location_qml = '/usr/share/reminders/qml/reminders.qml'
5252
53 home_dir = None
54
53 def get_launcher_and_type(self):55 def get_launcher_and_type(self):
54 if os.path.exists(self.local_location_binary):56 if os.path.exists(self.local_location_binary):
55 launcher = self.launch_test_local57 launcher = self.launch_test_local
@@ -63,8 +65,9 @@
63 return launcher, test_type65 return launcher, test_type
6466
65 def setUp(self):67 def setUp(self):
66 launcher, self.test_type = self.get_launcher_and_type()68 launcher, test_type = self.get_launcher_and_type()
67 self.home_dir = self._patch_home()69 if self.home_dir is None:
70 self.home_dir = self._patch_home(test_type)
68 self.pointing_device = Pointer(self.input_device_class.create())71 self.pointing_device = Pointer(self.input_device_class.create())
69 super(RemindersAppTestCase, self).setUp()72 super(RemindersAppTestCase, self).setUp()
7073
@@ -80,7 +83,7 @@
80 os.path.expanduser(os.path.join('~', '.Xauthority')),83 os.path.expanduser(os.path.join('~', '.Xauthority')),
81 os.path.join(directory, '.Xauthority'))84 os.path.join(directory, '.Xauthority'))
8285
83 def _patch_home(self):86 def _patch_home(self, test_type):
84 """ mock /home for testing purposes to preserve user data87 """ mock /home for testing purposes to preserve user data
85 """88 """
86 temp_dir_fixture = fixtures.TempDir()89 temp_dir_fixture = fixtures.TempDir()
@@ -95,7 +98,7 @@
9598
96 #click requires using initctl env (upstart), but the desktop can set99 #click requires using initctl env (upstart), but the desktop can set
97 #an environment variable instead100 #an environment variable instead
98 if self.test_type == 'click':101 if test_type == 'click':
99 self.useFixture(toolkit_fixtures.InitctlEnvironmentVariable(102 self.useFixture(toolkit_fixtures.InitctlEnvironmentVariable(
100 HOME=temp_dir))103 HOME=temp_dir))
101 else:104 else:
102105
=== modified file 'tests/autopilot/reminders/tests/test_reminders.py'
--- tests/autopilot/reminders/tests/test_reminders.py 2014-04-24 19:33:26 +0000
+++ tests/autopilot/reminders/tests/test_reminders.py 2014-05-08 23:52:52 +0000
@@ -23,9 +23,10 @@
23from autopilot import platform23from autopilot import platform
24from autopilot.matchers import Eventually24from autopilot.matchers import Eventually
25from testtools.matchers import Equals25from testtools.matchers import Equals
26from testtools import ExpectedException
2627
27import reminders28import reminders
28from reminders import fixture_setup, tests29from reminders import credentials, fixture_setup, tests
2930
3031
31logger = logging.getLogger(__name__)32logger = logging.getLogger(__name__)
@@ -40,7 +41,7 @@
40 def test_go_to_account_settings(self):41 def test_go_to_account_settings(self):
41 """Test that the Go to account settings button calls url-dispatcher."""42 """Test that the Go to account settings button calls url-dispatcher."""
42 if platform.model() == 'Desktop':43 if platform.model() == 'Desktop':
43 self.skipTest("URL dispatcher doesn't work on the desktop.")44 self.skipTest("URL dispatcher doesn't work on the desktop.")
44 url_dispatcher = fixture_setup.FakeURLDispatcher()45 url_dispatcher = fixture_setup.FakeURLDispatcher()
45 self.useFixture(url_dispatcher)46 self.useFixture(url_dispatcher)
4647
@@ -56,3 +57,28 @@
56 self.assertThat(57 self.assertThat(
57 get_last_dispatch_url_call_parameter,58 get_last_dispatch_url_call_parameter,
58 Eventually(Equals('settings:///system/online-accounts')))59 Eventually(Equals('settings:///system/online-accounts')))
60
61
62class RemindersTestCaseWithAccount(tests.RemindersAppTestCase):
63
64 def setUp(self):
65 # We need to change the home dir before adding the account, otherwise
66 # the account will not be found when the app is opened.
67 _, test_type = self.get_launcher_and_type()
68 self.home_dir = self._patch_home(test_type)
69 self.add_evernote_account()
70 super(RemindersTestCaseWithAccount, self).setUp()
71
72 def add_evernote_account(self):
73 account_manager = credentials.AccountManager()
74 oauth_token = (
75 'S=s1:U=8e6bf:E=14d08e375ff:C=145b1324a03:P=1cd:A=en-devtoken:'
76 'V=2:H=79b946c32b4515ee52b387f7b68baa69')
77 account = account_manager.add_evernote_account(
78 'dummy', 'dummy', oauth_token)
79 self.addCleanup(account_manager.delete_account, account)
80
81 def test_open_application_with_account(self):
82 """Test that the No account dialog is not visible."""
83 with ExpectedException(reminders.RemindersAppException):
84 self.app.main_view.no_account_dialog

Subscribers

People subscribed via source and target branches