本文整理汇总了Python中casexml.apps.phone.restore.RestoreConfig.get_payload方法的典型用法代码示例。如果您正苦于以下问题:Python RestoreConfig.get_payload方法的具体用法?Python RestoreConfig.get_payload怎么用?Python RestoreConfig.get_payload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类casexml.apps.phone.restore.RestoreConfig
的用法示例。
在下文中一共展示了RestoreConfig.get_payload方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_new_then_old_sync
# 需要导入模块: from casexml.apps.phone.restore import RestoreConfig [as 别名]
# 或者: from casexml.apps.phone.restore.RestoreConfig import get_payload [as 别名]
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()
示例2: test_initial_cache
# 需要导入模块: from casexml.apps.phone.restore import RestoreConfig [as 别名]
# 或者: from casexml.apps.phone.restore.RestoreConfig import get_payload [as 别名]
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())
示例3: _get_ota_balance_blocks
# 需要导入模块: from casexml.apps.phone.restore import RestoreConfig [as 别名]
# 或者: from casexml.apps.phone.restore.RestoreConfig import get_payload [as 别名]
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())
示例4: generate_restore_payload
# 需要导入模块: from casexml.apps.phone.restore import RestoreConfig [as 别名]
# 或者: from casexml.apps.phone.restore.RestoreConfig import get_payload [as 别名]
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()
示例5: setUp
# 需要导入模块: from casexml.apps.phone.restore import RestoreConfig [as 别名]
# 或者: from casexml.apps.phone.restore.RestoreConfig import get_payload [as 别名]
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())
示例6: _get_ota_balance_blocks
# 需要导入模块: from casexml.apps.phone.restore import RestoreConfig [as 别名]
# 或者: from casexml.apps.phone.restore.RestoreConfig import get_payload [as 别名]
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())
示例7: test_no_factor_set
# 需要导入模块: from casexml.apps.phone.restore import RestoreConfig [as 别名]
# 或者: from casexml.apps.phone.restore.RestoreConfig import get_payload [as 别名]
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)
示例8: setUp
# 需要导入模块: from casexml.apps.phone.restore import RestoreConfig [as 别名]
# 或者: from casexml.apps.phone.restore.RestoreConfig import get_payload [as 别名]
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())
示例9: prime_restore
# 需要导入模块: from casexml.apps.phone.restore import RestoreConfig [as 别名]
# 或者: from casexml.apps.phone.restore.RestoreConfig import get_payload [as 别名]
def prime_restore(username_or_id, domain, version, cache_timeout_hours,
overwrite_cache, check_cache_only):
couch_user = get_user(username_or_id, domain)
try:
project = couch_user.project
restore_config = RestoreConfig(
project=project,
restore_user=couch_user.to_ota_restore_user(),
params=RestoreParams(
version=version,
include_item_count=True,
),
cache_settings=RestoreCacheSettings(
force_cache=True,
cache_timeout=cache_timeout_hours * 60 * 60,
overwrite_cache=overwrite_cache
)
)
if check_cache_only:
cached_payload = _get_cached_payload(restore_config)
ret = u'Restore cache {} for user: {}'.format(
'EXISTS' if cached_payload else 'does not exist',
couch_user.human_friendly_name,
)
else:
restore_config.get_payload()
cached_payload = _get_cached_payload(restore_config)
if cached_payload:
ret = u'Restore cached successfully for user: {}'.format(
couch_user.human_friendly_name,
)
else:
raise PrimeRestoreException(u"Restore completed by cache still empty")
except Exception as e:
raise PrimeRestoreException(u'Error processing user: {}. Error was: {}'.format(
couch_user.human_friendly_name, str(e)
))
return {"messages": ret}
示例10: test_legacy_support_toggle
# 需要导入模块: from casexml.apps.phone.restore import RestoreConfig [as 别名]
# 或者: from casexml.apps.phone.restore.RestoreConfig import get_payload [as 别名]
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},
)
示例11: handle
# 需要导入模块: from casexml.apps.phone.restore import RestoreConfig [as 别名]
# 或者: from casexml.apps.phone.restore.RestoreConfig import get_payload [as 别名]
def handle(self, username, **options):
couch_user = CommCareUser.get_by_username(username)
project = couch_user.project
restore_config = RestoreConfig(
project=project,
restore_user=couch_user.to_ota_restore_user(),
params=RestoreParams(
version=V2,
include_item_count=True,
),
cache_settings=RestoreCacheSettings(
force_cache=True,
cache_timeout=1,
overwrite_cache=False,
)
)
with resident_set_size():
restore_config.get_payload()
示例12: test_old_then_new_sync
# 需要导入模块: from casexml.apps.phone.restore import RestoreConfig [as 别名]
# 或者: from casexml.apps.phone.restore.RestoreConfig import get_payload [as 别名]
def test_old_then_new_sync(self):
restore_config = RestoreConfig(self.project, user=self.user)
case = CaseFactory(domain=self.project.name, case_defaults={'owner_id': self.user_id}).create_case()
restore_payload = restore_config.get_payload().as_string()
self.assertTrue(case._id in restore_payload)
sync_log = synclog_from_restore_payload(restore_payload)
self.assertEqual(SyncLog, type(sync_log))
restore_config = RestoreConfig(self.project, user=self.user,
params=RestoreParams(sync_log_id=sync_log._id))
original_payload_back = restore_config.get_payload().as_string()
self.assertFalse(case._id in original_payload_back)
self.assertEqual(SyncLog, type(synclog_from_restore_payload(original_payload_back)))
OWNERSHIP_CLEANLINESS_RESTORE.set(self.domain, enabled=True, namespace='domain')
restore_config = RestoreConfig(self.project, user=self.user,
params=RestoreParams(sync_log_id=sync_log._id),
cache_settings=RestoreCacheSettings(overwrite_cache=True))
migrated_payload_back = restore_config.get_payload().as_string()
self.assertFalse(case._id in migrated_payload_back)
self.assertEqual(SimplifiedSyncLog, type(synclog_from_restore_payload(migrated_payload_back)))
OWNERSHIP_CLEANLINESS_RESTORE.set(self.domain, enabled=False, namespace='domain')
示例13: test_simple_factor
# 需要导入模块: from casexml.apps.phone.restore import RestoreConfig [as 别名]
# 或者: from casexml.apps.phone.restore.RestoreConfig import get_payload [as 别名]
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)))
示例14: generate_restore_payload
# 需要导入模块: from casexml.apps.phone.restore import RestoreConfig [as 别名]
# 或者: from casexml.apps.phone.restore.RestoreConfig import get_payload [as 别名]
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()
示例15: test_simple_factor
# 需要导入模块: from casexml.apps.phone.restore import RestoreConfig [as 别名]
# 或者: from casexml.apps.phone.restore.RestoreConfig import get_payload [as 别名]
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(
project=self.domain,
restore_user=self.user.to_ota_restore_user(),
params=RestoreParams(version=V2),
)
payload_string = restore_config.get_payload().as_string()
caseblocks = extract_caseblocks_from_xml(payload_string)
self.assertEqual(6, len(caseblocks))
self.assertEqual(1, len([cb for cb in caseblocks if cb.get_case_id() == case1.case_id]))
self.assertEqual(1, len([cb for cb in caseblocks if cb.get_case_id() == case2.case_id]))
self.assertEqual(3, len([cb for cb in caseblocks if case1.name in cb.get_case_name()]))
self.assertEqual(3, len([cb for cb in caseblocks if case2.name in cb.get_case_name()]))