Beispiel #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)
Beispiel #2
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()
Beispiel #3
0
 def create_note(self, data):
     note = Note(action=ACTION_NOEXSIST, )
     btype.Note.from_tuple(data).give_to_obj(note)
     note.id = None
     note.updated = int(time.time() * 1000)
     note.created = int(time.time() * 1000)
     self.session.add(note)
     self.session.commit()
     self.data_changed()
     return btype.Note.from_obj(note).struct
Beispiel #4
0
 def create_note(self, data):
     note = Note(
         action=ACTION_NOEXSIST,
     )
     btype.Note.from_tuple(data).give_to_obj(note)
     note.id = None
     note.updated = int(time.time() * 1000)
     note.created = int(time.time() * 1000)
     self.session.add(note)
     self.session.commit()
     self.data_changed()
     return btype.Note.from_obj(note).struct
Beispiel #5
0
 def create_note(self, data):
     note = Note(
         action=ACTION_CREATE,
     )
     btype.Note.from_tuple(data).give_to_obj(note)
     note.id = None
     try:
         note.updated = self.sq(func.max(Note.created)).one()[0]
     except (NoResultFound, IndexError):
         note.updated = 0
     self.session.add(note)
     self.session.commit()
     return btype.Note.from_obj(note).struct
Beispiel #6
0
 def test_stop_sharing(self):
     """Test stop sharing"""
     notebook = self._get_default_notebook()
     note = Note(
         title='67890', action=ACTION_CREATE,
         notebook=notebook, content='12345',
         share_status=SHARE_NEED_SHARE,
     )
     self.session.add(note)
     self.session.commit()
     self.sync.notes_local()
     self.sync.notes_sharing()
     note.share_status = SHARE_NEED_STOP
     self.session.commit()
     self.sync.notes_remote()
     self.sync.notes_stop_sharing()
     self.assertEqual(note.share_status, SHARE_NONE)
Beispiel #7
0
 def test_share_note(self):
     """Test sharing note"""
     notebook = self._get_default_notebook()
     note = Note(
         title='67890', action=ACTION_CREATE,
         notebook=notebook, content='12345',
         share_status=SHARE_NEED_SHARE,
     )
     self.session.add(note)
     self.session.commit()
     self.sync.notes_local()
     self.sync.notes_sharing()
     share_url = self.note_store.shareNote(self.auth_token, note.guid)
     self.assertIn(share_url, note.share_url)
     self.assertEqual(note.share_status, SHARE_SHARED)