本文整理汇总了Python中casexml.apps.phone.models.SimplifiedSyncLog.save方法的典型用法代码示例。如果您正苦于以下问题:Python SimplifiedSyncLog.save方法的具体用法?Python SimplifiedSyncLog.save怎么用?Python SimplifiedSyncLog.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类casexml.apps.phone.models.SimplifiedSyncLog
的用法示例。
在下文中一共展示了SimplifiedSyncLog.save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sync_log
# 需要导入模块: from casexml.apps.phone.models import SimplifiedSyncLog [as 别名]
# 或者: from casexml.apps.phone.models.SimplifiedSyncLog import save [as 别名]
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)
示例2: test_copy_payload
# 需要导入模块: from casexml.apps.phone.models import SimplifiedSyncLog [as 别名]
# 或者: from casexml.apps.phone.models.SimplifiedSyncLog import save [as 别名]
def test_copy_payload(self):
sync_log = SimplifiedSyncLog(case_ids_on_phone=set(["case-1", "case-2"]))
sync_log.save()
payload = dummy_restore_xml(sync_log._id).strip()
fd, path = tempfile.mkstemp()
with os.fdopen(fd, "wb") as f:
f.write(payload)
with open(path, "r") as f:
updated_fileref = copy_payload_and_synclog_and_get_new_file(f)
updated_payload = updated_fileref.file.read()
updated_id = synclog_id_from_restore_payload(updated_payload)
self.assertNotEqual(sync_log._id, updated_id)
self.assertTrue(_restore_id_block(updated_id) in updated_payload)
self.assertFalse(sync_log._id in updated_payload)
updated_log = get_properly_wrapped_sync_log(updated_id)
self.assertEqual(updated_log.case_ids_on_phone, sync_log.case_ids_on_phone)