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


Python restore.RestoreConfig类代码示例

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


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

示例1: generate_restore_payload

def generate_restore_payload(project, user, restore_id="", version=V1, state_hash="",
                             items=False, overwrite_cache=False, force_cache=False):
    """
    Gets an XML payload suitable for OTA restore.

        user:          who the payload is for
        restore_id:    last sync token for this user
        version:       the restore API version

        returns: the xml payload of the sync operation
    """
    config = RestoreConfig(
        project=project,
        user=user,
        params=RestoreParams(
            sync_log_id=restore_id,
            version=version,
            state_hash=state_hash,
            include_item_count=items
        ),
        cache_settings=RestoreCacheSettings(
            overwrite_cache=overwrite_cache,
            force_cache=force_cache,
        )
    )
    return config.get_payload().as_string()
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:26,代码来源:utils.py

示例2: get_restore_response

def get_restore_response(domain, couch_user, app_id=None, since=None, version='1.0',
                         state=None, items=False, force_cache=False,
                         cache_timeout=None, overwrite_cache=False,
                         force_restore_mode=None):
    # not a view just a view util
    if not couch_user.is_commcare_user():
        return HttpResponse("No linked chw found for %s" % couch_user.username,
                            status=401)  # Authentication Failure
    elif domain != couch_user.domain:
        return HttpResponse("%s was not in the domain %s" % (couch_user.username, domain),
                            status=401)

    project = Domain.get_by_name(domain)
    app = get_app(domain, app_id) if app_id else None
    restore_config = RestoreConfig(
        project=project,
        user=couch_user.to_casexml_user(),
        params=RestoreParams(
            sync_log_id=since,
            version=version,
            state_hash=state,
            include_item_count=items,
            force_restore_mode=force_restore_mode,
            app=app,
        ),
        cache_settings=RestoreCacheSettings(
            force_cache=force_cache,
            cache_timeout=cache_timeout,
            overwrite_cache=overwrite_cache
        ),
    )
    return restore_config.get_response()
开发者ID:bazuzi,项目名称:commcare-hq,代码行数:32,代码来源:views.py

示例3: setUp

    def setUp(self):
        super(CommTrackSyncTest, self).setUp()
        # reused stuff
        self.casexml_user = self.user.to_casexml_user()
        self.sp_block = CaseBlock(
            case_id=self.sp._id,
            version=V2,
        ).as_xml()

        # bootstrap ota stuff
        self.ct_settings.consumption_config = ConsumptionConfig(
            min_transactions=0,
            min_window=0,
            optimal_window=60,
        )
        self.ct_settings.ota_restore_config = StockRestoreConfig(
            section_to_consumption_types={'stock': 'consumption'}
        )
        set_default_monthly_consumption_for_domain(self.domain.name, 5)
        self.ota_settings = self.ct_settings.get_ota_restore_settings()

        # get initial restore token
        restore_config = RestoreConfig(
            self.casexml_user,
            version=V2,
            stock_settings=self.ota_settings,
        )
        self.sync_log_id = synclog_id_from_restore_payload(restore_config.get_payload())
开发者ID:SEL-Columbia,项目名称:commcare-hq,代码行数:28,代码来源:test_xml.py

示例4: _get_ota_balance_blocks

def _get_ota_balance_blocks(project, user):
    restore_config = RestoreConfig(
        project=project,
        restore_user=user.to_ota_restore_user(),
        params=RestoreParams(version=V2),
    )
    return extract_balance_xml(restore_config.get_payload().as_string())
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:7,代码来源:test_xml.py

示例5: _get_ota_balance_blocks

def _get_ota_balance_blocks(ct_settings, user):
    ota_settings = ct_settings.get_ota_restore_settings()
    restore_config = RestoreConfig(
        user.to_casexml_user(),
        version=V2,
        stock_settings=ota_settings,
    )
    return extract_balance_xml(restore_config.get_payload())
开发者ID:SEL-Columbia,项目名称:commcare-hq,代码行数:8,代码来源:test_xml.py

