本文整理汇总了Python中casexml.apps.case.mock.CaseBlock.as_xml方法的典型用法代码示例。如果您正苦于以下问题:Python CaseBlock.as_xml方法的具体用法?Python CaseBlock.as_xml怎么用?Python CaseBlock.as_xml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类casexml.apps.case.mock.CaseBlock
的用法示例。
在下文中一共展示了CaseBlock.as_xml方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_case_block_index_default_relationship
# 需要导入模块: from casexml.apps.case.mock import CaseBlock [as 别名]
# 或者: from casexml.apps.case.mock.CaseBlock import as_xml [as 别名]
def test_case_block_index_default_relationship(self):
"""
CaseBlock index relationship should default to "child"
"""
case_block = CaseBlock(
case_id='123456',
case_type='newborn',
date_modified='2015-07-24',
date_opened='2015-07-24',
index={
'parent': ChildIndexAttrs(case_type='mother', case_id='789abc')
},
)
self.assertEqual(
ElementTree.tostring(case_block.as_xml()).decode('utf-8'),
re.sub(r'(\n| {2,})', '', """
<case case_id="123456" date_modified="2015-07-24" xmlns="http://commcarehq.org/case/transaction/v2">
<update>
<case_type>newborn</case_type>
<date_opened>2015-07-24</date_opened>
</update>
<index>
<parent case_type="mother">789abc</parent>
</index>
</case>
""")
)
示例2: test_case_block_index_omit_child
# 需要导入模块: from casexml.apps.case.mock import CaseBlock [as 别名]
# 或者: from casexml.apps.case.mock.CaseBlock import as_xml [as 别名]
def test_case_block_index_omit_child(self):
"""
CaseBlock index relationship omit relationship attribute if set to "child"
"""
case_block = CaseBlock(
case_id='123456',
case_type='newborn',
date_modified='2015-07-24',
index={
'parent': IndexAttrs(case_type='mother', case_id='789abc', relationship='child')
},
)
self.assertEqual(
ElementTree.tostring(case_block.as_xml()),
re.sub(r'(\n| {2,})', '', """
<case case_id="123456" date_modified="2015-07-24" xmlns="http://commcarehq.org/case/transaction/v2">
<update>
<case_type>newborn</case_type>
</update>
<index>
<parent case_type="mother">789abc</parent>
</index>
</case>
""")
)
示例3: create_case_from_dhis2
# 需要导入模块: from casexml.apps.case.mock import CaseBlock [as 别名]
# 或者: from casexml.apps.case.mock.CaseBlock import as_xml [as 别名]
def create_case_from_dhis2(dhis2_child, domain, user):
"""
Create a new case using the data pulled from DHIS2
:param dhis2_child: TRACKED_ENTITY (i.e. "Child") from DHIS2
:param domain: (str) The name of the domain
:param user: (Document) The owner of the new case
:return: New case ID
"""
case_id = uuid.uuid4().hex
update = {k: dhis2_child[v] for k, v in NUTRITION_ASSESSMENT_PROGRAM_FIELDS.iteritems()}
update['dhis_org_id'] = dhis2_child['Org unit']
# Do the inverse of push_case() to 'Gender' / 'child_gender'
if 'child_gender' in update:
if update['child_gender'] == 'Undefined':
del update['child_gender']
else:
update['child_gender'] = update['child_gender'].lower()
caseblock = CaseBlock(
create=True,
case_id=case_id,
owner_id=user.userID,
user_id=user.userID,
case_type=CASE_TYPE,
case_name=update[CASE_NAME] if CASE_NAME else '',
external_id=dhis2_child['Instance'],
update=update
)
casexml = ElementTree.tostring(caseblock.as_xml())
submit_case_blocks(casexml, domain)
return case_id
示例4: submit_mapping_case_block
# 需要导入模块: from casexml.apps.case.mock import CaseBlock [as 别名]
# 或者: from casexml.apps.case.mock.CaseBlock import as_xml [as 别名]
def submit_mapping_case_block(user, index):
mapping = user.get_location_map_case()
if mapping:
caseblock = CaseBlock(
create=False,
case_id=mapping._id,
version=V2,
index=index
)
else:
caseblock = CaseBlock(
create=True,
case_type=const.USER_LOCATION_OWNER_MAP_TYPE,
case_id=location_map_case_id(user),
version=V2,
owner_id=user._id,
index=index,
case_name=const.USER_LOCATION_OWNER_MAP_TYPE.replace('-', ' '),
user_id=const.COMMTRACK_USERNAME,
)
submit_case_blocks(
ElementTree.tostring(
caseblock.as_xml(format_datetime=json_format_datetime)
),
user.domain,
)
示例5: submit_mapping_case_block
# 需要导入模块: from casexml.apps.case.mock import CaseBlock [as 别名]
# 或者: from casexml.apps.case.mock.CaseBlock import as_xml [as 别名]
def submit_mapping_case_block(user, index):
mapping = user.get_location_map_case()
if mapping:
caseblock = CaseBlock(
create=False,
case_id=mapping._id,
version=V2,
index=index
)
else:
caseblock = CaseBlock(
create=True,
case_type=USER_LOCATION_OWNER_MAP_TYPE,
case_id=location_map_case_id(user),
version=V2,
owner_id=user._id,
index=index
)
submit_case_blocks(
ElementTree.tostring(caseblock.as_xml()),
user.domain,
user.username,
user._id
)
示例6: make_supply_point_product
# 需要导入模块: from casexml.apps.case.mock import CaseBlock [as 别名]
# 或者: from casexml.apps.case.mock.CaseBlock import as_xml [as 别名]
def make_supply_point_product(supply_point_case, product_uuid, owner_id=None):
domain = supply_point_case.domain
id = uuid.uuid4().hex
user_id = const.get_commtrack_user_id(domain)
owner_id = owner_id or get_owner_id(supply_point_case) or user_id
username = const.COMMTRACK_USERNAME
product_name = Product.get(product_uuid).name
caseblock = CaseBlock(
case_id=id,
create=True,
version=V2,
case_name=product_name,
user_id=user_id,
owner_id=owner_id,
case_type=const.SUPPLY_POINT_PRODUCT_CASE_TYPE,
update={
"product": product_uuid
},
index={
const.PARENT_CASE_REF: (const.SUPPLY_POINT_CASE_TYPE,
supply_point_case._id),
}
)
casexml = ElementTree.tostring(caseblock.as_xml())
submit_case_blocks(casexml, domain, username, user_id,
xmlns=const.COMMTRACK_SUPPLY_POINT_PRODUCT_XMLNS)
sppc = SupplyPointProductCase.get(id)
sppc.bind_to_location(supply_point_case.location)
sppc.save()
return sppc
示例7: test_case_block_index_supports_relationship
# 需要导入模块: from casexml.apps.case.mock import CaseBlock [as 别名]
# 或者: from casexml.apps.case.mock.CaseBlock import as_xml [as 别名]
def test_case_block_index_supports_relationship(self):
"""
CaseBlock index should allow the relationship to be set
"""
case_block = CaseBlock(
case_id='abcdef',
case_type='at_risk',
date_modified='2015-07-24',
date_opened='2015-07-24',
index={
'host': IndexAttrs(case_type='newborn', case_id='123456', relationship='extension')
},
)
self.assertEqual(
ElementTree.tostring(case_block.as_xml()).decode('utf-8'),
re.sub(r'(\n| {2,})', '', """
<case case_id="abcdef" date_modified="2015-07-24" xmlns="http://commcarehq.org/case/transaction/v2">
<update>
<case_type>at_risk</case_type>
<date_opened>2015-07-24</date_opened>
</update>
<index>
<host case_type="newborn" relationship="extension">123456</host>
</index>
</case>
""")
)
示例8: testBadIndexReference
# 需要导入模块: from casexml.apps.case.mock import CaseBlock [as 别名]
# 或者: from casexml.apps.case.mock.CaseBlock import as_xml [as 别名]
def testBadIndexReference(self):
block = CaseBlock(create=True, case_id=self.CASE_ID, user_id=USER_ID, version=V2,
index={'bad': ('bad-case', 'not-an-existing-id')})
try:
post_case_blocks([block.as_xml()])
self.fail("Submitting against a bad case in an index should fail!")
except IllegalCaseId:
pass
示例9: test_reprocess_xform_error
# 需要导入模块: from casexml.apps.case.mock import CaseBlock [as 别名]
# 或者: from casexml.apps.case.mock.CaseBlock import as_xml [as 别名]
def test_reprocess_xform_error(self):
case_id = uuid.uuid4().hex
parent_case_id = uuid.uuid4().hex
case = CaseBlock(
create=True,
case_id=case_id,
user_id='user1',
owner_id='user1',
case_type='demo',
case_name='child',
index={'parent': ('parent_type', parent_case_id)}
)
post_case_blocks([case.as_xml()], domain=self.domain)
form_accessors = FormAccessors(self.domain)
error_forms = form_accessors.get_forms_by_type('XFormError', 10)
self.assertEqual(1, len(error_forms))
form = error_forms[0]
reprocess_xform_error(form)
error_forms = form_accessors.get_forms_by_type('XFormError', 10)
self.assertEqual(1, len(error_forms))
case = CaseBlock(
create=True,
case_id=parent_case_id,
user_id='user1',
owner_id='user1',
case_type='parent_type',
case_name='parent',
)
post_case_blocks([case.as_xml()], domain=self.domain)
reprocess_xform_error(form_accessors.get_form(form.form_id))
form = form_accessors.get_form(form.form_id)
# self.assertTrue(form.initial_processing_complete) Can't change this with SQL forms at the moment
self.assertTrue(form.is_normal)
self.assertIsNone(form.problem)
case = CaseAccessors(self.domain).get_case(case_id)
self.assertEqual(1, len(case.indices))
self.assertEqual(case.indices[0].referenced_id, parent_case_id)
self._validate_case(case)
示例10: testArchiveModifiedOn
# 需要导入模块: from casexml.apps.case.mock import CaseBlock [as 别名]
# 或者: from casexml.apps.case.mock.CaseBlock import as_xml [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)
示例11: test_globally_unique_case_id
# 需要导入模块: from casexml.apps.case.mock import CaseBlock [as 别名]
# 或者: from casexml.apps.case.mock.CaseBlock import as_xml [as 别名]
def test_globally_unique_case_id(self):
case_id = uuid.uuid4().hex
case = CaseBlock(
create=True,
case_id=case_id,
user_id='user1',
owner_id='user1',
case_type='demo',
case_name='create_case'
)
with override_settings(TESTS_SHOULD_USE_SQL_BACKEND=False):
post_case_blocks([case.as_xml()], domain='domain1')
with override_settings(TESTS_SHOULD_USE_SQL_BACKEND=True):
xform, cases = post_case_blocks([case.as_xml()], domain='domain2')
self.assertEqual(0, len(cases))
self.assertTrue(xform.is_error)
self.assertIn('IllegalCaseId', xform.problem)
示例12: to_xml
# 需要导入模块: from casexml.apps.case.mock import CaseBlock [as 别名]
# 或者: from casexml.apps.case.mock.CaseBlock import as_xml [as 别名]
def to_xml(to_update):
caseblock = CaseBlock(
create=False,
case_id=to_update.case.case_id,
user_id=MOTECH_ID,
owner_id=to_update.new_owner_id or CaseBlock.undefined,
case_type=to_update.new_type or CaseBlock.undefined,
)
return ElementTree.tostring(caseblock.as_xml())
示例13: update_case_external_id
# 需要导入模块: from casexml.apps.case.mock import CaseBlock [as 别名]
# 或者: from casexml.apps.case.mock.CaseBlock import as_xml [as 别名]
def update_case_external_id(case, external_id):
"""
Update the external_id of a case
"""
caseblock = CaseBlock(
create=False,
case_id=case['_id'],
external_id=external_id
)
casexml = ElementTree.tostring(caseblock.as_xml())
submit_case_blocks(casexml, case['domain'])
示例14: test_date_opened_coercion
# 需要导入模块: from casexml.apps.case.mock import CaseBlock [as 别名]
# 或者: from casexml.apps.case.mock.CaseBlock import as_xml [as 别名]
def test_date_opened_coercion(self):
delete_all_users()
self.project = Domain(name='some-domain')
self.project.save()
user = create_restore_user(self.project.name)
case_id = uuid.uuid4().hex
modified_on = datetime.utcnow()
case = CaseBlock(
create=True,
case_id=case_id,
user_id=user.user_id, owner_id=user.user_id, case_type='demo',
case_name='create_case', date_modified=modified_on, date_opened=modified_on, update={
'dynamic': '123'
}
)
post_case_blocks([case.as_xml()], domain='some-domain')
# update the date_opened to date type to check for value on restore
case.date_opened = case.date_opened.date()
check_user_has_case(self, user, case.as_xml())
示例15: _create_closed_case
# 需要导入模块: from casexml.apps.case.mock import CaseBlock [as 别名]
# 或者: from casexml.apps.case.mock.CaseBlock import as_xml [as 别名]
def _create_closed_case(cls):
case_id = uuid.uuid4().hex
caseblock = CaseBlock(
case_id=case_id,
case_type=cls.case_type,
date_opened=cls.closed_case_date_opened,
date_modified=cls.closed_case_date_closed,
case_name=cls.case_name,
close=True,
)
post_case_blocks([caseblock.as_xml()], domain=cls.domain)
return case_id