def test_get_note_link(self, sdk): User = namedtuple("User", ["id", "shardId"]) user = User(id="user_id:123", shardId="shardId:qwe") sdk().get_user_store().getUser = mock.Mock(return_value=user) sdk().service_host = "evernote.service.host" api = EvernoteApi("access_token") result = api.get_note_link("note_guid:xxx") self.assertEqual(result, "https://evernote.service.host/shard/shardId:qwe/nl/user_id:123/note_guid:xxx/") result = api.get_note_link("note_guid:zzz", app_link=True) self.assertEqual(result, "evernote:///view/user_id:123/shardId:qwe/note_guid:zzz/note_guid:zzz/")
def test_update_note(self, sdk): content = '<?xml version="1.0" encoding="UTF-8"?>'\ '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">'\ '<en-note><br />'\ '<div>test text</div>'\ '<p>Test</p><br />'\ '</en-note>' note = Types.Note(guid="123", title="One big note", content=content) note.notebookGuid = "notebook" self.note_store().getNote = mock.Mock(return_value=note) self.note_store().createNote = mock.Mock(return_value=Types.Note( guid="new")) self.note_store().updateNote = mock.Mock(return_value="updated") sdk().get_note_store = self.note_store api = EvernoteApi("access_token") api.get_note_link = mock.Mock(return_value="http://evernote.com/123") tmp_filename = None with tempfile.NamedTemporaryFile(mode="r+", suffix=".txt", dir="/tmp") as f: f.write("Hello") tmp_filename = basename(f.name) result = api.update_note("123", text="Merry Christmas", title="Santa Claus", html="<p>New Year</p>", files=[{ "path": f.name, "name": tmp_filename }]) self.assertEqual(result, "updated") self.note_store().createNote.assert_called_once() call_args = self.note_store().createNote.call_args[0] self.assertEqual(call_args[0].title, "Santa Claus") self.note_store().updateNote.assert_called_once() call_args = self.note_store().updateNote.call_args[0] self.assertEqual(len(call_args), 1) self.assertEqual(call_args[0].title, "One big note") self.assertEqual(call_args[0].notebookGuid, "notebook") self.assertEqual( call_args[0].content, '<?xml version="1.0" encoding="UTF-8"?>' '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">' '<en-note><br />' '<div>test text</div>' '<p>Test</p><br />' '<br /><div>Merry Christmas</div><p>New Year</p><br />' f'<a href="http://evernote.com/123">{tmp_filename}</a>' '</en-note>')