本文整理汇总了Python中casexml.apps.case.models.CommCareCase类的典型用法代码示例。如果您正苦于以下问题:Python CommCareCase类的具体用法?Python CommCareCase怎么用?Python CommCareCase使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CommCareCase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_list
def test_get_list(self):
"""
Any case in the appropriate domain should be in the list from the API.
"""
# The actual infrastructure involves saving to CouchDB, having PillowTop
# read the changes and write it to ElasticSearch.
# the pillow is set to offline mode - elasticsearch not needed to validate
fake_case_es = FakeXFormES()
v0_4.MOCK_CASE_ES = fake_case_es
modify_date = datetime.utcnow()
backend_case = CommCareCase(server_modified_on=modify_date, domain=self.domain.name)
backend_case.save()
self.addCleanup(backend_case.delete)
translated_doc = transform_case_for_elasticsearch(backend_case.to_json())
fake_case_es.add_doc(translated_doc['_id'], translated_doc)
response = self._assert_auth_get_resource(self.list_endpoint)
self.assertEqual(response.status_code, 200)
api_cases = json.loads(response.content)['objects']
self.assertEqual(len(api_cases), 1)
api_case = api_cases[0]
self.assertEqual(api_case['server_date_modified'], json_format_datetime(backend_case.server_modified_on))
示例2: _send_case_to_es
def _send_case_to_es(self,
domain=None,
owner_id=None,
user_id=None,
case_type=None,
opened_on=None,
closed_on=None):
actions = [CommCareCaseAction(
action_type=CASE_ACTION_CREATE,
date=opened_on,
)]
case = CommCareCase(
_id=uuid.uuid4().hex,
domain=domain or self.domain,
owner_id=owner_id or self.owner_id,
user_id=user_id or self.user_id,
type=case_type or self.case_type,
opened_on=opened_on or datetime.now(),
opened_by=user_id or self.user_id,
closed_on=closed_on,
closed_by=user_id or self.user_id,
actions=actions,
)
send_to_elasticsearch('cases', case.to_json())
self.es.indices.refresh(CASE_INDEX_INFO.index)
return case
示例3: get_cases
def get_cases(case_ids, ordered=False):
return [
CommCareCase.wrap(doc) for doc in iter_docs(
CommCareCase.get_db(),
case_ids
)
]
示例4: test_out_of_order
def test_out_of_order(self):
case = CommCareCase(actions=[
CommCareCaseAction(server_date=datetime(2001, 1, 1, 0, 0, 0)),
CommCareCaseAction(server_date=datetime(2001, 1, 3, 0, 0, 0)),
CommCareCaseAction(server_date=datetime(2001, 1, 2, 0, 0, 0)),
])
self.assertFalse(case.check_action_order())
示例5: IndexSimpleTest
class IndexSimpleTest(SimpleTestCase):
def setUp(self):
self.i1 = CommCareCaseIndex(identifier="i1", referenced_type="t1", referenced_id="id1")
self.i2 = CommCareCaseIndex(identifier="i2", referenced_type="t2", referenced_id="id2")
self.case = CommCareCase(indices=[self.i1, self.i2])
def testHasIndex(self):
self.assertEqual(True, self.case.has_index("i1"))
self.assertEqual(True, self.case.has_index("i2"))
self.assertEqual(False, self.case.has_index("i3"))
def testGetIndex(self):
self.assertEqual(self.i1, self.case.get_index("i1"))
self.assertEqual(self.i2, self.case.get_index("i2"))
self.assertEqual(None, self.case.get_index("i3"))
self.assertEqual(None, self.case.get_index("id1"))
def testGetIndexByRef(self):
self.assertEqual(self.i1, self.case.get_index_by_ref_id("id1"))
self.assertEqual(self.i2, self.case.get_index_by_ref_id("id2"))
self.assertEqual(None, self.case.get_index_by_ref_id("id3"))
self.assertEqual(None, self.case.get_index_by_ref_id("i1"))
def testRemoveIndexByRef(self):
self.assertEqual(2, len(self.case.indices))
self.case.remove_index_by_ref_id("id1")
self.assertEqual(1, len(self.case.indices))
self.assertRaises(ValueError, self.case.remove_index_by_ref_id, "id3")
self.assertRaises(ValueError, self.case.remove_index_by_ref_id, "i2")
示例6: test_rebuild_indicators
def test_rebuild_indicators(self, datetime_mock):
datetime_mock.utcnow.return_value = self.fake_time_now
sample_doc, expected_indicators = get_sample_doc_and_indicators(self.fake_time_now)
CommCareCase.get_db().save_doc(sample_doc)
self.addCleanup(lambda id: CommCareCase.get_db().delete_doc(id), sample_doc['_id'])
rebuild_indicators(self.config._id)
self._check_sample_doc_state(expected_indicators)
示例7: test_already_sorted
def test_already_sorted(self):
case = CommCareCase(actions=[
CommCareCaseAction(server_date=datetime(2001, 1, 1, 0, 0, 0)),
CommCareCaseAction(server_date=datetime(2001, 1, 2, 0, 0, 0)),
CommCareCaseAction(server_date=datetime(2001, 1, 3, 0, 0, 0)),
])
self.assertTrue(case.check_action_order())
示例8: _send_case_to_es
def _send_case_to_es(self,
domain=None,
owner_id=None,
user_id=None,
case_type=None,
opened_on=None,
closed_on=None):
actions = [CommCareCaseAction(
action_type=CASE_ACTION_CREATE,
date=opened_on,
)]
case = CommCareCase(
_id=uuid.uuid4().hex,
domain=domain or self.domain,
owner_id=owner_id or self.owner_id,
user_id=user_id or self.user_id,
type=case_type or self.case_type,
opened_on=opened_on or datetime.now(),
opened_by=user_id or self.user_id,
closed_on=closed_on,
closed_by=user_id or self.user_id,
actions=actions,
)
self.pillow.change_transport(case.to_json())
self.pillow.get_es_new().indices.refresh(self.pillow.es_index)
return case
示例9: test_rebuild_indicators
def test_rebuild_indicators(self, datetime_mock):
datetime_mock.utcnow.return_value = self.fake_time_now
self.config.save()
sample_doc, _ = get_sample_doc_and_indicators(self.fake_time_now)
CommCareCase.get_db().save_doc(sample_doc)
rebuild_indicators(self.config._id)
self._check_sample_doc_state()
示例10: testRebuildEmpty
def testRebuildEmpty(self):
self.assertEqual(None, rebuild_case("notarealid"))
try:
CommCareCase.get_with_rebuild("notarealid")
self.fail("get with rebuild should still fail for unknown cases")
except ResourceNotFound:
pass
示例11: testAttachments
def testAttachments(self):
self.assertEqual(len(CommCareCase.get(self.case_id).case_attachments), 0)
scan_path = os.path.join(os.path.dirname(__file__), "data", "vscan", "VH014466XK_000016_20130722T175057")
files = self.pack_directory(scan_path)
utils.attach_images_to_case(self.case_id, files)
self.assertEqual(len(CommCareCase.get(self.case_id).case_attachments), 3)
示例12: UtilTestCase
class UtilTestCase(TestCase):
def setUp(self):
self.case = CommCareCase(domain='test-domain', name='test-case')
self.case.save()
self.user = CommCareUser.create('test-domain', 'test-user', '123')
def tearDown(self):
self.case.delete()
self.user.delete()
def testCleanPhoneNumber(self):
phone_number = " 324 23-23421241"
cleaned = clean_phone_number(phone_number)
self.assertEquals(cleaned, "+3242323421241")
def test_get_contact(self):
contact = get_contact(self.case.get_id)
self.assertEqual(contact.get_id, self.case.get_id)
self.assertTrue(isinstance(contact, CommConnectCase))
contact = get_contact(self.user.get_id)
self.assertEqual(contact.get_id, self.user.get_id)
self.assertTrue(isinstance(contact, CommCareUser))
with self.assertRaises(ContactNotFoundException):
get_contact('this-id-should-not-be-found')
def test_apply_leniency(self):
self.assertEqual('16175551234', apply_leniency(' 1 (617) 555-1234 '))
self.assertEqual('16175551234', apply_leniency(' 1.617.555.1234 '))
self.assertEqual('16175551234', apply_leniency(' +1 617 555 1234 '))
示例13: cases
def cases(self):
if "debug_case" in self.request.GET:
case = CommCareCase.get(self.request.GET["debug_case"])
if case.domain != DOMAIN:
raise Http404()
return [case]
query = (
case_es.CaseES()
.domain(self.domain)
.exclude_source()
.opened_range(lte=self.datespan.enddate_utc)
.case_type(self.default_case_type)
)
query.index = "report_cases"
if self.case_status == "open":
query = query.filter(
es_filters.OR(case_es.is_closed(False), case_es.closed_range(gte=self.datespan.enddate_utc))
)
elif self.case_status == "closed":
query = query.filter(case_es.closed_range(lte=self.datespan.enddate_utc))
query = query.owner([user["doc_id"] for user in self.users_matching_filter])
result = query.run()
return [CommCareCase.wrap(doc) for doc in iter_docs(CommCareCase.get_db(), result.doc_ids)]
示例14: setUp
def setUp(self):
# we have to set the fake database before any other calls
self.orig_db = CommCareCase.get_db()
self.database = FakeCouchDb()
CommCareCase.set_db(self.database)
self.spec = {
"type": "related_doc",
"related_doc_type": "CommCareCase",
"doc_id_expression": {"type": "property_name", "property_name": "parent_id"},
"value_expression": {"type": "property_name", "property_name": "related_property"},
}
self.expression = ExpressionFactory.from_spec(self.spec)
self.nested_expression = ExpressionFactory.from_spec(
{
"type": "related_doc",
"related_doc_type": "CommCareCase",
"doc_id_expression": {"type": "property_name", "property_name": "parent_id"},
"value_expression": {
"type": "related_doc",
"related_doc_type": "CommCareCase",
"doc_id_expression": {"type": "property_name", "property_name": "parent_id"},
"value_expression": {"type": "property_name", "property_name": "related_property"},
},
}
)
示例15: testDuplicateCasePropertiesBug
def testDuplicateCasePropertiesBug(self):
"""
How do we do when submitting multiple values for the same property
in an update block
"""
file_path = os.path.join(os.path.dirname(__file__), "data", "bugs",
"duplicate_case_properties.xml")
with open(file_path, "rb") as f:
xml_data = f.read()
form = post_xform_to_couch(xml_data)
# before the bug was fixed this call failed
process_cases(form)
case = CommCareCase.get(form.xpath("form/case/@case_id"))
# make sure the property is there, but empty
self.assertEqual("", case.foo)
file_path = os.path.join(os.path.dirname(__file__), "data", "bugs",
"duplicate_case_properties_2.xml")
with open(file_path, "rb") as f:
xml_data = f.read()
form = post_xform_to_couch(xml_data)
process_cases(form)
case = CommCareCase.get(form.xpath("form/case/@case_id"))
# make sure the property takes the last defined value
self.assertEqual("2", case.bar)