Example #1
0
 def test_local_notes(self):
     """Test local notes sync"""
     notebook = self._get_default_notebook()
     note = Note(
         title='67890', action=ACTION_CREATE,
         notebook=notebook, content='12345',
     )
     self.session.add(note)
     self.session.commit()
     self.sync.notes_local()
     self.assertEqual(note.action, ACTION_NONE)
     note_remote = self.note_store.getNote(
         self.auth_token, note.guid, True, False, False, False,
     )
     self.assertEqual(notebook.guid, note_remote.notebookGuid)
     note.title += '*'
     note.action = ACTION_CHANGE
     self.sync.notes_local()
     self.assertEqual(note.action, ACTION_NONE)
     note_remote = self.note_store.getNote(
         self.auth_token, note.guid, True, False, False, False,
     )
     self.assertEqual(note.title, note_remote.title)
     note.action = ACTION_DELETE
     self.sync.notes_local()
     note_remote = self.note_store.getNote(
         self.auth_token, note.guid, True, False, False, False,
     )
     self.assertFalse(note_remote.active)
     with self.assertRaises(NoResultFound):
         self.sq(Note).filter(
             Note.guid == note_remote.guid,
         ).one()
Example #2
0
 def test_local_resources(self):
     """Test local resources"""
     remote_notebook = self.note_store.getDefaultNotebook(self.auth_token)
     notebook = Notebook(guid=remote_notebook.guid)
     notebook.from_api(remote_notebook)
     self.session.add(notebook)
     self.session.commit()
     note = Note(
         title='67890', action=ACTION_CREATE,
         notebook=notebook, content='12345',
     )
     self.session.add(note)
     self.session.commit()
     res = Resource(
         note_id=note.id, file_name='test.png',
         file_path=resource_path, mime='image/png',
         action=ACTION_CREATE,
     )
     self.session.add(res)
     self.session.commit()
     self.sync.notes_local()
     note_remote = self.note_store.getNote(
         self.auth_token, note.guid, True, True, False, False,
     )
     self.assertEqual('test.png', note_remote.resources[0].attributes.fileName)
     self.session.delete(res)
     self.session.commit()
     note.action = ACTION_CHANGE
     self.sync.notes_local()
     note_remote = self.note_store.getNote(
         self.auth_token, note.guid, True, True, False, False,
     )
     self.assertIsNone(note_remote.resources)