本文整理匯總了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)