本文整理匯總了Python中corehq.form_processor.interfaces.FormProcessorInterface類的典型用法代碼示例。如果您正苦於以下問題:Python FormProcessorInterface類的具體用法?Python FormProcessorInterface怎麽用?Python FormProcessorInterface使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了FormProcessorInterface類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setUp
def setUp(self):
delete_all_xforms()
delete_all_cases()
FormProcessorInterface.post_case_blocks(
[CaseBlock(create=True, case_id="mother_case_id", case_type="mother-case").as_xml()],
{"domain": TEST_DOMAIN},
)
self.case_id = "test_case_1"
self.date_modified = datetime.utcnow() - timedelta(hours=1)
self.date_modified = self.date_modified.replace(microsecond=0)
FormProcessorInterface.post_case_blocks(
[
CaseBlock(
create=True,
case_id=self.case_id,
owner_id="owner",
user_id="user",
case_type="c_type",
case_name=("a" * TEST_NAME_LEN) + "123456789",
external_id="external_id",
date_modified=self.date_modified,
update={"foo": "bar"},
index={"mom": ("mother-case", "mother_case_id")},
).as_xml()
],
{"domain": TEST_DOMAIN},
)
instance = CommCareCase.get(self.case_id)
self.casedata = CaseData.create_or_update_from_instance(instance)
示例2: testUserRestoreWithCase
def testUserRestoreWithCase(self):
file_path = os.path.join(os.path.dirname(__file__), "data", "create_short.xml")
with open(file_path, "rb") as f:
xml_data = f.read()
FormProcessorInterface.submit_form_locally(xml_data, self.domain)
expected_case_block = """
<case case_id="asdf" date_modified="2010-06-29T13:42:50.000000Z" user_id="foo"
xmlns="http://commcarehq.org/case/transaction/v2">
<create>
<case_type>test_case_type</case_type>
<case_name>test case name</case_name>
<owner_id>foo</owner_id>
</create>
<update>
<external_id>someexternal</external_id>
</update>
</case>"""
restore_payload = generate_restore_payload(
project=Domain(name=self.domain),
user=dummy_user(),
items=True,
version=V3
)
sync_log_id = SyncLog.view(
"phone/sync_logs_by_user",
include_docs=True,
reduce=False,
).one().get_id
check_xml_line_by_line(
self,
dummy_restore_xml(sync_log_id, expected_case_block, items=4),
restore_payload
)
示例3: testMismatch
def testMismatch(self):
self.assertEqual(CaseStateHash(EMPTY_HASH), self.sync_log.get_state_hash())
c1 = CaseBlock(case_id="abc123", create=True,
owner_id=self.user.user_id).as_xml()
c2 = CaseBlock(case_id="123abc", create=True,
owner_id=self.user.user_id).as_xml()
FormProcessorInterface.post_case_blocks([c1, c2],
form_extras={"last_sync_token": self.sync_log.get_id})
self.sync_log = get_properly_wrapped_sync_log(self.sync_log.get_id)
real_hash = CaseStateHash("409c5c597fa2c2a693b769f0d2ad432b")
bad_hash = CaseStateHash("thisisntright")
self.assertEqual(real_hash, self.sync_log.get_state_hash())
generate_restore_payload(
self.project, self.user, self.sync_log.get_id,
version=V2, state_hash=str(real_hash)
)
try:
generate_restore_payload(self.project, self.user, self.sync_log.get_id,
version=V2, state_hash=str(bad_hash))
self.fail("Call to generate a payload with a bad hash should fail!")
except BadStateException, e:
self.assertEqual(real_hash, e.server_hash)
self.assertEqual(bad_hash, e.phone_hash)
self.assertEqual(2, len(e.case_ids))
self.assertTrue("abc123" in e.case_ids)
self.assertTrue("123abc" in e.case_ids)
示例4: test_deleted_indices_removed
def test_deleted_indices_removed(self):
factory = CaseFactory(
self.domain,
case_defaults={
'user_id': self.commcare_user._id,
'owner_id': self.commcare_user._id,
'case_type': 'a-case',
'create': True,
},
)
# create a parent/child set of cases
parent_id, child_id = [uuid.uuid4().hex for i in range(2)]
child, parent = factory.create_or_update_case(CaseStructure(
case_id=child_id,
indices=[
CaseIndex(CaseStructure(case_id=parent_id))
]
))
# confirm the child has an index, and 1 form
self.assertEqual(1, len(child.indices))
self.assertEqual(parent_id, child.indices[0].referenced_id)
self.assertEqual(1, len(child.xform_ids))
# simulate parent deletion
FormProcessorInterface.soft_delete_case(parent_id)
# call the remove index task
remove_indices_from_deleted_cases(self.domain, [parent_id])
# check that the index is removed via a new form
child = CommCareCase.get(child_id)
self.assertEqual(0, len(child.indices))
self.assertEqual(2, len(child.xform_ids))
示例5: test_conflicting_ids
def test_conflicting_ids(self):
"""
If a form and a case share an ID it's a conflict
"""
xml_data = self.get_xml('id_conflicts')
with self.assertRaises(BulkSaveError):
FormProcessorInterface.submit_form_locally(xml_data)
示例6: testSignal
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)
示例7: update_and_test
def update_and_test(case_id, owner=None, should_have=None, should_not_have=None):
case_block = self.get_update_block(
case_id=case_id,
update={'greeting': "Hello!"},
owner_id=owner.get_id if owner else None,
)
FormProcessorInterface.post_case_blocks([case_block], {'domain': self.domain})
check_has_block(case_block, should_have, should_not_have, line_by_line=False)
示例8: add_parent_access
def add_parent_access(self, user, case):
case_block = CaseBlock(
create=True,
case_id=uuid.uuid4().hex,
case_type='magic_map',
owner_id=user._id,
index={'parent': ('participant', case._id)}
).as_xml()
FormProcessorInterface.post_case_blocks([case_block], {'domain': self.domain})
示例9: create_and_test
def create_and_test(case_id, user, owner, should_have, should_not_have):
case_block = self.get_create_block(
case_id=case_id,
type="case",
user_id=user.user_id,
owner_id=owner.get_id,
)
FormProcessorInterface.post_case_blocks([case_block], {'domain': self.domain})
check_has_block(case_block, should_have, should_not_have)
示例10: update_case_owner
def update_case_owner(self, case, owner):
case_block = CaseBlock(
create=False,
case_id=case._id,
case_type='participant',
owner_id=owner._id,
user_id=owner._id,
).as_xml()
FormProcessorInterface.post_case_blocks([case_block], {'domain': self.domain})
示例11: test_broken_save
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
)
示例12: test_empty_name
def test_empty_name(self):
case_id = "case_with_no_name"
FormProcessorInterface.post_case_blocks(
[CaseBlock(create=True, case_id=case_id, case_type="nameless").as_xml()], {"domain": TEST_DOMAIN}
)
instance = CommCareCase.get(case_id)
casedata = CaseData.create_or_update_from_instance(instance)
self.assertIsNotNone(casedata)
self.assertEqual("", casedata.name)
示例13: _new_case
def _new_case(cls, properties):
id = uuid.uuid4().hex
case_block = CaseBlock(
create=True,
case_id=id,
case_type=cls.case_type,
update=properties,
).as_xml()
FormProcessorInterface.post_case_blocks([case_block], {'domain': cls.domain})
return CommCareCase.get(id)
示例14: testTopLevelExclusion
def testTopLevelExclusion(self):
"""
Entire forms tagged as device logs should be excluded
"""
file_path = os.path.join(os.path.dirname(__file__), "data", "exclusion", "device_report.xml")
with open(file_path, "rb") as f:
xml_data = f.read()
FormProcessorInterface.submit_form_locally(xml_data)
self.assertEqual(0, get_total_case_count())
示例15: test_assign_bad_index_ref
def test_assign_bad_index_ref(self):
# the case has to exist to create the index, but if we delete it later the assignment
# shouldn't fail
case = self._new_case()
case_with_bad_ref = self._new_case(index={"parent": ("person", case._id)})
FormProcessorInterface.soft_delete_case(case._id)
# this call previously failed
res = assign_case(case_with_bad_ref.id, self.primary_user._id, include_subcases=True, include_parent_cases=True)
self.assertEqual(2, len(res))
self.assertIn(case_with_bad_ref._id, res)
self.assertIn(case._id, res)