本文整理匯總了Python中corehq.form_processor.interfaces.FormProcessorInterface.create_from_generic方法的典型用法代碼示例。如果您正苦於以下問題:Python FormProcessorInterface.create_from_generic方法的具體用法?Python FormProcessorInterface.create_from_generic怎麽用?Python FormProcessorInterface.create_from_generic使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類corehq.form_processor.interfaces.FormProcessorInterface
的用法示例。
在下文中一共展示了FormProcessorInterface.create_from_generic方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testSignal
# 需要導入模塊: from corehq.form_processor.interfaces import FormProcessorInterface [as 別名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import create_from_generic [as 別名]
def testSignal(self):
global archive_counter, restore_counter
archive_counter = 0
restore_counter = 0
def count_archive(**kwargs):
global archive_counter
archive_counter += 1
def count_unarchive(**kwargs):
global restore_counter
restore_counter += 1
xform_archived.connect(count_archive)
xform_unarchived.connect(count_unarchive)
xform = FormProcessorInterface.create_from_generic(
GenericXFormInstance(form={'foo': 'bar'}),
GenericFormAttachment(name='form.xml', content='<data/>')
)
self.assertEqual(0, archive_counter)
self.assertEqual(0, restore_counter)
FormProcessorInterface.archive_xform(xform)
self.assertEqual(1, archive_counter)
self.assertEqual(0, restore_counter)
FormProcessorInterface.unarchive_xform(xform)
self.assertEqual(1, archive_counter)
self.assertEqual(1, restore_counter)
示例2: testArchive
# 需要導入模塊: from corehq.form_processor.interfaces import FormProcessorInterface [as 別名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import create_from_generic [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)
示例3: test_wrong_domain
# 需要導入模塊: from corehq.form_processor.interfaces import FormProcessorInterface [as 別名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import create_from_generic [as 別名]
def test_wrong_domain(self):
domain = 'test-domain'
generic_xform = GenericXFormInstance(
doc_type='XFormInstance',
domain='wrong-domain',
)
xform = FormProcessorInterface.create_from_generic(generic_xform)
instance = self._get_file()
instance = instance.replace(self.ID, xform.id)
xform = FormProcessorInterface.post_xform(instance, domain=domain)
self.assertNotEqual(xform.id, self.ID)