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


Python models.SimplifiedSyncLog类代码示例

本文整理汇总了Python中casexml.apps.phone.models.SimplifiedSyncLog的典型用法代码示例。如果您正苦于以下问题:Python SimplifiedSyncLog类的具体用法?Python SimplifiedSyncLog怎么用?Python SimplifiedSyncLog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SimplifiedSyncLog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_sync_log

    def test_sync_log(self):
        from casexml.apps.phone.models import SyncLog, SimplifiedSyncLog
        from corehq.apps.users.models import WebUser, CommCareUser
        from casexml.apps.phone.models import get_sync_log_class_by_format

        web_user = WebUser.create(
            domain=self.domain_name,
            username='webuser_4',
            password='secret',
            email='[email protected]',
        )
        mobile_user = CommCareUser.create(
            self.domain_name, 'mobile_user1', 'secret'
        )
        other_user = CommCareUser.create(
            'other_domain', 'mobile_user2', 'secret'
        )
        self.addCleanup(other_user.delete)

        l1 = SyncLog(user_id=web_user._id)
        l1.save()
        l2 = SimplifiedSyncLog(user_id=mobile_user._id)
        l2.save()
        other_log = SyncLog(user_id=other_user._id)
        other_log.save()

        def _synclog_to_class(doc):
            if doc['doc_type'] == 'SyncLog':
                return get_sync_log_class_by_format(doc.get('log_format'))

        expected_docs = [web_user, mobile_user, l1, l2]
        not_expected_docs = [other_user, other_log]
        self._dump_and_load(expected_docs, not_expected_docs, doc_to_doc_class=_synclog_to_class)
开发者ID:,项目名称:,代码行数:33,代码来源:

示例2: test_prune_self_indexing

 def test_prune_self_indexing(self):
     [id] = ['recursive']
     tree = IndexTree(indices={
         id: convert_list_to_dict([id]),
     })
     sync_log = SimplifiedSyncLog(index_tree=tree, case_ids_on_phone=set([id]))
     sync_log.prune_case(id)
     self.assertFalse(id in sync_log.case_ids_on_phone)
     self.assertFalse(id in sync_log.dependent_case_ids_on_phone)
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:9,代码来源:test_index_tree.py

示例3: test_prune_multiple_children

    def test_prune_multiple_children(self):
        [grandparent_id, parent_id, child_id_1, child_id_2] = all_ids = ['rickard', 'ned', 'bran', 'arya']
        tree = IndexTree(indices={
            child_id_1: convert_list_to_dict([parent_id]),
            child_id_2: convert_list_to_dict([parent_id]),
            parent_id: convert_list_to_dict([grandparent_id]),
        })
        sync_log = SimplifiedSyncLog(index_tree=tree, case_ids_on_phone=set(all_ids))

        # first prune the parent and grandparent
        sync_log.prune_case(grandparent_id)
        sync_log.prune_case(parent_id)
        self.assertTrue(grandparent_id in sync_log.case_ids_on_phone)
        self.assertTrue(grandparent_id in sync_log.dependent_case_ids_on_phone)
        self.assertTrue(parent_id in sync_log.case_ids_on_phone)
        self.assertTrue(parent_id in sync_log.dependent_case_ids_on_phone)

        # just pruning one child should preserve the parent index
        sync_log.prune_case(child_id_1)
        self.assertTrue(grandparent_id in sync_log.case_ids_on_phone)
        self.assertTrue(grandparent_id in sync_log.dependent_case_ids_on_phone)
        self.assertTrue(parent_id in sync_log.case_ids_on_phone)
        self.assertTrue(parent_id in sync_log.dependent_case_ids_on_phone)
        self.assertFalse(child_id_1 in sync_log.case_ids_on_phone)

        # pruning the other one should wipe it
        sync_log.prune_case(child_id_2)
        for id in all_ids:
            self.assertFalse(id in sync_log.case_ids_on_phone)
            self.assertFalse(id in sync_log.dependent_case_ids_on_phone)
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:30,代码来源:test_index_tree.py

