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
=== modified file 'debian/control'
--- debian/control 2014-05-16 12:52:13 +0000
+++ debian/control 2014-05-22 08:31:45 +0000
@@ -50,12 +50,14 @@
50Package: reminders-app-autopilot50Package: reminders-app-autopilot
51Architecture: all51Architecture: all
52Depends: ${misc:Depends},52Depends: ${misc:Depends},
53 evernote-sdk-python3,
53 reminders-app (>= ${source:Version}), reminders-app (<< ${source:Version}.1~),54 reminders-app (>= ${source:Version}), reminders-app (<< ${source:Version}.1~),
54 libautopilot-qt,55 libautopilot-qt,
55 libqt5test5,56 libqt5test5,
56 python3-dbus,57 python3-dbus,
57 python3-dbusmock,58 python3-dbusmock,
58 python3-fixtures,59 python3-fixtures,
60 python3-thrift,
59 ubuntu-ui-toolkit-autopilot,61 ubuntu-ui-toolkit-autopilot,
60Description: Test package for the Reminders app62Description: Test package for the Reminders app
61 Autopilot tests for the Reminders app package63 Autopilot tests for the Reminders app package
6264
=== modified file 'tests/autopilot/reminders/__init__.py'
--- tests/autopilot/reminders/__init__.py 2014-05-22 08:31:45 +0000
+++ tests/autopilot/reminders/__init__.py 2014-05-22 08:31:45 +0000
@@ -21,12 +21,9 @@
21import logging21import logging
22from distutils import version22from distutils import version
2323
24<<<<<<< TREE24import ubuntuuitoolkit
25
25import autopilot26import autopilot
26=======
27import ubuntuuitoolkit
28
29>>>>>>> MERGE-SOURCE
30from autopilot import logging as autopilot_logging27from autopilot import logging as autopilot_logging
31from autopilot.introspection import dbus28from autopilot.introspection import dbus
32from ubuntuuitoolkit import emulators as toolkit_emulators29from ubuntuuitoolkit import emulators as toolkit_emulators
3330
=== added file 'tests/autopilot/reminders/evernote.py'
--- tests/autopilot/reminders/evernote.py 1970-01-01 00:00:00 +0000
+++ tests/autopilot/reminders/evernote.py 2014-05-22 08:31:45 +0000
@@ -0,0 +1,132 @@
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
18from evernote.api import client
19from evernote.edam.type import ttypes
20from evernote.edam.error import ttypes as errors
21
22
23TEST_OAUTH_TOKEN = (
24 'S=s1:U=8e6bf:E=14d08e375ff:C=145b1324a03:P=1cd:A=en-devtoken:V=2:'
25 'H=79b946c32b4515ee52b387f7b68baa69')
26EVERNOTE_NOTE_XML_PROLOG = (
27 '<?xml version="1.0" encoding="UTF-8"?>'
28 '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">')
29EVERNOTE_NOTE_XML_ELEMENT_FORMAT = '<en-note>{}</en-note>'
30
31
32class SandboxEvernoteClient(client.EvernoteClient):
33 """Client to access the Evernote API on the sandbox server."""
34
35 def __init__(self):
36 super(SandboxEvernoteClient, self).__init__(
37 token=TEST_OAUTH_TOKEN, sandbox=True)
38
39 @property
40 def note_store(self):
41 return self.get_note_store()
42
43 def create_notebook(self, name):
44 """Create a notebook.
45
46 :param name: The name of the notebook to create.
47 :return: The created notebook.
48
49 """
50 notebook = ttypes.Notebook()
51 notebook.name = name
52
53 return self.note_store.createNotebook(notebook)
54
55 def create_note(self, title, content, notebook_guid):
56 """Create a note.
57
58 :param title: The title of the note to create.
59 :param content: The content to add to the note.
60 :return: The created note.
61
62 """
63 note = ttypes.Note()
64 note.title = title
65 note.content = EVERNOTE_NOTE_XML_PROLOG
66 note.content += EVERNOTE_NOTE_XML_ELEMENT_FORMAT.format(content)
67 note.notebookGuid = notebook_guid
68
69 return self.note_store.createNote(note)
70
71 def get_note_content(self, note_guid):
72 """Return the content of a note.
73
74 :param note_guid: The GUID of the note.
75 :return: The content of the note.
76
77 """
78 return self.note_store.getNoteContent(note_guid)
79
80 def expunge_notebook(self, notebook_guid):
81 """Permanently remove a notebook.
82
83 :param notebook_guid: The GUID of the notebook to expunge.
84
85 """
86 self.note_store.expungeNotebook(notebook_guid)
87
88 def get_notebook(self, notebook_guid):
89 """Return a notebook.
90
91 :param notebook_guid: The GUID of the notebook.
92
93 """
94 return self.note_store.getNotebook(notebook_guid)
95
96 def expunge_note(self, note_guid):
97 """Permanently remove a note.
98
99 :param note_guid: The GUID of the note to expunge.
100
101 """
102 return self.note_store.expungeNote(note_guid)
103
104 def get_note(self, note_guid):
105 """Return a note.
106
107 :param note_guid: The GUID of the note.
108
109 """
110 return self.note_store.getNote(note_guid, False, False, False, False)
111
112 def expunge_notebook_by_name(self, name):
113 """Permanently remove a notebook.
114
115 :param name: The first notebook found with this name will be expunged.
116
117 """
118 notebook = self.get_notebook_by_name(name)
119 self.expunge_notebook(notebook.guid)
120
121 def get_notebook_by_name(self, name):
122 """Return a notebook.
123
124 :param name: The first notebook found with this name will be returned.
125
126 """
127 notebooks = self.note_store.listNotebooks()
128 for notebook in notebooks:
129 if notebook.name == name:
130 return notebook
131 else:
132 raise errors.EDAMNotFoundException()
0133
=== added file 'tests/autopilot/reminders/tests/test_evernote.py'
--- tests/autopilot/reminders/tests/test_evernote.py 1970-01-01 00:00:00 +0000
+++ tests/autopilot/reminders/tests/test_evernote.py 2014-05-22 08:31:45 +0000
@@ -0,0 +1,128 @@
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
17import uuid
18
19import testtools
20from evernote.edam.error import ttypes as errors
21
22
23from reminders import evernote
24
25
26class EvernoteTestCase(testtools.TestCase):
27 """Test the evernote access with the SDK."""
28
29 def setUp(self):
30 super(EvernoteTestCase, self).setUp()
31 self.client = evernote.SandboxEvernoteClient()
32
33 def create_test_notebook(self, name=None):
34 if name is None:
35 name = 'Test notebook {}'.format(uuid.uuid1())
36 created_notebook = self.client.create_notebook(name)
37 self.addCleanup(self.expunge_test_notebook, created_notebook.guid)
38 return created_notebook
39
40 def expunge_test_notebook(self, notebook_guid):
41 try:
42 self.client.expunge_notebook(notebook_guid)
43 except errors.EDAMNotFoundException:
44 # The notebook was already deleted or not successfully created.
45 pass
46
47 def create_test_note(self, title=None, content=None, notebook_guid=None):
48 if title is None:
49 title = 'Test note {}'.format(uuid.uuid1())
50 if content is None:
51 content = 'test content.'
52 if notebook_guid is None:
53 notebook = self.create_test_notebook()
54 notebook_guid = notebook.guid
55
56 created_note = self.client.create_note(title, content, notebook_guid)
57 self.addCleanup(self.expunge_test_note, created_note.guid)
58 return created_note
59
60 def expunge_test_note(self, note_guid):
61 try:
62 self.client.expunge_note(note_guid)
63 except errors.EDAMNotFoundException:
64 # The note was already deleted or not successfully created.
65 pass
66
67 def test_create_notebook(self):
68 """Test that we can create a notebook on the evernote server."""
69 test_notebook_name = 'Test notebook {}'.format(uuid.uuid1())
70
71 # An exception will be raised if the notebook can't be created.
72 created_notebook = self.create_test_notebook(test_notebook_name)
73
74 self.assertEqual(created_notebook.name, test_notebook_name)
75
76 def test_create_note(self):
77 """Test that we can create a note on the evernote server."""
78 test_note_title = 'Test note {}'.format(uuid.uuid1())
79 test_note_content = 'test content.'
80 test_notebook = self.create_test_notebook()
81
82 # An exception will be raised if the note can't be created.
83 created_note = self.create_test_note(
84 test_note_title, test_note_content, test_notebook.guid)
85
86 self.assertEqual(created_note.title, test_note_title)
87 created_note_content = self.client.get_note_content(
88 created_note.guid)
89 self.assertIn(test_note_content, created_note_content)
90
91 def test_expunge_notebook_must_permanently_remove_it(self):
92 """Test that an expunged notebook is no longer available."""
93 created_notebook = self.create_test_notebook()
94
95 self.client.expunge_notebook(created_notebook.guid)
96
97 self.assertRaises(
98 errors.EDAMNotFoundException,
99 self.client.get_notebook,
100 created_notebook.guid)
101
102 def test_expunge_note_must_permanently_remove_it(self):
103 """Test that an expunged note is no longer available."""
104 created_note = self.create_test_note()
105
106 self.client.expunge_note(created_note.guid)
107
108 self.assertRaises(
109 errors.EDAMNotFoundException,
110 self.client.get_note,
111 created_note.guid)
112
113 def test_expunge_notebook_by_name_must_permanently_remove_it(self):
114 """Test that an expunged notebook is no longer available."""
115 created_notebook = self.create_test_notebook()
116
117 self.client.expunge_notebook_by_name(created_notebook.name)
118
119 self.assertRaises(
120 errors.EDAMNotFoundException,
121 self.client.get_notebook,
122 created_notebook.guid)
123
124 def test_get_unexisting_notebook_by_name_must_raise_exception(self):
125 self.assertRaises(
126 errors.EDAMNotFoundException,
127 self.client.get_notebook_by_name,
128 'I do not exist.')
0129
=== modified file 'tests/autopilot/reminders/tests/test_reminders.py'
--- tests/autopilot/reminders/tests/test_reminders.py 2014-05-22 08:31:45 +0000
+++ tests/autopilot/reminders/tests/test_reminders.py 2014-05-22 08:31:45 +0000
@@ -23,10 +23,11 @@
2323
24from autopilot import platform24from autopilot import platform
25from autopilot.matchers import Eventually25from autopilot.matchers import Eventually
26from evernote.edam.error import ttypes as evernote_errors
26from testtools.matchers import Equals27from testtools.matchers import Equals
2728
28import reminders29import reminders
29from reminders import credentials, fixture_setup, tests30from reminders import credentials, evernote, fixture_setup, tests
3031
3132
32logger = logging.getLogger(__name__)33logger = logging.getLogger(__name__)
@@ -66,24 +67,29 @@
66 no_account_dialog = self.app.main_view.no_account_dialog67 no_account_dialog = self.app.main_view.no_account_dialog
67 self.add_evernote_account()68 self.add_evernote_account()
68 no_account_dialog.wait_until_destroyed()69 no_account_dialog.wait_until_destroyed()
70 self.evernote_client = evernote.SandboxEvernoteClient()
6971
70 def add_evernote_account(self):72 def add_evernote_account(self):
71 account_manager = credentials.AccountManager()73 account_manager = credentials.AccountManager()
72 oauth_token = (
73 'S=s1:U=8e6bf:E=14d08e375ff:C=145b1324a03:P=1cd:A=en-devtoken:'
74 'V=2:H=79b946c32b4515ee52b387f7b68baa69')
75 account = account_manager.add_evernote_account(74 account = account_manager.add_evernote_account(
76 'dummy', 'dummy', oauth_token)75 'dummy', 'dummy', evernote.TEST_OAUTH_TOKEN)
77 self.addCleanup(account_manager.delete_account, account)76 self.addCleanup(account_manager.delete_account, account)
78 del account_manager._manager77 del account_manager._manager
79 del account_manager78 del account_manager
8079
80 def expunge_test_notebook(self, notebook_name):
81 try:
82 self.evernote_client.expunge_notebook_by_name(notebook_name)
83 except evernote_errors.EDAMNotFoundException:
84 # The notebook was already deleted or not successfully created.
85 pass
86
81 def test_add_notebook_must_append_it_to_list(self):87 def test_add_notebook_must_append_it_to_list(self):
88 """Test that an added notebook will be available for selection."""
82 test_notebook_title = 'Test notebook {}'.format(uuid.uuid1())89 test_notebook_title = 'Test notebook {}'.format(uuid.uuid1())
90 self.addCleanup(self.expunge_test_notebook, test_notebook_title)
8391
84 notebooks_page = self.app.open_notebooks()92 notebooks_page = self.app.open_notebooks()
85 # FIXME delete the added notebook. Otherwise, the test account will
86 # fill up. See http://pad.lv/1318749 --elopio - 2014-05-12
87 notebooks_page.add_notebook(test_notebook_title)93 notebooks_page.add_notebook(test_notebook_title)
8894
89 last_notebook = notebooks_page.get_notebooks()[-1]95 last_notebook = notebooks_page.get_notebooks()[-1]
@@ -96,3 +102,14 @@
96 self.assertEqual(last_notebook[0], test_notebook_title)102 self.assertEqual(last_notebook[0], test_notebook_title)
97 self.assertEqual(last_notebook[2], 'Private')103 self.assertEqual(last_notebook[2], 'Private')
98 self.assertEqual(last_notebook[3], 0)104 self.assertEqual(last_notebook[3], 0)
105
106 def test_add_notebook_must_create_it_in_server(self):
107 """Test that an added notebook will be created on the server."""
108 test_notebook_title = 'Test notebook {}'.format(uuid.uuid1())
109 self.addCleanup(self.expunge_test_notebook, test_notebook_title)
110
111 notebooks_page = self.app.open_notebooks()
112 notebooks_page.add_notebook(test_notebook_title)
113
114 # An exception will be raised if the notebook is note found.
115 self.evernote_client.get_notebook_by_name(test_notebook_title)

Subscribers

People subscribed via source and target branches