Example #1
0
def operations_are_retried_on_refresh():
    changes_store = ChangesStore()
    changes_store.try_or_save(note_store.updateNote, developer_token, note)
    note_store.updateNote.side_effect = None
    changes_store.retry_failed_operations()

    assert_not_in(operation, changes_store.saved_operations)
Example #2
0
 def __init__(self):
     self._developer_token = config.get('login_details', 'developer_token')
     self.note_store = _get_note_store()
     self.changes_store = ChangesStore()
Example #3
0
class EvernoteApi(object):
    def __init__(self):
        self._developer_token = config.get('login_details', 'developer_token')
        self.note_store = _get_note_store()
        self.changes_store = ChangesStore()


    def list_notebooks(self):
        notebooks = self.note_store.listNotebooks(self._developer_token)
        return notebooks

    def get_notebook_guid(self, notebook_name):
        for notebook in self.list_notebooks():
            if notebook.name.lower() == notebook_name.lower():
                return notebook.guid
        else:
            print 'Notebook {0} not found'.format(notebook_name)
            exit()

    def list_notes(self, notebook_name):
        notebook_guid = self.get_notebook_guid(notebook_name)
        note_filter = NoteFilter(notebookGuid=notebook_guid,
                                 ascending=False,
                                 order=1)
        result_spec = NotesMetadataResultSpec(includeTitle=True)
        note_list = self.note_store.findNotesMetadata(self._developer_token,
                                                      note_filter,
                                                      0,
                                                      1000,
                                                      result_spec)

        return note_list.notes

    def create_note(self, note_title, note_content, notebook_name):
        note = ttypes.Note()
        note.title = note_title
        note.notebookGuid = self.get_notebook_guid(notebook_name)
        note.content = self._create_note_content(note_content)

        self.note_store.createNote(self._developer_token, note)
        self.changed_cache.remove_value('changed')

    def get_note(self, note_title, notebook_name):
        for note in self.list_notes(notebook_name):
            if note.title.lower() == note_title.lower():
                return self.note_store.getNote(self._developer_token,
                                               note.guid,
                                               True, False,
                                               False, False)

    def update_note(self, note_title, note_content, notebook_name):
        note = self.get_note(note_title, notebook_name)
        old_content = note.content
        note.content = self._create_note_content(note_content)
        if old_content != note.content:
            self.note_store.updateNote(self._developer_token, note)
            self.changed_cache.remove_value('changed')

    def retry_failed_operations(self):
        self.changes_store.retry_failed_operations()

    def refresh_cache(self):
        cache.invalidate(self._get_note_store_url)
        self.changed_cache.remove_value('changed')

    def _create_note_content(self, note_content):
        html_content = markdown.markdown(note_content)
        return self._surround_with_html(html_content)

    def _surround_with_html(self, text):
        return '<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note>{0}</en-note>'.format(text)
Example #4
0
def notes_are_saved_when_note_store_throws():
    changes_store = ChangesStore()
    changes_store.try_or_save(note_store.updateNote, developer_token, note)

    assert_in(operation, changes_store.saved_operations)