Merge lp:~elopio/reminders-app/evernote-sdk into lp:reminders-app

Proposed by Leo Arias
Status: Merged
Approved by: Nicholas Skaggs
Approved revision: 143
Merged at revision: 152
Proposed branch: lp:~elopio/reminders-app/evernote-sdk
Merge into: lp:reminders-app
Prerequisite: lp:~elopio/reminders-app/autopilot-add_notebook
Diff against target: 375 lines (+288/-12)
5 files modified
debian/control (+2/-0)
tests/autopilot/reminders/__init__.py (+2/-5)
tests/autopilot/reminders/evernote.py (+132/-0)
tests/autopilot/reminders/tests/test_evernote.py (+128/-0)
tests/autopilot/reminders/tests/test_reminders.py (+24/-7)
To merge this branch: bzr merge lp:~elopio/reminders-app/evernote-sdk
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Carla Sella Pending
Richard Huddie Pending
Julia Palandri Pending
VĂ­ctor R. Ruiz Pending
Allan LeSage Pending
Ubuntu Notes app developers Pending
Review via email: mp+219642@code.launchpad.net

Commit message

Added helpers for setting up and cleaning up the evernote account.
Added a test to check that an added note will be created on the server.
Make sure that all tests remove all the things they create.

To post a comment you must log in.
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: 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) wrote :
review: Needs Fixing (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
1=== modified file 'debian/control'
2--- debian/control 2014-05-16 12:52:13 +0000
3+++ debian/control 2014-05-22 08:31:45 +0000
4@@ -50,12 +50,14 @@
5 Package: reminders-app-autopilot
6 Architecture: all
7 Depends: ${misc:Depends},
8+ evernote-sdk-python3,
9 reminders-app (>= ${source:Version}), reminders-app (<< ${source:Version}.1~),
10 libautopilot-qt,
11 libqt5test5,
12 python3-dbus,
13 python3-dbusmock,
14 python3-fixtures,
15+ python3-thrift,
16 ubuntu-ui-toolkit-autopilot,
17 Description: Test package for the Reminders app
18 Autopilot tests for the Reminders app package
19
20=== modified file 'tests/autopilot/reminders/__init__.py'
21--- tests/autopilot/reminders/__init__.py 2014-05-22 08:31:45 +0000
22+++ tests/autopilot/reminders/__init__.py 2014-05-22 08:31:45 +0000
23@@ -21,12 +21,9 @@
24 import logging
25 from distutils import version
26
27-<<<<<<< TREE
28+import ubuntuuitoolkit
29+
30 import autopilot
31-=======
32-import ubuntuuitoolkit
33-
34->>>>>>> MERGE-SOURCE
35 from autopilot import logging as autopilot_logging
36 from autopilot.introspection import dbus
37 from ubuntuuitoolkit import emulators as toolkit_emulators
38
39=== added file 'tests/autopilot/reminders/evernote.py'
40--- tests/autopilot/reminders/evernote.py 1970-01-01 00:00:00 +0000
41+++ tests/autopilot/reminders/evernote.py 2014-05-22 08:31:45 +0000
42@@ -0,0 +1,132 @@
43+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
44+#
45+# Copyright (C) 2014 Canonical Ltd.
46+#
47+# This program is free software; you can redistribute it and/or modify
48+# it under the terms of the GNU General Public License version 3, as published
49+# by the Free Software Foundation.
50+#
51+# This program is distributed in the hope that it will be useful,
52+# but WITHOUT ANY WARRANTY; without even the implied warranty of
53+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
54+# GNU General Public License for more details.
55+#
56+# You should have received a copy of the GNU General Public License
57+# along with this program. If not, see <http://www.gnu.org/licenses/>.
58+
59+
60+from evernote.api import client
61+from evernote.edam.type import ttypes
62+from evernote.edam.error import ttypes as errors
63+
64+
65+TEST_OAUTH_TOKEN = (
66+ 'S=s1:U=8e6bf:E=14d08e375ff:C=145b1324a03:P=1cd:A=en-devtoken:V=2:'
67+ 'H=79b946c32b4515ee52b387f7b68baa69')
68+EVERNOTE_NOTE_XML_PROLOG = (
69+ '<?xml version="1.0" encoding="UTF-8"?>'
70+ '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">')
71+EVERNOTE_NOTE_XML_ELEMENT_FORMAT = '<en-note>{}</en-note>'
72+
73+
74+class SandboxEvernoteClient(client.EvernoteClient):
75+ """Client to access the Evernote API on the sandbox server."""
76+
77+ def __init__(self):
78+ super(SandboxEvernoteClient, self).__init__(
79+ token=TEST_OAUTH_TOKEN, sandbox=True)
80+
81+ @property
82+ def note_store(self):
83+ return self.get_note_store()
84+
85+ def create_notebook(self, name):
86+ """Create a notebook.
87+
88+ :param name: The name of the notebook to create.
89+ :return: The created notebook.
90+
91+ """
92+ notebook = ttypes.Notebook()
93+ notebook.name = name
94+
95+ return self.note_store.createNotebook(notebook)
96+
97+ def create_note(self, title, content, notebook_guid):
98+ """Create a note.
99+
100+ :param title: The title of the note to create.
101+ :param content: The content to add to the note.
102+ :return: The created note.
103+
104+ """
105+ note = ttypes.Note()
106+ note.title = title
107+ note.content = EVERNOTE_NOTE_XML_PROLOG
108+ note.content += EVERNOTE_NOTE_XML_ELEMENT_FORMAT.format(content)
109+ note.notebookGuid = notebook_guid
110+
111+ return self.note_store.createNote(note)
112+
113+ def get_note_content(self, note_guid):
114+ """Return the content of a note.
115+
116+ :param note_guid: The GUID of the note.
117+ :return: The content of the note.
118+
119+ """
120+ return self.note_store.getNoteContent(note_guid)
121+
122+ def expunge_notebook(self, notebook_guid):
123+ """Permanently remove a notebook.
124+
125+ :param notebook_guid: The GUID of the notebook to expunge.
126+
127+ """
128+ self.note_store.expungeNotebook(notebook_guid)
129+
130+ def get_notebook(self, notebook_guid):
131+ """Return a notebook.
132+
133+ :param notebook_guid: The GUID of the notebook.
134+
135+ """
136+ return self.note_store.getNotebook(notebook_guid)
137+
138+ def expunge_note(self, note_guid):
139+ """Permanently remove a note.
140+
141+ :param note_guid: The GUID of the note to expunge.
142+
143+ """
144+ return self.note_store.expungeNote(note_guid)
145+
146+ def get_note(self, note_guid):
147+ """Return a note.
148+
149+ :param note_guid: The GUID of the note.
150+
151+ """
152+ return self.note_store.getNote(note_guid, False, False, False, False)
153+
154+ def expunge_notebook_by_name(self, name):
155+ """Permanently remove a notebook.
156+
157+ :param name: The first notebook found with this name will be expunged.
158+
159+ """
160+ notebook = self.get_notebook_by_name(name)
161+ self.expunge_notebook(notebook.guid)
162+
163+ def get_notebook_by_name(self, name):
164+ """Return a notebook.
165+
166+ :param name: The first notebook found with this name will be returned.
167+
168+ """
169+ notebooks = self.note_store.listNotebooks()
170+ for notebook in notebooks:
171+ if notebook.name == name:
172+ return notebook
173+ else:
174+ raise errors.EDAMNotFoundException()
175
176=== added file 'tests/autopilot/reminders/tests/test_evernote.py'
177--- tests/autopilot/reminders/tests/test_evernote.py 1970-01-01 00:00:00 +0000
178+++ tests/autopilot/reminders/tests/test_evernote.py 2014-05-22 08:31:45 +0000
179@@ -0,0 +1,128 @@
180+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
181+#
182+# Copyright (C) 2014 Canonical Ltd.
183+#
184+# This program is free software; you can redistribute it and/or modify
185+# it under the terms of the GNU General Public License version 3, as published
186+# by the Free Software Foundation.
187+#
188+# This program is distributed in the hope that it will be useful,
189+# but WITHOUT ANY WARRANTY; without even the implied warranty of
190+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
191+# GNU General Public License for more details.
192+#
193+# You should have received a copy of the GNU General Public License
194+# along with this program. If not, see <http://www.gnu.org/licenses/>.
195+
196+import uuid
197+
198+import testtools
199+from evernote.edam.error import ttypes as errors
200+
201+
202+from reminders import evernote
203+
204+
205+class EvernoteTestCase(testtools.TestCase):
206+ """Test the evernote access with the SDK."""
207+
208+ def setUp(self):
209+ super(EvernoteTestCase, self).setUp()
210+ self.client = evernote.SandboxEvernoteClient()
211+
212+ def create_test_notebook(self, name=None):
213+ if name is None:
214+ name = 'Test notebook {}'.format(uuid.uuid1())
215+ created_notebook = self.client.create_notebook(name)
216+ self.addCleanup(self.expunge_test_notebook, created_notebook.guid)
217+ return created_notebook
218+
219+ def expunge_test_notebook(self, notebook_guid):
220+ try:
221+ self.client.expunge_notebook(notebook_guid)
222+ except errors.EDAMNotFoundException:
223+ # The notebook was already deleted or not successfully created.
224+ pass
225+
226+ def create_test_note(self, title=None, content=None, notebook_guid=None):
227+ if title is None:
228+ title = 'Test note {}'.format(uuid.uuid1())
229+ if content is None:
230+ content = 'test content.'
231+ if notebook_guid is None:
232+ notebook = self.create_test_notebook()
233+ notebook_guid = notebook.guid
234+
235+ created_note = self.client.create_note(title, content, notebook_guid)
236+ self.addCleanup(self.expunge_test_note, created_note.guid)
237+ return created_note
238+
239+ def expunge_test_note(self, note_guid):
240+ try:
241+ self.client.expunge_note(note_guid)
242+ except errors.EDAMNotFoundException:
243+ # The note was already deleted or not successfully created.
244+ pass
245+
246+ def test_create_notebook(self):
247+ """Test that we can create a notebook on the evernote server."""
248+ test_notebook_name = 'Test notebook {}'.format(uuid.uuid1())
249+
250+ # An exception will be raised if the notebook can't be created.
251+ created_notebook = self.create_test_notebook(test_notebook_name)
252+
253+ self.assertEqual(created_notebook.name, test_notebook_name)
254+
255+ def test_create_note(self):
256+ """Test that we can create a note on the evernote server."""
257+ test_note_title = 'Test note {}'.format(uuid.uuid1())
258+ test_note_content = 'test content.'
259+ test_notebook = self.create_test_notebook()
260+
261+ # An exception will be raised if the note can't be created.
262+ created_note = self.create_test_note(
263+ test_note_title, test_note_content, test_notebook.guid)
264+
265+ self.assertEqual(created_note.title, test_note_title)
266+ created_note_content = self.client.get_note_content(
267+ created_note.guid)
268+ self.assertIn(test_note_content, created_note_content)
269+
270+ def test_expunge_notebook_must_permanently_remove_it(self):
271+ """Test that an expunged notebook is no longer available."""
272+ created_notebook = self.create_test_notebook()
273+
274+ self.client.expunge_notebook(created_notebook.guid)
275+
276+ self.assertRaises(
277+ errors.EDAMNotFoundException,
278+ self.client.get_notebook,
279+ created_notebook.guid)
280+
281+ def test_expunge_note_must_permanently_remove_it(self):
282+ """Test that an expunged note is no longer available."""
283+ created_note = self.create_test_note()
284+
285+ self.client.expunge_note(created_note.guid)
286+
287+ self.assertRaises(
288+ errors.EDAMNotFoundException,
289+ self.client.get_note,
290+ created_note.guid)
291+
292+ def test_expunge_notebook_by_name_must_permanently_remove_it(self):
293+ """Test that an expunged notebook is no longer available."""
294+ created_notebook = self.create_test_notebook()
295+
296+ self.client.expunge_notebook_by_name(created_notebook.name)
297+
298+ self.assertRaises(
299+ errors.EDAMNotFoundException,
300+ self.client.get_notebook,
301+ created_notebook.guid)
302+
303+ def test_get_unexisting_notebook_by_name_must_raise_exception(self):
304+ self.assertRaises(
305+ errors.EDAMNotFoundException,
306+ self.client.get_notebook_by_name,
307+ 'I do not exist.')
308
309=== modified file 'tests/autopilot/reminders/tests/test_reminders.py'
310--- tests/autopilot/reminders/tests/test_reminders.py 2014-05-22 08:31:45 +0000
311+++ tests/autopilot/reminders/tests/test_reminders.py 2014-05-22 08:31:45 +0000
312@@ -23,10 +23,11 @@
313
314 from autopilot import platform
315 from autopilot.matchers import Eventually
316+from evernote.edam.error import ttypes as evernote_errors
317 from testtools.matchers import Equals
318
319 import reminders
320-from reminders import credentials, fixture_setup, tests
321+from reminders import credentials, evernote, fixture_setup, tests
322
323
324 logger = logging.getLogger(__name__)
325@@ -66,24 +67,29 @@
326 no_account_dialog = self.app.main_view.no_account_dialog
327 self.add_evernote_account()
328 no_account_dialog.wait_until_destroyed()
329+ self.evernote_client = evernote.SandboxEvernoteClient()
330
331 def add_evernote_account(self):
332 account_manager = credentials.AccountManager()
333- oauth_token = (
334- 'S=s1:U=8e6bf:E=14d08e375ff:C=145b1324a03:P=1cd:A=en-devtoken:'
335- 'V=2:H=79b946c32b4515ee52b387f7b68baa69')
336 account = account_manager.add_evernote_account(
337- 'dummy', 'dummy', oauth_token)
338+ 'dummy', 'dummy', evernote.TEST_OAUTH_TOKEN)
339 self.addCleanup(account_manager.delete_account, account)
340 del account_manager._manager
341 del account_manager
342
343+ def expunge_test_notebook(self, notebook_name):
344+ try:
345+ self.evernote_client.expunge_notebook_by_name(notebook_name)
346+ except evernote_errors.EDAMNotFoundException:
347+ # The notebook was already deleted or not successfully created.
348+ pass
349+
350 def test_add_notebook_must_append_it_to_list(self):
351+ """Test that an added notebook will be available for selection."""
352 test_notebook_title = 'Test notebook {}'.format(uuid.uuid1())
353+ self.addCleanup(self.expunge_test_notebook, test_notebook_title)
354
355 notebooks_page = self.app.open_notebooks()
356- # FIXME delete the added notebook. Otherwise, the test account will
357- # fill up. See http://pad.lv/1318749 --elopio - 2014-05-12
358 notebooks_page.add_notebook(test_notebook_title)
359
360 last_notebook = notebooks_page.get_notebooks()[-1]
361@@ -96,3 +102,14 @@
362 self.assertEqual(last_notebook[0], test_notebook_title)
363 self.assertEqual(last_notebook[2], 'Private')
364 self.assertEqual(last_notebook[3], 0)
365+
366+ def test_add_notebook_must_create_it_in_server(self):
367+ """Test that an added notebook will be created on the server."""
368+ test_notebook_title = 'Test notebook {}'.format(uuid.uuid1())
369+ self.addCleanup(self.expunge_test_notebook, test_notebook_title)
370+
371+ notebooks_page = self.app.open_notebooks()
372+ notebooks_page.add_notebook(test_notebook_title)
373+
374+ # An exception will be raised if the notebook is note found.
375+ self.evernote_client.get_notebook_by_name(test_notebook_title)

Subscribers

People subscribed via source and target branches