Example #1
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)
Example #2
0
 def _get_default_notebook(self):
     """Get default notebook"""
     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()
     return notebook
Example #3
0
 def test_local_notebooks(self):
     """Test sync local notebooks"""
     name = str(datetime.now())
     notebook = Notebook(
         name=name, action=ACTION_CREATE,
     )
     self.session.add(notebook)
     self.session.commit()
     self.sync.notebooks_local()
     self.assertEqual(notebook.action, ACTION_NONE)
     notebook_remote = self.note_store.getNotebook(self.auth_token, notebook.guid)
     self.assertEqual(notebook.name, notebook_remote.name)
     notebook.name += '*'
     notebook.action = ACTION_CHANGE
     self.sync.notebooks_local()
     self.assertEqual(notebook.action, ACTION_NONE)
     notebook_remote = self.note_store.getNotebook(self.auth_token, notebook.guid)
     self.assertEqual(notebook.name, notebook_remote.name)
Example #4
0
 def create_notebook(self, name):
     if self.sq(Note).filter(Notebook.name == name, ).count():
         raise DBusException('Notebook with this name already exist', )
     notebook = Notebook(
         action=ACTION_CREATE,
         name=name,
         default=False,
     )
     self.session.add(notebook)
     self.session.commit()
     self.data_changed()
     return btype.Notebook.from_obj(notebook).struct
Example #5
0
 def test_local_notes(self):
     """Test local notes sync"""
     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()
     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 #6
0
 def test_tag_notebook_validation(self):
     """Test tags and notebooks names validation for #201"""
     notebook = Notebook(
         name="Blog posts%s" % str(datetime.now()), action=ACTION_CREATE,
     )
     self.session.add(notebook)
     self.session.commit()
     self.sync.notebooks_local()
     self.assertNotIn('skipped', self.sync.logs[-1])
     self.assertNotIn('Notebook.name', self.sync.logs[-1])
     tag = Tag(
         name="spackeria%s" % str(datetime.now()), action=ACTION_CREATE,
     )
     self.session.add(tag)
     self.session.commit()
     self.sync.tags_local()
     self.assertNotIn('skipped', self.sync.logs[-1])
     self.assertNotIn('Tag.name', self.sync.logs[-1])