示例4: test_purge_extension_non_dependent_host

 def test_purge_extension_non_dependent_host(self):
     """Purging an extension should not remove the host or itself if the host is directly owned
     """
     [host_id, extension_id] = all_ids = ['host', 'extension']
     extension_tree = IndexTree(indices={
         extension_id: convert_list_to_dict([host_id]),
     })
     sync_log = SimplifiedSyncLog(extension_index_tree=extension_tree,
                                  case_ids_on_phone=set(all_ids))
     sync_log.purge(extension_id)
     self.assertTrue(extension_id in sync_log.case_ids_on_phone)
     self.assertTrue(host_id in sync_log.case_ids_on_phone)
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:12,代码来源:test_index_tree.py

示例5: test_purge_partial_children

 def test_purge_partial_children(self):
     [parent_id, child_id_1, child_id_2] = all_ids = ['parent', 'child1', 'child2']
     tree = IndexTree(indices={
         child_id_1: convert_list_to_dict([parent_id]),
         child_id_2: convert_list_to_dict([parent_id]),
     })
     sync_log = SimplifiedSyncLog(
         index_tree=tree,
         case_ids_on_phone=set(all_ids),
         dependent_case_ids_on_phone=set([parent_id, child_id_2])
     )
     # this used to fail with an AssertionError
     sync_log.purge(parent_id)
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:13,代码来源:test_index_tree.py

示例6: test_purge_extension

    def test_purge_extension(self, ):
        """Purging extension removes host
        """
        [host_id, extension_id] = all_ids = ['host', 'extension']
        extension_tree = IndexTree(indices={
            extension_id: convert_list_to_dict([host_id]),
        })
        sync_log = SimplifiedSyncLog(extension_index_tree=extension_tree,
                                     dependent_case_ids_on_phone=set([host_id]),
                                     case_ids_on_phone=set(all_ids))

        sync_log.purge(extension_id)
        self.assertFalse(extension_id in sync_log.case_ids_on_phone)
        self.assertFalse(host_id in sync_log.case_ids_on_phone)
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:14,代码来源:test_index_tree.py

示例7: test_purge_extension_host_has_multiple_extensions

 def test_purge_extension_host_has_multiple_extensions(self):
     """Purging an extension should remove host and its other extensions
     """
     [host_id, extension_id, extension_id_2] = all_ids = ['host', 'extension', 'extension_2']
     extension_tree = IndexTree(indices={
         extension_id: convert_list_to_dict([host_id]),
         extension_id_2: convert_list_to_dict([host_id]),
     })
     sync_log = SimplifiedSyncLog(extension_index_tree=extension_tree,
                                  dependent_case_ids_on_phone=set([host_id, extension_id_2]),
                                  case_ids_on_phone=set(all_ids))
     sync_log.purge(extension_id)
     self.assertFalse(extension_id in sync_log.case_ids_on_phone)
     self.assertFalse(extension_id_2 in sync_log.case_ids_on_phone)
     self.assertFalse(host_id in sync_log.case_ids_on_phone)
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:15,代码来源:test_index_tree.py

示例8: test_open_extension_of_extension

    def test_open_extension_of_extension(self):
        all_ids = ['host', 'extension', 'extension_of_extension']
        host_id, extension_id, extension_of_extension_id = all_ids
        extension_tree = IndexTree(indices={
            extension_id: convert_list_to_dict([host_id]),
            extension_of_extension_id: convert_list_to_dict([extension_id]),
        })
        sync_log = SimplifiedSyncLog(extension_index_tree=extension_tree,
                                     dependent_case_ids_on_phone=set([host_id, extension_id]),
                                     closed_cases=set([host_id, extension_id]),
                                     case_ids_on_phone=set(all_ids))

        sync_log.purge(host_id)
        self.assertFalse(host_id in sync_log.case_ids_on_phone)
        self.assertFalse(extension_id in sync_log.case_ids_on_phone)
        self.assertFalse(extension_of_extension_id in sync_log.case_ids_on_phone)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:16,代码来源:test_index_tree.py

