当前位置: 首页>>代码示例>>Python>>正文


Python SQLCipherDatabase.whats_changed方法代码示例

本文整理汇总了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
开发者ID:Moscarda,项目名称:soledad,代码行数:104,代码来源:test_sync_target.py


注:本文中的leap.soledad.client.sqlcipher.SQLCipherDatabase.whats_changed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。