def test_generate_csv_from_xml(self): root_dir_xml = os.path.join(self.__tempfolder.name, str(uuid.uuid4()), str(uuid.uuid4())) root_dir_csv = os.path.join(self.__tempfolder.name, str(uuid.uuid4()), str(uuid.uuid4())) work_dir = os.path.join(self.__tempfolder.name, "work") xml_string = '''<TDSReport> <Test subject="MATH" testId="SBAC-FT-SomeDescription-ELA-7" grade="3" assessmentType="Summative" academicYear="2014" /> <Examinee key="12"> <ExamineeRelationship context="INITIAL" name="StateAbbreviation" entityKey="3" value="CA" contextDate="2014-04-14T11:13:41.803"/> </Examinee> <Opportunity> <Item position="position_value" segmentId="segmentId_value" bankKey="test" key="key_value" operational="operational_value" isSelected="isSelected_value" format="format_type_value" score="score_value" scoreStatus="scoreStatus_value" adminDate="adminDate_value" numberVisits="numberVisits_value" mimeType="test" strand="strand_value" contentLevel="contentLevel_value" pageNumber="pageNumber_value" pageVisits="pageVisits_value" pageTime="pageTime_value" dropped="dropped_value"> </Item> </Opportunity> </TDSReport>''' meta_names = Meta(True, 'test1', 'test2', 'test3', 'test4', 'test5', 'test6', 'test7', 'test8', 'test9') xml_file_path = create_path(root_dir_xml, meta_names, generate_path_to_raw_xml) file_writer(xml_file_path, xml_string) rows = [] csv_file_path = create_path(root_dir_csv, meta_names, generate_path_to_item_csv) generate_csv_from_xml(meta_names, csv_file_path, xml_file_path, work_dir, metadata_queue='test') with open(csv_file_path, newline='') as csv_file: csv_reader = csv.reader(csv_file, delimiter=',') for row in csv_reader: rows.append(row) csv_first_row_list = ['key_value', 'test1', 'segmentId_value', 'position_value', '', 'operational_value', 'isSelected_value', 'format_type_value', 'score_value', 'scoreStatus_value', 'adminDate_value', 'numberVisits_value', 'strand_value', 'contentLevel_value', 'pageNumber_value', 'pageVisits_value', 'pageTime_value', 'dropped_value'] self.assertEqual(1, len(rows)) self.assertEqual(csv_first_row_list, rows[0])
def test_process_assessment_data(self): base_dir = os.path.join(self.__tempfolder.name, 'work') xml_string = '''<TDSReport> <Test subject="MATH" grade="3" testId="SBAC-FT-SomeDescription-ELA-7" assessmentType="Summative" academicYear="2014" /> <Examinee key="134"> <ExamineeRelationship context="INITIAL" name="StateAbbreviation" entityKey="3" value="CA" contextDate="2014-04-14T11:13:41.803"/> </Examinee> <Opportunity> </Opportunity> </TDSReport>''' meta = Meta(True, 'test1', 'state_code', 'test3', 'test4', 'test5', 'test6', 'test7', 'test8', 'asmt_id') root = ET.fromstring(xml_string) process_assessment_data(root, meta) # test asmt guids asmt_guids = get_all_assessment_guids() self.assertIsNotNone(asmt_guids) state_code, asmt_guid = next(iter(asmt_guids)) self.assertEqual(state_code, 'CA') self.assertEqual(asmt_guid, 'SBAC-FT-SomeDescription-ELA-7') # test metadata with TSBDBConnection() as conn: asmt_meta = get_metadata(conn, asmt_guid) self.assertIsNotNone(asmt_meta) self.assertIsNotNone(asmt_meta[0][Constants.CONTENT]) assessments = get_assessments(asmt_guid) self.assertIsNotNone(assessments) self.assertEqual(len(assessments), 3) guids, rows, headers = assessments self.assertIsNotNone(guids) self.assertIsNotNone(rows) self.assertEqual(len(headers), 90)
def test_create_path_invalid(self): meta = Meta(True, 'NA', 'state_name', 'district_id', 'academic_year', 'asmt_type', 'subject', 'grade', 'effective_date', 'asmt_id') path = os.path.join(self.__temp_dir.name, 'student_id', 'STATE_NAME', 'district_id', 'academic_year', 'asmt_type', 'subject', 'grade', 'effective_date') create_path_result = create_path(self.__temp_dir.name, meta, generate_path_to_raw_xml) self.assertNotEqual(path, create_path_result)
def test_generate_csv_from_xml_parse_error(self): root_dir_xml = os.path.join(self.__tempfolder.name, str(uuid.uuid4()), str(uuid.uuid4())) root_dir_csv = os.path.join(self.__tempfolder.name, str(uuid.uuid4()), str(uuid.uuid4())) work_dir = os.path.join(self.__tempfolder.name, "work") xml_string = "bad xml" meta_names = Meta(True, 'test1', 'test2', 'test3', 'test4', 'test5', 'test6', 'test7', 'test8', 'test9') xml_file_path = create_path(root_dir_xml, meta_names, generate_path_to_raw_xml) file_writer(xml_file_path, xml_string) csv_file_path = create_path(root_dir_csv, meta_names, generate_path_to_item_csv) self.assertRaises(TSBException, generate_csv_from_xml, meta_names, csv_file_path, xml_file_path, work_dir, metadata_queue='test')
def test_get_all_item_level_for_tsb_csv(self): xml_string = '''<TestXML> <ElementOne key=""> <ElementTwo context="FINAL" name="dummyValue" value="DummyState" /> </ElementOne><Opportunity> <Item position="test" segmentId="segmentId_value" bankKey="test" key="key_value" operational="test" isSelected="test" format="test" score="test" scoreStatus="test" adminDate="test" numberVisits="test" mimeType="test" strand="test" contentLevel="test" pageNumber="test" pageVisits="test" pageTime="test" dropped="test"> </Item> </Opportunity></TestXML>''' root = ET.fromstring(xml_string) meta = Meta(True, '213', None, None, None, None, None, None, None, None) row = item_level_utils.get_item_level_data(root, meta) self.assertEqual('key_value', row[0][0]) self.assertEqual('segmentId_value', row[0][2])
def test_generate_csv_from_xml_parse_exception_written(self, mock_process_item_level_data): mock_process_item_level_data.return_value = True root_dir_xml = os.path.join(self.__tempfolder.name, str(uuid.uuid4()), str(uuid.uuid4())) root_dir_csv = os.path.join(self.__tempfolder.name, str(uuid.uuid4()), str(uuid.uuid4())) work_dir = os.path.join(self.__tempfolder.name, "work") xml_string = '''<TDSReport> <Test subject="MATH" grade="3" assessmentType="Summative" academicYear="2014" /> <Examinee key="12"> <Opportunity> <Item position="position_value" segmentId="segmentId_value" bankKey="test" key="key_value" operational="operational_value" isSelected="isSelected_value" format="format_type_value" score="score_value" scoreStatus="scoreStatus_value" adminDate="adminDate_value" numberVisits="numberVisits_value" mimeType="test" strand="strand_value" contentLevel="contentLevel_value" pageNumber="pageNumber_value" pageVisits="pageVisits_value" pageTime="pageTime_value" dropped="dropped_value"> </Item> </Opportunity> </TDSReport>''' meta_names = Meta(True, 'test1', 'test2', 'test3', 'test4', 'test5', 'test6', 'test7', 'test8', 'test9') xml_file_path = create_path(root_dir_xml, meta_names, generate_path_to_raw_xml) file_writer(xml_file_path, xml_string) csv_file_path = create_path(root_dir_csv, meta_names, generate_path_to_item_csv) self.assertRaises(TSBException, generate_csv_from_xml, meta_names, csv_file_path, xml_file_path, work_dir, metadata_queue='test')