示例9: handle

    def handle(self, *args, **options):
        from casexml.apps.phone.models import properly_wrap_sync_log, SyncLog, SimplifiedSyncLog

        if len(args) < 1:
            print "Usage: ./manage.py sync_log_debugger <filename1> [<filename2>] [<filename3>]..."
            sys.exit(0)

        logs = []
        log_names = []
        for filename in args:
            if os.path.isdir(filename):
                filenames = [os.path.join(filename, item) for item in sorted(os.listdir(filename))]
            else:
                filenames = [filename]

            for filename in filenames:
                log_name = os.path.basename(filename)
                log_names.append(log_name)
                with open(filename) as f:
                    wrapped_log = properly_wrap_sync_log(json.loads(f.read()))
                    logs.append(wrapped_log)
                    if isinstance(wrapped_log, SyncLog):
                        log_names.append("migrated-{}".format(log_name))
                        logs.append(SimplifiedSyncLog.from_other_format(wrapped_log))
                    elif getattr(wrapped_log, "migrated_from", None):
                        log_names.append("migrated_from-{}".format(log_name))
                        logs.append(properly_wrap_sync_log(wrapped_log.to_json()["migrated_from"]))

        print "state hashes"
        for i in range(len(log_names)):
            print "{} ({}): {}".format(log_names[i], logs[i]._id, logs[i].get_state_hash())

        print "\ncase diffs"
        for i in range(len(log_names)):
            for j in range(len(log_names)):
                if i != j:
                    case_diff = set(logs[i].get_footprint_of_cases_on_phone()) - set(
                        logs[j].get_footprint_of_cases_on_phone()
                    )
                    if case_diff:
                        print "cases on {} and not {}: {}".format(
                            log_names[i], log_names[j], ", ".join(sorted(case_diff))
                        )

        if options["debugger"]:
            union_of_ids = set().union(*[set(log.get_footprint_of_cases_on_phone()) for log in logs])
            intersection_of_ids = set().intersection(*[set(log.get_footprint_of_cases_on_phone()) for log in logs])
            import pdb

            pdb.set_trace()

        if options["check_hash"]:
            log_to_check = logs[int(options["index"])]
            result = _brute_force_search(
                log_to_check.case_ids_on_phone, options["check_hash"], depth=int(options["depth"])
            )
            if result:
                print "check successful - missing ids {}".format(result)
            else:
                print "no match found"
开发者ID:johan--,项目名称:commcare-hq,代码行数:60,代码来源:sync_log_debugger.py

示例10: test_indices

 def test_indices(self):
     parents = ["catelyn", "ned", "cersei", "jaimie"]
     index_structure = {
         "bran": [{"identifier": "mom", "referenced_id": "catelyn"}, {"identifier": "dad", "referenced_id": "ned"}],
         "myrcella": [
             {"identifier": "mom", "referenced_id": "cersei"},
             {"identifier": "dad", "referenced_id": "jaimie"},
         ],
     }
     sync_log = SyncLog(
         cases_on_phone=[
             CaseState(case_id="bran", indices=[CommCareCaseIndex(**args) for args in index_structure["bran"]]),
             CaseState(
                 case_id="myrcella", indices=[CommCareCaseIndex(**args) for args in index_structure["myrcella"]]
             ),
         ],
         dependent_cases_on_phone=[CaseState(case_id=parent) for parent in parents],
     )
     migrated = SimplifiedSyncLog.from_other_format(sync_log)
     for case_id, indices in index_structure.items():
         self.assertTrue(case_id in migrated.index_tree.indices)
         for index in indices:
             self.assertEqual(index["referenced_id"], migrated.index_tree.indices[case_id][index["identifier"]])
     for parent in parents:
         self.assertTrue(parent in migrated.case_ids_on_phone)
         self.assertTrue(parent in migrated.dependent_case_ids_on_phone)
开发者ID:johan--,项目名称:commcare-hq,代码行数:26,代码来源:test_new_sync.py

示例11: test_cases_on_phone

 def test_cases_on_phone(self):
     case_ids = ["nymeria", "lady"]
     sync_log = SyncLog(cases_on_phone=[CaseState(case_id=case_id) for case_id in case_ids])
     migrated = SimplifiedSyncLog.from_other_format(sync_log)
     for case_id in case_ids:
         self.assertTrue(case_id in migrated.case_ids_on_phone)
         self.assertFalse(case_id in migrated.dependent_case_ids_on_phone)
