本文整理汇总了Python中casexml.apps.case.models.CommCareCase.get方法的典型用法代码示例。如果您正苦于以下问题:Python CommCareCase.get方法的具体用法?Python CommCareCase.get怎么用?Python CommCareCase.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类casexml.apps.case.models.CommCareCase
的用法示例。
在下文中一共展示了CommCareCase.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testArchivingOnlyForm
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get [as 别名]
def testArchivingOnlyForm(self):
"""
Checks that archiving the only form associated with the case archives
the case and unarchiving unarchives it.
"""
case_id = _post_util(create=True, p1='p1-1', p2='p2-1')
case = CommCareCase.get(case_id)
self.assertEqual('CommCareCase', case._doc['doc_type'])
self.assertEqual(2, len(case.actions))
[form_id] = case.xform_ids
form = XFormInstance.get(form_id)
form.archive()
case = CommCareCase.get(case_id)
self.assertEqual('CommCareCase-Deleted', case._doc['doc_type'])
# should just have the 'rebuild' action
self.assertEqual(1, len(case.actions))
self.assertEqual(const.CASE_ACTION_REBUILD, case.actions[0].action_type)
form.unarchive()
case = CommCareCase.get(case_id)
self.assertEqual('CommCareCase', case._doc['doc_type'])
self.assertEqual(3, len(case.actions))
self.assertEqual(const.CASE_ACTION_REBUILD, case.actions[-1].action_type)
示例2: test_date_case_properties_for_inequality
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get [as 别名]
def test_date_case_properties_for_inequality(self):
case = CommCareCase(
domain=self.domain,
type='test-case-type-2',
)
self.rule2.automaticupdaterulecriteria_set = [
AutomaticUpdateRuleCriteria(
property_name='property1',
property_value='2016-02-24',
match_type=AutomaticUpdateRuleCriteria.MATCH_NOT_EQUAL,
),
]
case.set_case_property('property1', '2016-02-24')
case.save()
case = CommCareCase.get(case.get_id)
case.server_modified_on = datetime(2015, 1, 1)
self.assertFalse(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
case.set_case_property('property1', '2016-02-25')
case.save()
case = CommCareCase.get(case.get_id)
case.server_modified_on = datetime(2015, 1, 1)
self.assertTrue(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
case.delete()
示例3: testRecursiveUpdates
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get [as 别名]
def testRecursiveUpdates(self):
parent_case = self._make_case(self.other_user._id, self.other_user._id)
case = self._make_case(self.other_user._id, self.other_user._id,
index={'parent': ('parent-case', parent_case._id)})
subcase1 = self._make_case(self.other_user._id, self.other_user._id,
index={'parent': ('parent-case', case._id)})
subcase2 = self._make_case(self.other_user._id, self.other_user._id,
index={'parent': ('parent-case', case._id)})
subsub1 = self._make_case(self.other_user._id, self.other_user._id,
index={'parent': ('parent-case', subcase1._id)})
subsub2 = self._make_case(self.other_user._id, self.other_user._id,
index={'parent': ('parent-case', subcase1._id)})
cases = [case, subcase1, subcase2, subsub1, subsub2]
for c in cases:
self.assertEqual(self.other_user._id, c.owner_id)
reconcile_ownership(case, self.user, recursive=True)
case = CommCareCase.get(case._id)
owner = get_wrapped_owner(get_owner_id(case))
self.assertTrue(isinstance(owner, Group))
self.assertTrue(self.other_user._id in owner.users)
self.assertTrue(self.user._id in owner.users)
self.assertTrue(owner.case_sharing)
self.assertFalse(owner.reporting)
for c in cases:
c = CommCareCase.get(c._id)
self.assertEqual(owner._id, c.owner_id)
parent_case = CommCareCase.get(parent_case._id)
self.assertEqual(self.other_user._id, parent_case.owner_id)
示例4: testDuplicateCasePropertiesBug
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get [as 别名]
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)
示例5: test_edit_submissions_simple
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get [as 别名]
def test_edit_submissions_simple(self):
initial_quantity = 100
form_id = submit_case_blocks(
case_blocks=get_single_balance_block(quantity=initial_quantity, **self._stock_state_key),
domain=self.domain,
)
stock_state, latest_txn, all_txns = self._get_stats()
self.assertEqual(stock_state.stock_on_hand, initial_quantity)
self.assertEqual(latest_txn.stock_on_hand, initial_quantity)
self.assertEqual(all_txns.count(), 1)
case = CommCareCase.get(id=self.case.case_id)
self.assertEqual(1, len(case.actions))
self.assertEqual([form_id], case.xform_ids)
# change the value to 50
edit_quantity = 50
submit_case_blocks(
case_blocks=get_single_balance_block(quantity=edit_quantity, **self._stock_state_key),
domain=self.domain,
form_id=form_id,
)
case = CommCareCase.get(id=self.case.case_id)
self.assertEqual(1, len(case.actions))
stock_state, latest_txn, all_txns = self._get_stats()
self.assertEqual(stock_state.stock_on_hand, edit_quantity)
self.assertEqual(latest_txn.stock_on_hand, edit_quantity)
self.assertEqual(all_txns.count(), 1)
self.assertEqual([form_id], case.xform_ids)
示例6: testAttachments
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get [as 别名]
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)
示例7: get
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get [as 别名]
def get(self, case_id):
if not case_id:
raise IllegalCaseId('case_id must not be empty')
if case_id in self.cache:
return self.cache[case_id]
try:
if self.strip_history:
case_doc = CommCareCase.get_lite(case_id, wrap=self.wrap)
elif self.lock:
try:
case_doc, lock = CommCareCase.get_locked_obj(_id=case_id)
except redis.RedisError:
case_doc = CommCareCase.get(case_id)
else:
self.locks.append(lock)
else:
if self.wrap:
case_doc = CommCareCase.get(case_id)
else:
case_doc = CommCareCase.get_db().get(case_id)
except ResourceNotFound:
return None
self.validate_doc(case_doc)
self.cache[case_id] = case_doc
return case_doc
示例8: test_date_case_properties_for_equality
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get [as 别名]
def test_date_case_properties_for_equality(self):
"""
Date case properties are automatically converted from string to date
when fetching from the db, so here we want to make sure this doesn't
interfere with our ability to compare dates for equality.
"""
case = CommCareCase(
domain=self.domain,
type='test-case-type-2',
)
self.rule2.automaticupdaterulecriteria_set = [
AutomaticUpdateRuleCriteria(
property_name='property1',
property_value='2016-02-24',
match_type=AutomaticUpdateRuleCriteria.MATCH_EQUAL,
),
]
case.set_case_property('property1', '2016-02-24')
case.save()
case = CommCareCase.get(case.get_id)
case.server_modified_on = datetime(2015, 1, 1)
self.assertTrue(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
case.set_case_property('property1', '2016-02-25')
case.save()
case = CommCareCase.get(case.get_id)
case.server_modified_on = datetime(2015, 1, 1)
self.assertFalse(self.rule2.rule_matches_case(case, datetime(2016, 1, 1)))
case.delete()
示例9: create_and_test
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get [as 别名]
def create_and_test(case_id, user, owner, should_have, should_not_have, version):
case_block = self.get_create_block(
case_id=case_id, type="case", user_id=user.user_id, owner_id=owner.get_id, version=version
)
post_case_blocks([case_block], {"domain": self.domain})
CommCareCase.get(case_id)
check_has_block(case_block, should_have, should_not_have, version=version)
示例10: _check_state
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get [as 别名]
def _check_state(self, new_owner_id, expected_changed):
expected_ids = set(c._id for c in expected_changed)
for case in expected_changed:
expected = CommCareCase.get(case._id)
self.assertEqual(new_owner_id, expected.owner_id)
for case in (c for c in self.all if c._id not in expected_ids):
remaining = CommCareCase.get(case._id)
self.assertEqual(self.original_owner._id, remaining.owner_id)
示例11: tearDown
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get [as 别名]
def tearDown(self):
try:
# delete case, so that post of xform_xml creates new case as expected multiple-times
CommCareCase.get(case_id).delete()
except:
pass
for repeat_record in self.repeat_records(self.domain_name):
repeat_record.delete()
示例12: test_repeater
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get [as 别名]
def test_repeater(self):
CommCareCase.get(case_id)
def now():
return datetime.utcnow()
repeat_records = RepeatRecord.all(domain=self.domain, due_before=now())
self.assertEqual(len(repeat_records), 2)
self.clear_log()
for repeat_record in repeat_records:
repeat_record.fire(post_fn=self.make_post_fn([404, 404, 404]))
repeat_record.save()
for (url, status, data, headers) in self.log:
self.assertEqual(status, 404)
self.clear_log()
next_check_time = now() + timedelta(minutes=60)
repeat_records = RepeatRecord.all(domain=self.domain, due_before=now() + timedelta(minutes=15))
self.assertEqual(len(repeat_records), 0)
repeat_records = RepeatRecord.all(domain=self.domain, due_before=next_check_time + timedelta(seconds=2))
self.assertEqual(len(repeat_records), 2)
for repeat_record in repeat_records:
self.assertLess(abs(next_check_time - repeat_record.next_check), timedelta(seconds=2))
repeat_record.fire(post_fn=self.make_post_fn([404, 200]))
repeat_record.save()
self.assertEqual(len(self.log), 4)
self.assertEqual(self.log[1][:3], (self.form_repeater.url, 200, xform_xml))
self.assertIn('received-on', self.log[1][3])
self.assertEqual(self.log[3][:2], (self.case_repeater.url, 200))
self.assertIn('server-modified-on', self.log[3][3])
check_xml_line_by_line(self, self.log[3][2], case_block)
repeat_records = RepeatRecord.all(domain=self.domain, due_before=next_check_time)
for repeat_record in repeat_records:
self.assertEqual(repeat_record.succeeded, True)
self.assertEqual(repeat_record.next_check, None)
repeat_records = RepeatRecord.all(domain=self.domain, due_before=now())
self.assertEqual(len(repeat_records), 0)
self.post_xml(update_xform_xml)
repeat_records = RepeatRecord.all(domain=self.domain, due_before=now())
self.assertEqual(len(repeat_records), 2)
示例13: filter_cases
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get [as 别名]
def filter_cases(request, domain, app_id, module_id):
app = Application.get(app_id)
module = app.get_module(module_id)
delegation = request.GET.get('task-list') == 'true'
auth_cookie = request.COOKIES.get('sessionid')
xpath = SuiteGenerator(app).get_filter_xpath(module, delegation=delegation)
# touchforms doesn't like this to be escaped
xpath = HTMLParser.HTMLParser().unescape(xpath)
if delegation:
case_type = DELEGATION_STUB_CASE_TYPE
else:
case_type = module.case_type
if xpath:
# if we need to do a custom filter, send it to touchforms for processing
additional_filters = {
"properties/case_type": case_type,
"footprint": True
}
result = touchforms_api.filter_cases(domain, request.couch_user,
xpath, additional_filters,
auth=DjangoAuth(auth_cookie))
if result.get('status', None) == 'error':
return HttpResponseServerError(
result.get("message", _("Something went wrong filtering your cases.")))
case_ids = result.get("cases", [])
else:
# otherwise just use our built in api with the defaults
case_ids = [res.id for res in get_filtered_cases(
domain, status=CASE_STATUS_OPEN, case_type=case_type,
user_id=request.couch_user._id, ids_only=True
)]
cases = [CommCareCase.get(id) for id in case_ids]
# refilter these because we might have accidentally included footprint cases
# in the results from touchforms. this is a little hacky but the easiest
# (quick) workaround. should be revisted when we optimize the case list.
cases = filter(lambda c: c.type == case_type, cases)
cases = [c.get_json() for c in cases if c]
parents = []
if delegation:
for case in cases:
parent_id = case['indices']['parent']['case_id']
parents.append(CommCareCase.get(parent_id))
return json_response({
'cases': cases,
'parents': parents
})
else:
return json_response(cases)
示例14: _check_state
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get [as 别名]
def _check_state(self, new_owner_id, expected_changed, update=None):
expected_ids = set(c._id for c in expected_changed)
for case in expected_changed:
expected = CommCareCase.get(case._id)
self.assertEqual(new_owner_id, expected.owner_id)
if update:
for prop, value in update.items():
self.assertEqual(getattr(expected, prop), value)
for case in (c for c in self.all if c._id not in expected_ids):
remaining = CommCareCase.get(case._id)
self.assertEqual(self.original_owner._id, remaining.owner_id)
示例15: testActionComparison
# 需要导入模块: from casexml.apps.case.models import CommCareCase [as 别名]
# 或者: from casexml.apps.case.models.CommCareCase import get [as 别名]
def testActionComparison(self):
user_id = 'test-action-comparison-user'
case_id = _post_util(create=True, property='a1 wins', user_id=user_id)
_post_util(case_id=case_id, property='a2 wins', user_id=user_id)
_post_util(case_id=case_id, property='a3 wins', user_id=user_id)
# check initial state
case = CommCareCase.get(case_id)
create, a1, a2, a3 = deepcopy(list(case.actions))
self.assertEqual('a3 wins', case.property)
self.assertEqual(a1.updated_unknown_properties['property'], 'a1 wins')
self.assertEqual(a2.updated_unknown_properties['property'], 'a2 wins')
self.assertEqual(a3.updated_unknown_properties['property'], 'a3 wins')
def _confirm_action_order(case, expected_actions):
actual_actions = case.actions[1:] # always assume create is first and removed
for expected, actual in zip(expected_actions, actual_actions):
self.assertEqual(expected.updated_unknown_properties['property'],
actual.updated_unknown_properties['property'])
_confirm_action_order(case, [a1, a2, a3])
# test initial rebuild does nothing
update_strategy = ActionsUpdateStrategy(case)
update_strategy.soft_rebuild_case()
_confirm_action_order(case, [a1, a2, a3])
# test sorting by server date
case.actions[2].server_date = case.actions[2].server_date + timedelta(days=1)
update_strategy.soft_rebuild_case()
_confirm_action_order(case, [a1, a3, a2])
# test sorting by date within the same day
case = CommCareCase.get(case_id)
_confirm_action_order(case, [a1, a2, a3])
case.actions[2].date = case.actions[3].date + timedelta(minutes=1)
ActionsUpdateStrategy(case).soft_rebuild_case()
_confirm_action_order(case, [a1, a3, a2])
# test original form order
case = CommCareCase.get(case_id)
case.actions[3].server_date = case.actions[2].server_date
case.actions[3].date = case.actions[2].date
case.xform_ids = [a1.xform_id, a3.xform_id, a2.xform_id]
ActionsUpdateStrategy(case).soft_rebuild_case()
_confirm_action_order(case, [a1, a3, a2])
# test create comes before update
case = CommCareCase.get(case_id)
case.actions = [a1, create, a2, a3]
ActionsUpdateStrategy(case).soft_rebuild_case()
_confirm_action_order(case, [a1, a2, a3])