예제 #1
0
def _test_refer_case_payload_generator(initial_case_properties,
                                       expected_referral_props):
    domain = "source_domain"
    repeater = ReferCaseRepeater(domain=domain)
    generator = ReferCasePayloadGenerator(repeater)
    generator.submission_user_id = Mock(return_value='user1')
    generator.submission_username = Mock(return_value='user1')
    transfer_case = CommCareCase(type="transfer",
                                 case_json={
                                     "cases_to_forward": "case1",
                                     "new_owner": "owner1",
                                     "case_types": "patient",
                                     "patient_whitelist": "copy_this"
                                 })
    copy_value = uuid.uuid4().hex
    properties = {"copy_this": copy_value}
    properties.update(initial_case_properties or {})
    target_case = CommCareCase(case_id="1",
                               type="patient",
                               case_json=properties)
    with patch.object(CommCareCase.objects,
                      "get_cases",
                      return_value=[target_case]):
        form = generator.get_payload(None, transfer_case)
        formxml = ElementTree.fromstring(form)
        case = CaseBlock.from_xml(formxml.find("{%s}case" % V2_NAMESPACE))
        expected_update = {
            "cchq_referral_source_domain": domain,
            "cchq_referral_source_case_id": "1",
            "copy_this": copy_value
        }
        expected_update.update(expected_referral_props)
        eq(case.update, expected_update)
예제 #2
0
 def cases(self):
     """Dict of cases, keyed by case ID, from the sync body"""
     return {
         case.case_id: case
         for case in (CaseBlock.from_xml(node)
                      for node in self.xml.findall("{%s}case" %
                                                   V2_NAMESPACE))
     }
예제 #3
0
파일: utils.py 프로젝트: dimagi/commcare-hq
 def cases(self):
     """Dict of cases, keyed by case ID, from the sync body"""
     return {case.case_id: case for case in (CaseBlock.from_xml(node)
             for node in self.xml.findall("{%s}case" % V2_NAMESPACE))}