示例6: test_no_factor_set

 def test_no_factor_set(self):
     self.user.loadtest_factor = None
     self.user.save()
     case = self.factory.create_case()
     restore_config = RestoreConfig(self.user, version=V2)
     payload_string = restore_config.get_payload().as_string()
     caseblocks = extract_caseblocks_from_xml(payload_string)
     self.assertEqual(1, len(caseblocks))
     self.assertEqual(caseblocks[0].get_case_id(), case._id)
开发者ID:elbowink,项目名称:commcare-hq,代码行数:9,代码来源:test_loadtest_users.py

示例7: test_new_then_old_sync

 def test_new_then_old_sync(self):
     OWNERSHIP_CLEANLINESS_RESTORE.set(self.domain, enabled=True, namespace="domain")
     restore_config = RestoreConfig(self.project, user=self.user)
     sync_log = synclog_from_restore_payload(restore_config.get_payload().as_string())
     self.assertEqual(SimplifiedSyncLog, type(sync_log))
     OWNERSHIP_CLEANLINESS_RESTORE.set(self.domain, enabled=False, namespace="domain")
     restore_config = RestoreConfig(self.project, user=self.user, params=RestoreParams(sync_log_id=sync_log._id))
     with self.assertRaises(IncompatibleSyncLogType):
         restore_config.get_payload()
开发者ID:johan--,项目名称:commcare-hq,代码行数:9,代码来源:test_new_sync.py

示例8: setUp

    def setUp(self):
        delete_all_cases()
        delete_all_xforms()
        delete_all_sync_logs()

        self.user = User(user_id=USER_ID, username="syncguy", 
                         password="changeme", date_joined=datetime(2011, 6, 9)) 
        # this creates the initial blank sync token in the database
        restore_config = RestoreConfig(self.user)
        self.sync_log = synclog_from_restore_payload(restore_config.get_payload())
开发者ID:SEL-Columbia,项目名称:commcare-hq,代码行数:10,代码来源:test_sync_mode.py

示例9: test_initial_cache

    def test_initial_cache(self):
        restore_config = RestoreConfig(self.user, force_cache=True)
        original_payload = restore_config.get_payload()
        self.assertNotIsInstance(original_payload, CachedResponse)

        restore_config = RestoreConfig(self.user)
        cached_payload = restore_config.get_payload()
        self.assertIsInstance(cached_payload, CachedResponse)

        self.assertEqual(original_payload.as_string(), cached_payload.as_string())
开发者ID:aristide,项目名称:commcare-hq,代码行数:10,代码来源:test_sync_mode.py

示例10: test_legacy_support_toggle

    def test_legacy_support_toggle(self):
        restore_config = RestoreConfig(self.project, user=self.user)
        factory = CaseFactory(domain=self.project.name, case_defaults={"owner_id": self.user_id})
        # create a parent and child case (with index) from one user
        parent_id, child_id = [uuid.uuid4().hex for i in range(2)]
        factory.create_or_update_cases(
            [
                CaseStructure(
                    case_id=child_id,
                    attrs={"create": True},
                    indices=[
                        CaseIndex(
                            CaseStructure(case_id=parent_id, attrs={"create": True}),
                            relationship="child",
                            related_type="parent",
                        )
                    ],
                )
            ]
        )
        restore_payload = restore_config.get_payload().as_string()
        self.assertTrue(child_id in restore_payload)
        self.assertTrue(parent_id in restore_payload)
        sync_log = synclog_from_restore_payload(restore_payload)
        self.assertEqual(SimplifiedSyncLog, type(sync_log))
        # make both cases irrelevant by changing the owner ids
        factory.create_or_update_cases(
            [
                CaseStructure(case_id=parent_id, attrs={"owner_id": "different"}),
                CaseStructure(case_id=child_id, attrs={"owner_id": "different"}),
            ],
            form_extras={"last_sync_token": sync_log._id},
        )

        # doing it again should fail since they are no longer relevant

        # todo: add this back in when we add the assertion back. see SimplifiedSyncLog.prune_case
        # with self.assertRaises(SimplifiedSyncAssertionError):
        #     factory.create_or_update_cases([
        #         CaseStructure(case_id=child_id, attrs={'owner_id': 'different'}),
        #         CaseStructure(case_id=parent_id, attrs={'owner_id': 'different'}),
        #     ], form_extras={'last_sync_token': sync_log._id})

        # enabling the toggle should prevent the failure the second time
        # though we also need to hackily set the request object in the threadlocals
        LEGACY_SYNC_SUPPORT.set(self.domain, True, namespace="domain")
        request = JsonObject(domain=self.domain)
        set_request(request)
        factory.create_or_update_cases(
            [
                CaseStructure(case_id=child_id, attrs={"owner_id": "different"}),
                CaseStructure(case_id=parent_id, attrs={"owner_id": "different"}),
            ],
            form_extras={"last_sync_token": sync_log._id},
        )
