本文整理汇总了Python中corehq.form_processor.interfaces.FormProcessorInterface.get_xform方法的典型用法代码示例。如果您正苦于以下问题:Python FormProcessorInterface.get_xform方法的具体用法?Python FormProcessorInterface.get_xform怎么用?Python FormProcessorInterface.get_xform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.form_processor.interfaces.FormProcessorInterface
的用法示例。
在下文中一共展示了FormProcessorInterface.get_xform方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testArchive
# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import get_xform [as 别名]
def testArchive(self):
xform = FormProcessorInterface.create_from_generic(
GenericXFormInstance(form={'foo': 'bar'}),
GenericFormAttachment(name='form.xml', content='<data/>')
)
self.assertEqual("XFormInstance", xform.doc_type)
self.assertEqual(0, len(xform.history))
lower_bound = datetime.utcnow() - timedelta(seconds=1)
FormProcessorInterface.archive_xform(xform, user='mr. librarian')
upper_bound = datetime.utcnow() + timedelta(seconds=1)
xform = FormProcessorInterface.get_xform(xform.id)
self.assertEqual('XFormArchived', xform.doc_type)
[archival] = xform.history
self.assertTrue(lower_bound <= archival.date <= upper_bound)
self.assertEqual('archive', archival.operation)
self.assertEqual('mr. librarian', archival.user)
lower_bound = datetime.utcnow() - timedelta(seconds=1)
FormProcessorInterface.unarchive_xform(xform, user='mr. researcher')
upper_bound = datetime.utcnow() + timedelta(seconds=1)
xform = FormProcessorInterface.get_xform(xform.id)
self.assertEqual('XFormInstance', xform.doc_type)
[archival, restoration] = xform.history
self.assertTrue(lower_bound <= restoration.date <= upper_bound)
self.assertEqual('unarchive', restoration.operation)
self.assertEqual('mr. researcher', restoration.user)
示例2: test_broken_save
# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import get_xform [as 别名]
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.
"""
class BorkDB(object):
"""context manager for making a db's bulk_save temporarily fail"""
def __init__(self, db):
self.old = {}
self.db = db
def __enter__(self):
self.old['bulk_save'] = self.db.bulk_save
self.db.bulk_save = MagicMock(name='bulk_save',
side_effect=RequestFailed())
def __exit__(self, exc_type, exc_val, exc_tb):
self.db.bulk_save = self.old['bulk_save']
xforms = FormProcessorInterface.get_by_doc_type(self.domain, 'XFormInstance')
self.assertEqual(len(xforms), 0)
xml_data1, xml_data2 = self._get_files()
submit_form_locally(xml_data1, self.domain)
xform = FormProcessorInterface.get_xform(self.ID)
self.assertEqual(self.ID, xform.id)
self.assertEqual("XFormInstance", xform.doc_type)
self.assertEqual(self.domain, xform.domain)
self.assertEqual(
UnfinishedSubmissionStub.objects.filter(xform_id=self.ID).count(),
0
)
# This seems like a couch specific test util. Will likely need postgres test utils
with BorkDB(XFormInstance.get_db()):
with self.assertRaises(RequestFailed):
submit_form_locally(xml_data2, self.domain)
# it didn't go through, so make sure there are no edits still
xforms = FormProcessorInterface.get_by_doc_type(self.domain, 'XFormDeprecated')
self.assertEqual(len(xforms), 0)
xform = FormProcessorInterface.get_xform(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
)
示例3: test_simple_delete
# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import get_xform [as 别名]
def test_simple_delete(self):
factory = CaseFactory()
case = factory.create_case()
[case] = factory.create_or_update_case(CaseStructure(case_id=case._id, attrs={'update': {'foo': 'bar'}}))
self.assertIsNotNone(FormProcessorInterface.get_case(case.id))
self.assertEqual(2, len(case.xform_ids))
for form_id in case.xform_ids:
self.assertIsNotNone(FormProcessorInterface.get_xform(form_id))
FormProcessorInterface.hard_delete_case(case)
with self.assertRaises(CaseNotFound):
FormProcessorInterface.get_case(case.id)
for form_id in case.xform_ids:
with self.assertRaises(XFormNotFound):
FormProcessorInterface.get_xform(form_id)
示例4: test_second_edit_fails
# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import get_xform [as 别名]
def test_second_edit_fails(self):
form_id = uuid.uuid4().hex
case_id = uuid.uuid4().hex
case_block = CaseBlock(
create=True,
case_id=case_id,
case_type='person',
).as_string()
submit_case_blocks(case_block, domain=self.domain, form_id=form_id)
# submit an edit form with a bad case update (for example a bad ID)
case_block = CaseBlock(
create=True,
case_id='',
case_type='person',
).as_string()
submit_case_blocks(case_block, domain=self.domain, form_id=form_id)
xform = FormProcessorInterface.get_xform(form_id)
self.assertEqual('XFormError', xform.doc_type)
deprecated_xform = FormProcessorInterface.get_xform(xform.deprecated_form_id)
self.assertEqual('XFormDeprecated', deprecated_xform.doc_type)