def testParseWithIndices(self): self.testParseCreate() user_id = "bar-user-id" for prereq in ["some_referenced_id", "some_other_referenced_id"]: post_case_blocks( [ CaseBlock(create=True, case_id=prereq, user_id=user_id, version=V2).as_xml( format_datetime=json_format_datetime ) ] ) file_path = os.path.join(os.path.dirname(__file__), "data", "v2", "index_update.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("foo-case-id") self.assertEqual(2, len(case.indices)) self.assertTrue(case.has_index("foo_ref")) self.assertTrue(case.has_index("baz_ref")) self.assertEqual("bar", case.get_index("foo_ref").referenced_type) self.assertEqual("some_referenced_id", case.get_index("foo_ref").referenced_id) self.assertEqual("bop", case.get_index("baz_ref").referenced_type) self.assertEqual("some_other_referenced_id", case.get_index("baz_ref").referenced_id) # check the action self.assertEqual(2, len(case.actions)) [_, index_action] = case.actions self.assertEqual(const.CASE_ACTION_INDEX, index_action.action_type) self.assertEqual(2, len(index_action.indices)) # quick test for ota restore v2response = phone_views.xml_for_case(HttpRequest(), case.get_id, version="2.0") expected_v2_response = """ <case case_id="foo-case-id" date_modified="2011-12-07T13:42:50Z" user_id="bar-user-id" xmlns="http://commcarehq.org/case/transaction/v2"> <create> <case_type>v2_case_type</case_type> <case_name>test case name</case_name> <owner_id>bar-user-id</owner_id> </create> <index> <baz_ref case_type="bop">some_other_referenced_id</baz_ref> <foo_ref case_type="bar">some_referenced_id</foo_ref> </index> </case>""" check_xml_line_by_line(self, expected_v2_response, v2response.content)
def testWithReferrals(self): self.assertEqual(0, CommCareCase.view( "case/by_user", reduce=False, include_docs=True, ).count()) file_path = os.path.join(os.path.dirname(__file__), "data", "case_create.xml") with open(file_path, "rb") as f: xml_data = f.read() form = post_xform_to_couch(xml_data) process_cases(form) newcase = CommCareCase.view( "case/by_user", reduce=False, include_docs=True, ).one() self.assertEqual(0, len(newcase.referrals)) file_path = os.path.join(os.path.dirname(__file__), "data", "case_refer.xml") with open(file_path, "rb") as f: xml_data = f.read() form = post_xform_to_couch(xml_data) process_cases(form) [updated_case] = CommCareCase.view("case/by_user", reduce=False, include_docs=True).all() self.assertEqual(1, len(updated_case.referrals)) response = views.xml_for_case(HttpRequest(), updated_case.get_id) expected_response = """<case> <case_id>IKA9G79J4HDSPJLG3ER2OHQUY</case_id> <date_modified>2011-02-19T16:46:28Z</date_modified> <create> <case_type_id>cc_mobilize_client</case_type_id> <user_id>ae179a62-38af-11e0-b6a3-005056aa7fb5</user_id> <case_name>SIEGEL-ROBERT-5412366523984</case_name> <external_id>5412366523984</external_id> </create> <update> <Problems></Problems> <abdominalpain></abdominalpain> <address></address> <addstaff1></addstaff1> <addstaff2></addstaff2> <allmeds_likert></allmeds_likert> <arv_lasttreatment></arv_lasttreatment> <arv_missedtreatments></arv_missedtreatments> <arv_taking></arv_taking> <assistance></assistance> <confusion></confusion> <contact_age_alt></contact_age_alt> <contact_name_alt></contact_name_alt> <contact_phone_alt></contact_phone_alt> <deafness></deafness> <depression></depression> <diarrhea></diarrhea> <dob>2011-02-11</dob> <gender>male</gender> <given_name>ROBERT</given_name> <imbalance></imbalance> <injectionother></injectionother> <injectiontype></injectiontype> <jaundice></jaundice> <jointpain></jointpain> <legal_name>ROBERT SIEGEL</legal_name> <musclepain></musclepain> <muscleweakness></muscleweakness> <nickname>BOB</nickname> <other></other> <patient_dot>123</patient_dot> <patient_id>5412366523984</patient_id> <phone_number>1</phone_number> <place></place> <psychosis></psychosis> <rash></rash> <request_name>ME</request_name> <request_rank>staff_nurse</request_rank> <request_reason></request_reason> <request_timestamp>2011-02-19T16:46:28Z</request_timestamp> <ringing></ringing> <seizures></seizures> <short_name>SIEGEL, ROBERT</short_name> <sleeping></sleeping> <staffnumber1></staffnumber1> <staffnumber2></staffnumber2> <staffnumber3></staffnumber3> <surname>SIEGEL</surname> <swelling></swelling> <tb_lasttreatment></tb_lasttreatment> <tb_missedtreatments></tb_missedtreatments> <tbtype></tbtype> <tingling></tingling> <tribal_area></tribal_area> <txoutcome></txoutcome> <txstart>2011-02-11</txstart> <vision></vision> <vomiting></vomiting> </update> <referral> <referral_id>V2RLNE4VQYEMZRGYSOMLYU4PM</referral_id> <followup_date>2011-02-20</followup_date> <open> <referral_types>referral</referral_types> </open> </referral> </case>""" check_xml_line_by_line(self, expected_response, response.content) # this is really ridiculous. TODO, get rid of massive text wall x 2 expected_v2_response = """<case xmlns="http://commcarehq.org/case/transaction/v2" case_id="IKA9G79J4HDSPJLG3ER2OHQUY" date_modified="2011-02-19T16:46:28Z" user_id="ae179a62-38af-11e0-b6a3-005056aa7fb5"> <create> <case_type>cc_mobilize_client</case_type> <case_name>SIEGEL-ROBERT-5412366523984</case_name> <owner_id>ae179a62-38af-11e0-b6a3-005056aa7fb5</owner_id> </create> <update> <external_id>5412366523984</external_id> <Problems></Problems> <abdominalpain></abdominalpain> <address></address> <addstaff1></addstaff1> <addstaff2></addstaff2> <allmeds_likert></allmeds_likert> <arv_lasttreatment></arv_lasttreatment> <arv_missedtreatments></arv_missedtreatments> <arv_taking></arv_taking> <assistance></assistance> <confusion></confusion> <contact_age_alt></contact_age_alt> <contact_name_alt></contact_name_alt> <contact_phone_alt></contact_phone_alt> <deafness></deafness> <depression></depression> <diarrhea></diarrhea> <dob>2011-02-11</dob> <gender>male</gender> <given_name>ROBERT</given_name> <imbalance></imbalance> <injectionother></injectionother> <injectiontype></injectiontype> <jaundice></jaundice> <jointpain></jointpain> <legal_name>ROBERT SIEGEL</legal_name> <musclepain></musclepain> <muscleweakness></muscleweakness> <nickname>BOB</nickname> <other></other> <patient_dot>123</patient_dot> <patient_id>5412366523984</patient_id> <phone_number>1</phone_number> <place></place> <psychosis></psychosis> <rash></rash> <request_name>ME</request_name> <request_rank>staff_nurse</request_rank> <request_reason></request_reason> <request_timestamp>2011-02-19T16:46:28Z</request_timestamp> <ringing></ringing> <seizures></seizures> <short_name>SIEGEL, ROBERT</short_name> <sleeping></sleeping> <staffnumber1></staffnumber1> <staffnumber2></staffnumber2> <staffnumber3></staffnumber3> <surname>SIEGEL</surname> <swelling></swelling> <tb_lasttreatment></tb_lasttreatment> <tb_missedtreatments></tb_missedtreatments> <tbtype></tbtype> <tingling></tingling> <tribal_area></tribal_area> <txoutcome></txoutcome> <txstart>2011-02-11</txstart> <vision></vision> <vomiting></vomiting> </update> </case>""" v2response = views.xml_for_case(HttpRequest(), updated_case.get_id, version="2.0") check_xml_line_by_line(self, expected_v2_response, v2response.content)
def testWithReferrals(self): self.assertEqual(0, CommCareCase.view( "case/by_user", reduce=False, include_docs=True, ).count()) file_path = os.path.join(os.path.dirname(__file__), "data", "case_create.xml") with open(file_path, "rb") as f: xml_data = f.read() form = post_xform_to_couch(xml_data) process_cases(form) newcase = CommCareCase.view( "case/by_user", reduce=False, include_docs=True, ).one() self.assertEqual(0, len(newcase.referrals)) file_path = os.path.join(os.path.dirname(__file__), "data", "case_refer.xml") with open(file_path, "rb") as f: xml_data = f.read() form = post_xform_to_couch(xml_data) process_cases(form) [updated_case] = CommCareCase.view("case/by_user", reduce=False, include_docs=True).all() self.assertEqual(1, len(updated_case.referrals)) response = views.xml_for_case(HttpRequest(), updated_case.get_id) expected_response = """<case> <case_id>IKA9G79J4HDSPJLG3ER2OHQUY</case_id> <date_modified>2011-02-19T16:46:28Z</date_modified> <create> <case_type_id>cc_mobilize_client</case_type_id> <user_id>ae179a62-38af-11e0-b6a3-005056aa7fb5</user_id> <case_name>SIEGEL-ROBERT-5412366523984</case_name> <external_id>5412366523984</external_id> </create> <update> <Problems></Problems> <abdominalpain></abdominalpain> <address></address> <addstaff1></addstaff1> <addstaff2></addstaff2> <allmeds_likert></allmeds_likert> <arv_lasttreatment></arv_lasttreatment> <arv_missedtreatments></arv_missedtreatments> <arv_taking></arv_taking> <assistance></assistance> <confusion></confusion> <contact_age_alt></contact_age_alt> <contact_name_alt></contact_name_alt> <contact_phone_alt></contact_phone_alt> <deafness></deafness> <depression></depression> <diarrhea></diarrhea> <dob>2011-02-11</dob> <gender>male</gender> <given_name>ROBERT</given_name> <imbalance></imbalance> <injectionother></injectionother> <injectiontype></injectiontype> <jaundice></jaundice> <jointpain></jointpain> <legal_name>ROBERT SIEGEL</legal_name> <musclepain></musclepain> <muscleweakness></muscleweakness> <nickname>BOB</nickname> <other></other> <patient_dot>123</patient_dot> <patient_id>5412366523984</patient_id> <phone_number>1</phone_number> <place></place> <psychosis></psychosis> <rash></rash> <request_name>ME</request_name> <request_rank>staff_nurse</request_rank> <request_reason></request_reason> <request_timestamp>2011-02-19 16:46:28</request_timestamp> <ringing></ringing> <seizures></seizures> <short_name>SIEGEL, ROBERT</short_name> <sleeping></sleeping> <staffnumber1></staffnumber1> <staffnumber2></staffnumber2> <staffnumber3></staffnumber3> <surname>SIEGEL</surname> <swelling></swelling> <tb_lasttreatment></tb_lasttreatment> <tb_missedtreatments></tb_missedtreatments> <tbtype></tbtype> <tingling></tingling> <tribal_area></tribal_area> <txoutcome></txoutcome> <txstart>2011-02-11</txstart> <vision></vision> <vomiting></vomiting> </update> <referral> <referral_id>V2RLNE4VQYEMZRGYSOMLYU4PM</referral_id> <followup_date>2011-02-20</followup_date> <open> <referral_types>referral</referral_types> </open> </referral> </case>""" check_xml_line_by_line(self, expected_response, response.content) # this is really ridiculous. TODO, get rid of massive text wall x 2 expected_v2_response = """<case xmlns="http://commcarehq.org/case/transaction/v2" case_id="IKA9G79J4HDSPJLG3ER2OHQUY" date_modified="2011-02-19T16:46:28Z" user_id="ae179a62-38af-11e0-b6a3-005056aa7fb5"> <create> <case_type>cc_mobilize_client</case_type> <case_name>SIEGEL-ROBERT-5412366523984</case_name> <owner_id>ae179a62-38af-11e0-b6a3-005056aa7fb5</owner_id> </create> <update> <external_id>5412366523984</external_id> <Problems></Problems> <abdominalpain></abdominalpain> <address></address> <addstaff1></addstaff1> <addstaff2></addstaff2> <allmeds_likert></allmeds_likert> <arv_lasttreatment></arv_lasttreatment> <arv_missedtreatments></arv_missedtreatments> <arv_taking></arv_taking> <assistance></assistance> <confusion></confusion> <contact_age_alt></contact_age_alt> <contact_name_alt></contact_name_alt> <contact_phone_alt></contact_phone_alt> <deafness></deafness> <depression></depression> <diarrhea></diarrhea> <dob>2011-02-11</dob> <gender>male</gender> <given_name>ROBERT</given_name> <imbalance></imbalance> <injectionother></injectionother> <injectiontype></injectiontype> <jaundice></jaundice> <jointpain></jointpain> <legal_name>ROBERT SIEGEL</legal_name> <musclepain></musclepain> <muscleweakness></muscleweakness> <nickname>BOB</nickname> <other></other> <patient_dot>123</patient_dot> <patient_id>5412366523984</patient_id> <phone_number>1</phone_number> <place></place> <psychosis></psychosis> <rash></rash> <request_name>ME</request_name> <request_rank>staff_nurse</request_rank> <request_reason></request_reason> <request_timestamp>2011-02-19 16:46:28</request_timestamp> <ringing></ringing> <seizures></seizures> <short_name>SIEGEL, ROBERT</short_name> <sleeping></sleeping> <staffnumber1></staffnumber1> <staffnumber2></staffnumber2> <staffnumber3></staffnumber3> <surname>SIEGEL</surname> <swelling></swelling> <tb_lasttreatment></tb_lasttreatment> <tb_missedtreatments></tb_missedtreatments> <tbtype></tbtype> <tingling></tingling> <tribal_area></tribal_area> <txoutcome></txoutcome> <txstart>2011-02-11</txstart> <vision></vision> <vomiting></vomiting> </update> </case>""" v2response = views.xml_for_case(HttpRequest(), updated_case.get_id, version="2.0") check_xml_line_by_line(self, expected_v2_response, v2response.content)