开发者ID:johan--,项目名称:commcare-hq,代码行数:55,代码来源:test_new_sync.py

示例11: generate_restore_response

def generate_restore_response(project, user, restore_id="", version=V1, state_hash="", items=False):
    config = RestoreConfig(
        project=project,
        user=user,
        params=RestoreParams(
            sync_log_id=restore_id,
            version=version,
            state_hash=state_hash,
            include_item_count=items
        )
    )
    return config.get_response()
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:12,代码来源:utils.py

示例12: testCacheInvalidationAfterFileDelete

    def testCacheInvalidationAfterFileDelete(self):
        # first request should populate the cache
        original_payload = RestoreConfig(self.user, force_cache=True).get_payload()
        self.assertNotIsInstance(original_payload, CachedResponse)

        # Delete cached file
        os.remove(original_payload.get_filename())

        # resyncing should recreate the cache
        next_file = RestoreConfig(self.user).get_payload()
        self.assertNotIsInstance(next_file, CachedResponse)
        self.assertNotEqual(original_payload.get_filename(), next_file.get_filename())
开发者ID:aristide,项目名称:commcare-hq,代码行数:12,代码来源:test_sync_mode.py

示例13: test_simple_factor

 def test_simple_factor(self):
     self.user.loadtest_factor = 3
     self.user.save()
     case1 = self.factory.create_case(case_name='case1')
     case2 = self.factory.create_case(case_name='case2')
     restore_config = RestoreConfig(self.user, version=V2, domain=self.domain)
     payload_string = restore_config.get_payload().as_string()
     caseblocks = extract_caseblocks_from_xml(payload_string)
     self.assertEqual(6, len(caseblocks))
     self.assertEqual(1, len(filter(lambda cb: cb.get_case_id() == case1._id, caseblocks)))
     self.assertEqual(1, len(filter(lambda cb: cb.get_case_id() == case2._id, caseblocks)))
     self.assertEqual(3, len(filter(lambda cb: case1.name in cb.get_case_name(), caseblocks)))
     self.assertEqual(3, len(filter(lambda cb: case2.name in cb.get_case_name(), caseblocks)))
开发者ID:elbowink,项目名称:commcare-hq,代码行数:13,代码来源:test_loadtest_users.py

示例14: generate_restore_payload

def generate_restore_payload(user, restore_id="", version=V1, state_hash="",
                             items=False):
    """
    Gets an XML payload suitable for OTA restore.

        user:          who the payload is for
        restore_id:    last sync token for this user
        version:       the restore API version

        returns: the xml payload of the sync operation
    """
    config = RestoreConfig(user, restore_id, version, state_hash, items=items)
    return config.get_payload().as_string()
开发者ID:aristide,项目名称:commcare-hq,代码行数:13,代码来源:utils.py

示例15: get_restore_response

def get_restore_response(domain, couch_user, since=None, version='1.0', state=None):
    # not a view just a view util
    if not couch_user.is_commcare_user():
        return HttpResponse("No linked chw found for %s" % couch_user.username,
                            status=401)  # Authentication Failure
    elif domain != couch_user.domain:
        return HttpResponse("%s was not in the domain %s" % (couch_user.username, domain),
                            status=401)

    project = Domain.get_by_name(domain)
    restore_config = RestoreConfig(
        couch_user.to_casexml_user(), since, version, state,
        caching_enabled=project.ota_restore_caching,
    )
    return restore_config.get_response()
开发者ID:modonnell729,项目名称:commcare-hq,代码行数:15,代码来源:views.py


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