Example #1
0
    def test_multiple_event(self):
        # motivated by bug 5996
        form = etree.fromstring(
            "<form>"
            "  <event><name>42_arm_42</name>"
            "    <field><name>foo</name><value>bar</value></field>"
            "  </event>"
            "  <event><name>no_arm</name>"
            "    <field><name>foo</name><value>bar</value></field>"
            "  </event>"
            "</form>")

        second_event = form.xpath('//event')[1]
        out_dict_3 = {'study_id':self.CONST_STUDY_ID}

        output = upload.create_import_data_json(out_dict_3, second_event)
        self.assertTrue(output['contains_data'])
        self.assertFalse('42_arm_42' in output['json_data']['redcap_event_name'])
        self.assertTrue('no_arm' in output['json_data']['redcap_event_name'])
Example #2
0
    def test_empty_event_field_value(self):
        logging.info("Running " + __name__ 
            + "#test_empty_value() for study_id: " + `self.CONST_STUDY_ID`)
        # Case 2 input string
        string_2_empty_values = """
<event>
    <name>1_arm_1</name>
    <field>
        <name>chem_lbdtc</name>
        <value/>
    </field>
    <field>
        <name>chem_complete</name>
        <value/>
    </field>
    <field>
        <name>chem_nximport</name>
        <value/>
    </field>
    <field>
        <name>tbil_lborres</name>
        <value/>
    </field>
    <field>
        <name>tbil_lborresu</name>
        <value/>
    </field>
</event>"""

        string_2_out = """
record,redcap_event_name,field_name,value
73,"1_arm_1",chem_lbdtc,""
73,"1_arm_1",chem_complete,""
73,"1_arm_1",chem_nximport,""
73,"1_arm_1",tbil_lborres,""
73,"1_arm_1",tbil_lborresu,""
"""

        etree_2 = etree.ElementTree(etree.fromstring(string_2_empty_values))
        out_dict_2 = {'study_id':self.CONST_STUDY_ID}
        expected_result_dict_2 = {'contains_data': False, 'json_data': {'chem_complete': '', 'redcap_event_name': '1_arm_1', 'tbil_lborres': '', 'study_id': 73, 'chem_nximport': '', 'tbil_lborresu': '', 'chem_lbdtc': ''}}
        actual_result = upload.create_import_data_json(out_dict_2, etree_2)
        self.assertEqual(expected_result_dict_2,actual_result)
Example #3
0
    def test_mixed_event_field_value(self):
        logging.info("Running " + __name__ 
            + "#test_mixed_event_field_value() for study_id: " + `self.CONST_STUDY_ID`)


        string_3_mixed = """
<event>
    <name>1_arm_1</name>
    <field>
        <name>chem_lbdtc</name>
        <value>1902-12-17</value>
    </field>
    <field>
        <name>chem_complete</name>
        <value>2</value>
    </field>
    <field>
        <name>chem_nximport</name>
        <value>Y</value>
    </field>
    <field>
        <name>tbil_lborres</name>
        <value>1.7</value>
    </field>
    <field>
        <name>tbil_lborresu</name>
        <value/>
    </field>
</event>"""

        string_3_out = """
record,redcap_event_name,field_name,value
73,"1_arm_1",chem_lbdtc,"1902-12-17"
73,"1_arm_1",chem_complete,"2"
73,"1_arm_1",chem_nximport,"Y"
73,"1_arm_1",tbil_lborres,"1.7"
73,"1_arm_1",tbil_lborresu,""
"""
        etree_3 = etree.ElementTree(etree.fromstring(string_3_mixed))
        out_dict_3 = {'study_id':self.CONST_STUDY_ID}
        actual_result = upload.create_import_data_json(out_dict_3, etree_3)
        expected_result = {'contains_data': True, 'json_data': {'chem_complete': '2', 'redcap_event_name': '1_arm_1', 'tbil_lborres': '1.7', 'study_id': 73, 'chem_nximport': 'Y', 'tbil_lborresu': '', 'chem_lbdtc': '1902-12-17'}}
        self.assertEqual(actual_result, expected_result)