本文整理汇总了Python中corehq.form_processor.interfaces.FormProcessorInterface.post_case_blocks方法的典型用法代码示例。如果您正苦于以下问题:Python FormProcessorInterface.post_case_blocks方法的具体用法?Python FormProcessorInterface.post_case_blocks怎么用?Python FormProcessorInterface.post_case_blocks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.form_processor.interfaces.FormProcessorInterface
的用法示例。
在下文中一共展示了FormProcessorInterface.post_case_blocks方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testMismatch
# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_case_blocks [as 别名]
def testMismatch(self):
self.assertEqual(CaseStateHash(EMPTY_HASH), self.sync_log.get_state_hash())
c1 = CaseBlock(case_id="abc123", create=True,
owner_id=self.user.user_id).as_xml()
c2 = CaseBlock(case_id="123abc", create=True,
owner_id=self.user.user_id).as_xml()
FormProcessorInterface.post_case_blocks([c1, c2],
form_extras={"last_sync_token": self.sync_log.get_id})
self.sync_log = get_properly_wrapped_sync_log(self.sync_log.get_id)
real_hash = CaseStateHash("409c5c597fa2c2a693b769f0d2ad432b")
bad_hash = CaseStateHash("thisisntright")
self.assertEqual(real_hash, self.sync_log.get_state_hash())
generate_restore_payload(
self.project, self.user, self.sync_log.get_id,
version=V2, state_hash=str(real_hash)
)
try:
generate_restore_payload(self.project, self.user, self.sync_log.get_id,
version=V2, state_hash=str(bad_hash))
self.fail("Call to generate a payload with a bad hash should fail!")
except BadStateException, e:
self.assertEqual(real_hash, e.server_hash)
self.assertEqual(bad_hash, e.phone_hash)
self.assertEqual(2, len(e.case_ids))
self.assertTrue("abc123" in e.case_ids)
self.assertTrue("123abc" in e.case_ids)
示例2: setUp
# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_case_blocks [as 别名]
def setUp(self):
delete_all_xforms()
delete_all_cases()
FormProcessorInterface.post_case_blocks(
[CaseBlock(create=True, case_id="mother_case_id", case_type="mother-case").as_xml()],
{"domain": TEST_DOMAIN},
)
self.case_id = "test_case_1"
self.date_modified = datetime.utcnow() - timedelta(hours=1)
self.date_modified = self.date_modified.replace(microsecond=0)
FormProcessorInterface.post_case_blocks(
[
CaseBlock(
create=True,
case_id=self.case_id,
owner_id="owner",
user_id="user",
case_type="c_type",
case_name=("a" * TEST_NAME_LEN) + "123456789",
external_id="external_id",
date_modified=self.date_modified,
update={"foo": "bar"},
index={"mom": ("mother-case", "mother_case_id")},
).as_xml()
],
{"domain": TEST_DOMAIN},
)
instance = CommCareCase.get(self.case_id)
self.casedata = CaseData.create_or_update_from_instance(instance)
示例3: update_and_test
# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_case_blocks [as 别名]
def update_and_test(case_id, owner=None, should_have=None, should_not_have=None):
case_block = self.get_update_block(
case_id=case_id,
update={'greeting': "Hello!"},
owner_id=owner.get_id if owner else None,
)
FormProcessorInterface.post_case_blocks([case_block], {'domain': self.domain})
check_has_block(case_block, should_have, should_not_have, line_by_line=False)
示例4: add_parent_access
# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_case_blocks [as 别名]
def add_parent_access(self, user, case):
case_block = CaseBlock(
create=True,
case_id=uuid.uuid4().hex,
case_type='magic_map',
owner_id=user._id,
index={'parent': ('participant', case._id)}
).as_xml()
FormProcessorInterface.post_case_blocks([case_block], {'domain': self.domain})
示例5: create_and_test
# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_case_blocks [as 别名]
def create_and_test(case_id, user, owner, should_have, should_not_have):
case_block = self.get_create_block(
case_id=case_id,
type="case",
user_id=user.user_id,
owner_id=owner.get_id,
)
FormProcessorInterface.post_case_blocks([case_block], {'domain': self.domain})
check_has_block(case_block, should_have, should_not_have)
示例6: update_case_owner
# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_case_blocks [as 别名]
def update_case_owner(self, case, owner):
case_block = CaseBlock(
create=False,
case_id=case._id,
case_type='participant',
owner_id=owner._id,
user_id=owner._id,
).as_xml()
FormProcessorInterface.post_case_blocks([case_block], {'domain': self.domain})
示例7: _new_case
# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_case_blocks [as 别名]
def _new_case(cls, properties):
id = uuid.uuid4().hex
case_block = CaseBlock(
create=True,
case_id=id,
case_type=cls.case_type,
update=properties,
).as_xml()
FormProcessorInterface.post_case_blocks([case_block], {'domain': cls.domain})
return CommCareCase.get(id)
示例8: test_empty_name
# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_case_blocks [as 别名]
def test_empty_name(self):
case_id = "case_with_no_name"
FormProcessorInterface.post_case_blocks(
[CaseBlock(create=True, case_id=case_id, case_type="nameless").as_xml()], {"domain": TEST_DOMAIN}
)
instance = CommCareCase.get(case_id)
casedata = CaseData.create_or_update_from_instance(instance)
self.assertIsNotNone(casedata)
self.assertEqual("", casedata.name)
示例9: testRelationshipGetsSet
# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_case_blocks [as 别名]
def testRelationshipGetsSet(self):
user = User(user_id=USER_ID, username="", password="", date_joined="")
create_index = CaseBlock(
create=True,
case_id=self.CASE_ID,
user_id=USER_ID,
owner_id=USER_ID,
index={'mom': ('mother-case', self.MOTHER_CASE_ID, 'extension')},
).as_xml()
FormProcessorInterface.post_case_blocks([create_index])
check_user_has_case(self, user, create_index)
示例10: _make_some_cases
# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_case_blocks [as 别名]
def _make_some_cases(howmany, domain='dbcache-test'):
ids = [uuid.uuid4().hex for i in range(howmany)]
FormProcessorInterface.post_case_blocks([
CaseBlock(
create=True,
case_id=ids[i],
user_id='some-user',
update={
'my_index': i,
}
).as_xml() for i in range(howmany)
], {'domain': domain})
return ids
示例11: test_update
# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_case_blocks [as 别名]
def test_update(self):
FormProcessorInterface.post_case_blocks(
[
CaseBlock(
create=True, case_id="grand_mother_case_id", case_type="mother-case", owner_id="owner"
).as_xml()
],
{"domain": TEST_DOMAIN},
)
date_modified = datetime.utcnow()
FormProcessorInterface.post_case_blocks(
[
CaseBlock(
close=True,
case_id=self.case_id,
user_id="user2",
date_modified=date_modified,
index={"gmom": ("mother-case", "grand_mother_case_id")},
).as_xml()
],
{"domain": TEST_DOMAIN},
)
instance = CommCareCase.get(self.case_id)
updateddata = CaseData.create_or_update_from_instance(instance)
self.assertEqual(date_modified, updateddata.modified_on)
self.assertEqual("user2", updateddata.modified_by)
self.assertEqual(date_modified, updateddata.closed_on)
self.assertEqual(True, updateddata.closed)
actions = updateddata.actions.all()
self.assertEqual(5, len(actions))
for action in actions:
if action.index == 4:
self.assertEqual("close", action.action_type)
self.assertEqual(date.today(), action.date.date())
self.assertEqual(date.today(), action.server_date.date())
self.assertEqual("user2", action.user_id)
self.assertEqual("owner", action.case_owner)
self.assertEqual("c_type", action.case_type)
indices = self.casedata.indices.all()
self.assertEqual(2, len(indices))
self.assertEqual("gmom", indices[0].identifier)
self.assertEqual("mother-case", indices[0].referenced_type)
self.assertEqual("grand_mother_case_id", indices[0].referenced_id)
self.assertEqual("mom", indices[1].identifier)
self.assertEqual("mother-case", indices[1].referenced_type)
self.assertEqual("mother_case_id", indices[1].referenced_id)
示例12: _new_case
# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_case_blocks [as 别名]
def _new_case(self, index=None):
index = index or {}
id = uuid.uuid4().hex
case_block = CaseBlock(
create=True, case_id=id, case_type="person", owner_id=self.original_owner._id, index=index
).as_xml()
_, [case] = FormProcessorInterface.post_case_blocks([case_block], {"domain": self.domain})
return case
示例13: testSubmitToDeletedCase
# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_case_blocks [as 别名]
def testSubmitToDeletedCase(self):
# submitting to a deleted case should succeed and affect the case
case_id = 'immagetdeleted'
deleted_doc_type = 'CommCareCase-Deleted'
[xform, [case]] = FormProcessorInterface.post_case_blocks([
CaseBlock(create=True, case_id=case_id, user_id='whatever',
update={'foo': 'bar'}).as_xml()
])
self.assertEqual('bar', case.foo)
case = FormProcessorInterface.update_case_properties(case, doc_type=deleted_doc_type)
self.assertEqual(deleted_doc_type, case.doc_type)
[xform, [case]] = FormProcessorInterface.post_case_blocks([
CaseBlock(create=False, case_id=case_id, user_id='whatever',
update={'foo': 'not_bar'}).as_xml()
])
self.assertEqual('not_bar', case.foo)
self.assertEqual(deleted_doc_type, case.doc_type)
示例14: testArchiveModifiedOn
# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_case_blocks [as 别名]
def testArchiveModifiedOn(self):
case_id = uuid.uuid4().hex
now = datetime.utcnow().replace(microsecond=0)
earlier = now - timedelta(hours=1)
way_earlier = now - timedelta(days=1)
# make sure we timestamp everything so they have the right order
create_block = CaseBlock(case_id, create=True, date_modified=way_earlier)
FormProcessorInterface.post_case_blocks([create_block.as_xml()], form_extras={'received_on': way_earlier})
update_block = CaseBlock(case_id, update={'foo': 'bar'}, date_modified=earlier)
FormProcessorInterface.post_case_blocks([update_block.as_xml()], form_extras={'received_on': earlier})
case = CommCareCase.get(case_id)
self.assertEqual(earlier, case.modified_on)
second_form = XFormInstance.get(case.xform_ids[-1])
second_form.archive()
case = CommCareCase.get(case_id)
self.assertEqual(way_earlier, case.modified_on)
示例15: testBadIndexReferenceDomain
# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_case_blocks [as 别名]
def testBadIndexReferenceDomain(self):
case_in_other_domain = self.MOTHER_CASE_ID
parent_domain = 'parent'
child_domain = 'child'
FormProcessorInterface.post_case_blocks([
CaseBlock(create=True, case_id=case_in_other_domain, user_id=USER_ID).as_xml()
], form_extras={'domain': parent_domain})
block = CaseBlock(create=True, case_id='child-case-id', user_id=USER_ID,
index={'bad': ('bad-case', case_in_other_domain)})
xform, _ = FormProcessorInterface.post_case_blocks([block.as_xml()],
form_extras={'domain': child_domain})
self.assertTrue(xform.is_error)
self.assertEqual(xform.doc_type, 'XFormError')
self.assertIn('IllegalCaseId', xform.problem)
self.assertIn('Bad case id', xform.problem)