本文整理汇总了Python中casexml.apps.case.mock.CaseBlock.as_string方法的典型用法代码示例。如果您正苦于以下问题:Python CaseBlock.as_string方法的具体用法?Python CaseBlock.as_string怎么用?Python CaseBlock.as_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类casexml.apps.case.mock.CaseBlock
的用法示例。
在下文中一共展示了CaseBlock.as_string方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_multiple_case_blocks_some_deleted
# 需要导入模块: from casexml.apps.case.mock import CaseBlock [as 别名]
# 或者: from casexml.apps.case.mock.CaseBlock import as_string [as 别名]
def test_multiple_case_blocks_some_deleted(self, rebuild_case):
""" Don't rebuild deleted cases """
case_ids = [uuid.uuid4().hex, uuid.uuid4().hex, uuid.uuid4().hex]
for i, case_id in enumerate(case_ids):
if i == 0:
# only the first case is owned by the user getting retired
owner_id = self.other_user._id
else:
owner_id = self.commcare_user._id
caseblock = CaseBlock(
create=True,
case_id=case_id,
owner_id=owner_id,
user_id=self.commcare_user._id,
)
submit_case_blocks(caseblock.as_string(), self.domain, user_id=self.other_user._id)
self.other_user.retire()
detail = UserArchivedRebuild(user_id=self.other_user.user_id)
expected_call_args = [mock.call(self.domain, case_id, detail) for case_id in case_ids[1:]]
self.assertEqual(rebuild_case.call_count, len(case_ids) - 1)
self.assertItemsEqual(rebuild_case.call_args_list, expected_call_args)
示例2: test_forms_touching_live_case_not_deleted
# 需要导入模块: from casexml.apps.case.mock import CaseBlock [as 别名]
# 或者: from casexml.apps.case.mock.CaseBlock import as_string [as 别名]
def test_forms_touching_live_case_not_deleted(self):
case_id = uuid.uuid4().hex
caseblock = CaseBlock(
create=True,
case_id=case_id,
owner_id=self.commcare_user._id,
user_id=self.commcare_user._id,
)
xform, _ = submit_case_blocks(caseblock.as_string().decode('utf-8'), self.domain)
# other user submits form against the case and another case not owned by the user
# should NOT get deleted since this form touches a case that's still 'alive'
double_case_xform, _ = submit_case_blocks([
CaseBlock(
create=False,
case_id=case_id,
).as_string().decode('utf-8'),
CaseBlock(
create=True,
case_id=uuid.uuid4().hex,
owner_id=self.other_user._id,
user_id=self.other_user._id,
).as_string().decode('utf-8')
], self.domain, user_id=self.other_user._id)
self.commcare_user.retire()
self.assertTrue(FormAccessors(self.domain).get_form(xform.form_id).is_deleted)
self.assertFalse(FormAccessors(self.domain).get_form(double_case_xform.form_id).is_deleted)
# When the other user is deleted then the form should get deleted since it no-longer touches
# any 'live' cases.
self.other_user.retire()
self.assertTrue(FormAccessors(self.domain).get_form(double_case_xform.form_id).is_deleted)
示例3: test_all_case_forms_deleted
# 需要导入模块: from casexml.apps.case.mock import CaseBlock [as 别名]
# 或者: from casexml.apps.case.mock.CaseBlock import as_string [as 别名]
def test_all_case_forms_deleted(self):
from corehq.apps.callcenter.sync_user_case import sync_usercase
sync_usercase(self.commcare_user)
user_case_id = self.commcare_user.get_usercase_id()
# other user submits form against the case (should get deleted)
caseblock = CaseBlock(
create=False,
case_id=user_case_id,
)
submit_case_blocks(caseblock.as_string().decode('utf-8'), self.domain, user_id=self.other_user._id)
case_ids = CaseAccessors(self.domain).get_case_ids_by_owners([self.commcare_user._id])
self.assertEqual(1, len(case_ids))
form_ids = FormAccessors(self.domain).get_form_ids_for_user(self.commcare_user._id)
self.assertEqual(0, len(form_ids))
user_case = self.commcare_user.get_usercase()
self.assertEqual(2, len(user_case.xform_ids))
self.commcare_user.retire()
for form_id in user_case.xform_ids:
self.assertTrue(FormAccessors(self.domain).get_form(form_id).is_deleted)
self.assertTrue(CaseAccessors(self.domain).get_case(user_case_id).is_deleted)
示例4: test_edit_an_error
# 需要导入模块: from casexml.apps.case.mock import CaseBlock [as 别名]
# 或者: from casexml.apps.case.mock.CaseBlock import as_string [as 别名]
def test_edit_an_error(self):
form_id = uuid.uuid4().hex
case_block = CaseBlock(
create=True,
case_id='', # this should cause the submission to error
case_type='person',
owner_id='some-owner',
)
form, _ = submit_case_blocks(case_block.as_string(), domain=self.domain, form_id=form_id)
self.assertTrue(form.is_error)
self.assertTrue('IllegalCaseId' in form.problem)
case_block.case_id = uuid.uuid4().hex
form, _ = submit_case_blocks(case_block.as_string(), domain=self.domain, form_id=form_id)
self.assertFalse(form.is_error)
self.assertEqual(None, getattr(form, 'problem', None))