Пример #1
0
 def notebooks_remote(self):
     """Receive notebooks from server"""
     notebooks_ids = []
     for notebook in self.note_store.listNotebooks(self.auth_token):
         self.app.log('Notebook %s remote' % notebook.name)
         try:
             nb = self.sq(models.Notebook).filter(
                 models.Notebook.guid == notebook.guid, ).one()
             notebooks_ids.append(nb.id)
             if nb.service_updated < notebook.serviceUpdated:
                 nb.from_api(notebook)
         except NoResultFound:
             nb = models.Notebook(guid=notebook.guid)
             nb.from_api(notebook)
             self.session.add(nb)
             self.session.commit()
             notebooks_ids.append(nb.id)
     ids = filter(lambda id: id not in notebooks_ids,
                  map(
                      lambda nb: nb.id,
                      self.sq(models.Notebook).all(),
                  ))
     if len(ids):
         self.sq(models.Notebook).filter(
             and_(
                 models.Notebook.id.in_(ids),
                 models.Notebook.action != ACTION_CREATE,
                 models.Notebook.action != ACTION_CHANGE,
             )).delete(synchronize_session='fetch')
     self.session.commit()
Пример #2
0
 def test_service_get_notebook(self):
     notebook = models.Notebook(name='a123', default=True)
     self.session.add(notebook)
     self.session.commit()
     self.assertEqual(
         self.serv.get_notebook(notebook.id),
         (notebook.id, u'a123', True),
         'get notebook',
     )
Пример #3
0
 def test_service_list_notebooks(self):
     notebook = models.Notebook(name='a123')
     self.session.add(notebook)
     self.session.commit()
     self.assertEqual(
         self.serv.list_notebooks(),
         [(notebook.id, u'a123', None)],
         'list notebooks',
     )
Пример #4
0
 def test_service_create_note(self):
     notebook = models.Notebook(name='a123', default=True)
     self.session.add(notebook)
     self.session.commit()
     note = (None, u'q ab cd', u'123', None, None, notebook.id, [u'eee'])
     self.assertEqual(
         self.serv.create_note(note),
         (1, u'q ab cd', u'123', None, None, notebook.id, [u'eee']),
         'create note via service',
     )
Пример #5
0
 def test_service_delete_note(self):
     notebook = models.Notebook(name='a123', default=True)
     note = models.Note(
         title='123',
         content='123',
         notebook=notebook,
     )
     self.session.add_all([notebook, note])
     self.session.commit()
     self.serv.delete_note(note.id)
     self.assertEqual(note.action, ACTION_DELETE, 'delete note')
Пример #6
0
 def test_service_find_notes(self):
     note = models.Note(title='q ab cd',
                        content='123',
                        action=ACTION_CREATE)
     tag = models.Tag(name='eee')
     notebook = models.Notebook(name='123')
     self.session.add_all([note, tag, notebook])
     note.tags = [tag]
     note.notebook = notebook
     self.session.commit()
     self.assertEqual(
         self.serv.find_notes('ab cd', [notebook.id], [tag.id]),
         [(note.id, u'q ab cd', u'123', None, None, notebook.id, [u'eee'])],
         'find notes via service',
     )
Пример #7
0
 def test_service_update_note(self):
     notebook = models.Notebook(name='a123', default=True)
     note = models.Note(
         title='123',
         content='123',
         notebook=notebook,
     )
     self.session.add_all([notebook, note])
     self.session.commit()
     result = self.serv.update_note(
         (note.id, u'q ab cd', u'123', None, None, notebook.id, [u'eee']), )
     self.assertEqual(
         result,
         (note.id, u'q ab cd', u'123', None, None, notebook.id, [u'eee']),
         'update note',
     )
Пример #8
0
 def test_local_sync(self):
     note = models.Note(
         title='test',
         content='test',
         action=ACTION_CREATE,
     )
     self.session.add(note)
     self.sc.local_changes()
     self.assertEqual(
         'test',
         self.sc.note_store.getNote(
             token,
             note.guid,
             True,
             False,
             False,
             False,
         ).title,
         'sync simple note',
     )
     notebook = models.Notebook(
         name=str(datetime.now()),
         default=False,
         action=ACTION_CREATE,
     )
     self.session.add(notebook)
     note.notebook = notebook
     note.action = ACTION_CHANGE
     self.sc.local_changes()
     self.assertEqual(
         notebook.guid,
         self.sc.note_store.getNote(
             token,
             note.guid,
             True,
             False,
             False,
             False,
         ).notebookGuid,
         'sync note with notebook',
     )
     tag = models.Tag(
         name=str(datetime.now()),
         action=ACTION_CREATE,
     )
     self.session.add(tag)
     note.action = ACTION_CHANGE
     note.tags = [tag]
     self.sc.local_changes()
     self.assertEqual(
         [tag.guid],
         self.sc.note_store.getNote(
             token,
             note.guid,
             True,
             False,
             False,
             False,
         ).tagGuids,
         'sync note with tags',
     )
     notebook.name = str(datetime.now())
     notebook.action = ACTION_CHANGE
     self.sc.local_changes()
     self.assertEqual(
         notebook.name,
         self.sc.note_store.getNotebook(
             token,
             notebook.guid,
         ).name,
         'sync notebook change',
     )
     tag.name = str(datetime.now())
     tag.action = ACTION_CHANGE
     self.sc.local_changes()
     self.assertEqual(
         tag.name,
         self.sc.note_store.getTag(
             token,
             tag.guid,
         ).name,
         'sync tag change',
     )
     note.action = ACTION_DELETE
     self.sc.local_changes()
     self.assertIsNotNone(
         self.sc.note_store.getNote(
             token,
             note.guid,
             True,
             False,
             False,
             False,
         ), 'remove note')