def test_create_org_element_2(self) : try : testXMLFile = "crises/test_data/WorldCrises_bad_org.xml" root = read_and_validate_xml (testXMLFile) model = create_org_element (root[2]) assert(False) except : assert(True)
def parse_models (root, all_models, is_merge) : """ Parse all models under root (<WorldCrises>) and use ModelFactory to build models """ assert root.tag == 'WorldCrises' existingIDs = [] # Read all existing element IDs if merging if is_merge : existingElems = WCDBElement.objects.all() for elem in existingElems : existingIDs.append(elem.ID) for child in root : assert child.tag in ['Crisis', 'Person', 'Organization'] r_co = r_cp = r_op = [] text = None if child.tag == 'Crisis' : if child.attrib['ID'] in existingIDs : print child.attrib['ID'] + ' exists!' (crisis_id, new_model, list_types, list_elements, r_co, r_cp) = merge_crisis_content (child) else : (crisis_id, new_model, list_types, list_elements, r_co, r_cp, text) = create_crisis_element (child) all_models['crises'][crisis_id] = new_model elif child.tag == 'Person' : if child.attrib['ID'] in existingIDs : print child.attrib['ID'] + ' exists!' (person_id, new_model, list_types, list_elements, r_cp, r_op) = merge_person_content (child) else : (person_id, new_model, list_types, list_elements, r_cp, r_op, text) = create_person_element (child) all_models['people'][person_id] = new_model elif child.tag == 'Organization' : if child.attrib['ID'] in existingIDs : print child.attrib['ID'] + ' exists!' (org_id, new_model, list_types, list_elements, r_co, r_op) = merge_org_content (child) else : (org_id, new_model, list_types, list_elements, r_co, r_op, text) = create_org_element (child) all_models['orgs'][org_id] = new_model else : # should never reach here pass all_models['list_types'] += list_types all_models['list_elements'] += list_elements if not text == None : all_models['texts'].append(text) all_models['rel_crisis_org'] += r_co all_models['rel_crisis_person'] += r_cp all_models['rel_org_person'] += r_op
def test_create_org_element_1(self) : testXMLFile = "crises/test_data/WorldCrises_good.xml" root = read_and_validate_xml (testXMLFile) model = create_org_element (root[2]) assert(model[0] == "ORG_PMRLFD") assert(type(model[1]) is Organization)