本文整理匯總了Python中leap.soledad.client.sqlcipher.SQLCipherDatabase.whats_changed方法的典型用法代碼示例。如果您正苦於以下問題:Python SQLCipherDatabase.whats_changed方法的具體用法?Python SQLCipherDatabase.whats_changed怎麽用?Python SQLCipherDatabase.whats_changed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類leap.soledad.client.sqlcipher.SQLCipherDatabase
的用法示例。
在下文中一共展示了SQLCipherDatabase.whats_changed方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestSoledadDbSync
# 需要導入模塊: from leap.soledad.client.sqlcipher import SQLCipherDatabase [as 別名]
# 或者: from leap.soledad.client.sqlcipher.SQLCipherDatabase import whats_changed [as 別名]
#.........這裏部分代碼省略.........
"""
dbsyncer = getattr(self, 'dbsyncer', None)
if dbsyncer:
dbsyncer.close()
self.db1.close()
self.db2.close()
self._soledad.close()
# XXX should not access "private" attrs
shutil.rmtree(os.path.dirname(self._soledad._local_db_path))
SoledadWithCouchServerMixin.tearDown(self)
def do_sync(self, target_name):
"""
Perform sync using SoledadSynchronizer, SoledadSyncTarget
and Token auth.
"""
if self.token:
creds = {'token': {
'uuid': 'user-uuid',
'token': 'auth-token',
}}
target_url = self.getURL(self.db2._dbname)
# get a u1db syncer
crypto = self._soledad._crypto
replica_uid = self.db1._replica_uid
dbsyncer = SQLCipherU1DBSync(
self.opts,
crypto,
replica_uid,
None,
defer_encryption=True)
self.dbsyncer = dbsyncer
return dbsyncer.sync(target_url,
creds=creds,
defer_decryption=DEFER_DECRYPTION)
else:
return self._do_sync(self, target_name)
def _do_sync(self, target_name):
if self.oauth:
path = '~/' + target_name
extra = dict(creds={'oauth': {
'consumer_key': tests.consumer1.key,
'consumer_secret': tests.consumer1.secret,
'token_key': tests.token1.key,
'token_secret': tests.token1.secret,
}})
else:
path = target_name
extra = {}
target_url = self.getURL(path)
return self.db.sync(target_url, **extra)
def wait_for_sync(self):
"""
Wait for sync to finish.
"""
wait = 0
syncer = self.syncer
if syncer is not None:
while syncer.syncing:
time.sleep(WAIT_STEP)
wait += WAIT_STEP
if wait >= MAX_WAIT:
raise SyncTimeoutError
def test_db_sync(self):
"""
Test sync.
Adapted to check for encrypted content.
"""
doc1 = self.db1.create_doc_from_json(tests.simple_doc)
doc2 = self.db2.create_doc_from_json(tests.nested_doc)
d = self.do_sync('test')
def _assert_successful_sync(results):
import time
# need to give time to the encryption to proceed
# TODO should implement a defer list to subscribe to the
# all-decrypted event
time.sleep(2)
local_gen_before_sync = results
self.wait_for_sync()
gen, _, changes = self.db1.whats_changed(local_gen_before_sync)
self.assertEqual(1, len(changes))
self.assertEqual(doc2.doc_id, changes[0][0])
self.assertEqual(1, gen - local_gen_before_sync)
self.assertGetEncryptedDoc(
self.db2, doc1.doc_id, doc1.rev, tests.simple_doc, False)
self.assertGetEncryptedDoc(
self.db1, doc2.doc_id, doc2.rev, tests.nested_doc, False)
d.addCallback(_assert_successful_sync)
return d