本文整理汇总了Python中corehq.form_processor.interfaces.processor.FormProcessorInterface.post_xform方法的典型用法代码示例。如果您正苦于以下问题:Python FormProcessorInterface.post_xform方法的具体用法?Python FormProcessorInterface.post_xform怎么用?Python FormProcessorInterface.post_xform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.form_processor.interfaces.processor.FormProcessorInterface
的用法示例。
在下文中一共展示了FormProcessorInterface.post_xform方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DuplicateFormTest
# 需要导入模块: from corehq.form_processor.interfaces.processor import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.processor.FormProcessorInterface import post_xform [as 别名]
class DuplicateFormTest(TestCase, TestFileMixin):
ID = '7H46J37FGH3'
file_path = ('data',)
root = os.path.dirname(__file__)
def setUp(self):
self.interface = FormProcessorInterface()
def tearDown(self):
FormProcessorTestUtils.delete_all_xforms()
@run_with_all_backends
def test_basic_duplicate(self):
xml_data = self.get_xml('duplicate')
xform = self.interface.post_xform(xml_data)
self.assertEqual(self.ID, xform.form_id)
self.assertTrue(xform.is_normal)
self.assertEqual("test-domain", xform.domain)
xform = self.interface.post_xform(xml_data, domain='test-domain')
self.assertNotEqual(self.ID, xform.form_id)
self.assertTrue(xform.is_duplicate)
self.assertTrue(self.ID in xform.problem)
@run_with_all_backends
def test_wrong_doc_type(self):
domain = 'test-domain'
instance = self.get_xml('duplicate')
# Post an xform with an alternate doc_type
xform1 = self.interface.post_xform(
instance,
domain=domain,
)
# Change the doc_type of the form by archiving it
self.interface.xform_model.archive(xform1)
xform1 = self.interface.xform_model.get(xform1.form_id)
self.assertTrue(xform1.is_archived)
# Post an xform with that has different doc_type but same id
_, xform2, _ = self.interface.submit_form_locally(
instance,
domain=domain,
)
self.assertNotEqual(xform1.form_id, xform2.form_id)
@run_with_all_backends
def test_wrong_domain(self):
domain = 'test-domain'
instance = self.get_xml('duplicate')
_, xform1, _ = self.interface.submit_form_locally(
instance,
domain='wrong-domain',
)
_, xform2, _ = self.interface.submit_form_locally(
instance,
domain=domain,
)
self.assertNotEqual(xform1.form_id, xform2.form_id)
示例2: EditFormTest
# 需要导入模块: from corehq.form_processor.interfaces.processor import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.processor.FormProcessorInterface import post_xform [as 别名]
class EditFormTest(TestCase, TestFileMixin):
ID = '7H46J37FGH3'
domain = 'test-form-edits'
file_path = ('data', 'deprecation')
root = os.path.dirname(__file__)
def setUp(self):
self.interface = FormProcessorInterface(TEST_DOMAIN_NAME)
def tearDown(self):
FormProcessorTestUtils.delete_all_xforms()
UnfinishedSubmissionStub.objects.all().delete()
@run_with_all_backends
def test_basic_edit(self):
original_xml = self.get_xml('original')
edit_xml = self.get_xml('edit')
yesterday = datetime.utcnow() - timedelta(days=1)
def process(form):
form.domain = self.domain
form.received_on = yesterday
xform = self.interface.post_xform(original_xml, process=process)
self.assertEqual(self.ID, xform.form_id)
self.assertTrue(xform.is_normal)
self.assertEqual("", xform.form_data['vitals']['height'])
self.assertEqual("other", xform.form_data['assessment']['categories'])
xform = self.interface.post_xform(edit_xml, domain=self.domain)
self.assertEqual(self.ID, xform.form_id)
self.assertTrue(xform.is_normal)
self.assertEqual("100", xform.form_data['vitals']['height'])
self.assertEqual("Edited Baby!", xform.form_data['assessment']['categories'])
deprecated_xform = self.interface.xform_model.get(xform.deprecated_form_id)
self.assertEqual(self.ID, deprecated_xform.orig_id)
self.assertNotEqual(self.ID, deprecated_xform.form_id)
self.assertTrue(deprecated_xform.is_deprecated)
self.assertEqual("", deprecated_xform.form_data['vitals']['height'])
self.assertEqual("other", deprecated_xform.form_data['assessment']['categories'])
self.assertEqual(xform.received_on, deprecated_xform.received_on)
self.assertEqual(xform.deprecated_form_id, deprecated_xform.form_id)
self.assertTrue(xform.edited_on > deprecated_xform.received_on)
self.assertEqual(
deprecated_xform.get_xml(),
original_xml
)
self.assertEqual(xform.get_xml(), edit_xml)
@run_with_all_backends
def test_broken_save(self):
"""
Test that if the second form submission terminates unexpectedly
and the main form isn't saved, then there are no side effects
such as the original having been marked as deprecated.
"""
original_xml = self.get_xml('original')
edit_xml = self.get_xml('edit')
_, xform, _ = self.interface.submit_form_locally(original_xml, self.domain)
self.assertEqual(self.ID, xform.form_id)
self.assertTrue(xform.is_normal)
self.assertEqual(self.domain, xform.domain)
self.assertEqual(
UnfinishedSubmissionStub.objects.filter(xform_id=self.ID).count(),
0
)
with patch.object(self.interface.processor, 'bulk_save', side_effect=RequestFailed):
with self.assertRaises(RequestFailed):
self.interface.submit_form_locally(edit_xml, self.domain)
# it didn't go through, so make sure there are no edits still
self.assertIsNone(getattr(xform, 'deprecated_form_id', None))
xform = self.interface.xform_model.get(self.ID)
self.assertIsNotNone(xform)
self.assertEqual(
UnfinishedSubmissionStub.objects.filter(xform_id=self.ID,
saved=False).count(),
1
)
self.assertEqual(
UnfinishedSubmissionStub.objects.filter(xform_id=self.ID).count(),
1
)
def test_case_management(self):
form_id = uuid.uuid4().hex
case_id = uuid.uuid4().hex
owner_id = uuid.uuid4().hex
case_block = CaseBlock(
create=True,
#.........这里部分代码省略.........