开发者ID:johan--,项目名称:commcare-hq,代码行数:7,代码来源:test_new_sync.py

示例12: _new_sync_log

 def _new_sync_log(self):
     previous_log_id = None if self.is_initial else self.last_sync_log._id
     new_synclog = SimplifiedSyncLog(
         _id=uuid.uuid1().hex.lower(),
         domain=self.restore_user.domain,
         build_id=self.params.app_id,
         user_id=self.restore_user.user_id,
         owner_ids_on_phone=set(self.owner_ids),
         date=datetime.utcnow(),
         previous_log_id=previous_log_id,
         extensions_checked=True,
         device_id=self.params.device_id,
     )
     if self.is_livequery:
         new_synclog.log_format = LOG_FORMAT_LIVEQUERY
     return new_synclog
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:16,代码来源:restore.py

示例13: test_indices

 def test_indices(self):
     parents = ['catelyn', 'ned', 'cersei', 'jaimie']
     index_structure = {
         'bran': [
             {'identifier': 'mom', 'referenced_id': 'catelyn'},
             {'identifier': 'dad', 'referenced_id': 'ned'},
         ],
         'myrcella': [
             {'identifier': 'mom', 'referenced_id': 'cersei'},
             {'identifier': 'dad', 'referenced_id': 'jaimie'},
         ]
     }
     sync_log = SyncLog(
         cases_on_phone=[
             CaseState(case_id='bran', indices=[
                 CommCareCaseIndex(**args) for args in index_structure['bran']
             ]),
             CaseState(case_id='myrcella', indices=[
                 CommCareCaseIndex(**args) for args in index_structure['myrcella']
             ])
         ],
         dependent_cases_on_phone=[
             CaseState(case_id=parent) for parent in parents
         ]
     )
     migrated = SimplifiedSyncLog.from_other_format(sync_log)
     for case_id, indices in index_structure.items():
         self.assertTrue(case_id in migrated.index_tree.indices)
         for index in indices:
             self.assertEqual(index['referenced_id'],
                              migrated.index_tree.indices[case_id][index['identifier']])
     for parent in parents:
         self.assertTrue(parent in migrated.case_ids_on_phone)
         self.assertTrue(parent in migrated.dependent_case_ids_on_phone)
开发者ID:ekush,项目名称:commcare-hq,代码行数:34,代码来源:test_new_sync.py

示例14: test_prune_circular_loops

    def test_prune_circular_loops(self):
        [peer_id_1, peer_id_2] = all_ids = ['jaime', 'cersei']
        tree = IndexTree(indices={
            peer_id_1: convert_list_to_dict([peer_id_2]),
            peer_id_2: convert_list_to_dict([peer_id_1]),
        })
        sync_log = SimplifiedSyncLog(index_tree=tree, case_ids_on_phone=set(all_ids))

        # pruning one peer should keep everything around
        sync_log.prune_case(peer_id_1)
        for id in all_ids:
            self.assertTrue(id in sync_log.case_ids_on_phone)

        # pruning the second peer should remove everything
        sync_log.prune_case(peer_id_2)
        for id in all_ids:
            self.assertFalse(id in sync_log.case_ids_on_phone)
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:17,代码来源:test_index_tree.py

示例15: test_prune_parent_then_child

    def test_prune_parent_then_child(self):
        [parent_id, child_id] = all_ids = ['parent', 'child']
        tree = IndexTree(indices={
            child_id: convert_list_to_dict([parent_id]),
        })
        sync_log = SimplifiedSyncLog(index_tree=tree, case_ids_on_phone=set(all_ids))
        # this has no effect
        sync_log.prune_case(parent_id)
        self.assertTrue(child_id in sync_log.case_ids_on_phone)
        self.assertTrue(parent_id in sync_log.case_ids_on_phone)
        self.assertFalse(child_id in sync_log.dependent_case_ids_on_phone)
        self.assertTrue(parent_id in sync_log.dependent_case_ids_on_phone)

        # this should prune it entirely
        sync_log.prune_case(child_id)
        self.assertFalse(child_id in sync_log.case_ids_on_phone)
        self.assertFalse(parent_id in sync_log.case_ids_on_phone)
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:17,代码来源:test_index_tree.py


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