def test_add_clause_at_root(self): # a given clause is added to the XML tree xqe = XMLQueryEditor.XMLQueryEditor("test") prev_number_of_clauses = len( xqe.get_tree().getroot().findall(".//clause")) clause = xqe.generate_clause(operator="OR", field="subject", value="Quellenforschung", lang="de") xqe.add_clausular_element(clausular_element=clause) new_number_of_clauses = len( xqe.get_tree().getroot().findall(".//clause")) self.assertEquals(prev_number_of_clauses + 1, new_number_of_clauses) last_child = xqe.get_tree().getroot().findall(".//clause")[-1] self.assertEquals(last_child.find("value").text, "Quellenforschung")
def test_convert_to_clause_group(self): xqe = XMLQueryEditor.XMLQueryEditor("test") start_node = xqe.retrieve_node_by_id("4") start_op = start_node.attrib["operator"] start_neg = start_node.attrib["negated"] start_lang = start_node.attrib[ "{http://www.w3.org/XML/1998/namespace}lang"] xqe.convert_to_clause_group("4") # we now test that the clause has a new position ... found_node = xqe._tree.getroot().find( "./clause-group/clause-group/clause-group/clause[@node-id=\"4\"]") self.assertIsNotNone(found_node) # ... but is otherwise unchanged end_op = found_node.attrib["operator"] end_neg = found_node.attrib["negated"] # TODO: why do I need to namespace here, but not in earlier tests? end_lang = found_node.attrib[ "{http://www.w3.org/XML/1998/namespace}lang"] self.assertEquals(start_op, end_op) self.assertEquals(start_neg, end_neg) self.assertEquals(start_lang, end_lang)
def test_reading_directory(self): xqe = XMLQueryEditor.XMLQueryEditor("test") query_list = xqe.read_query_directory() self.assertGreater(len(query_list), 1) self.assertIn("test", query_list)
def test_facet_query_does_not_exclude_on_AND(self): xqe = XMLQueryEditor.XMLQueryEditor("test") facet_query = xqe.get_facet_query_for_clause("1") self.assertEquals( "(-proxy_dc_subject:\"test\" OR proxy_dc_subject:\"l'examen\" OR (CREATOR:\"Leonardo da Vinci\"))", facet_query)
def test_facet_query_excludes_on_OR(self): xqe = XMLQueryEditor.XMLQueryEditor("test") facet_query = xqe.get_facet_query_for_clause("4") self.assertEquals(facet_query, "title:\"test title\"")
def test_force_operator_conversion_raises_error_if_no_results(self): xqe = XMLQueryEditor.XMLQueryEditor("test") self.assertRaises(ZeroResultsException, xqe.set_all_operators, "OR", "5")
def test_clause_conversion_triggers_inconsistency_error_as_needed(self): xqe = XMLQueryEditor.XMLQueryEditor("test") self.assertRaises(InconsistentOperatorException, xqe.ungroup_clause_group, "5")
def test_deprecating_first_clause_in_group_removes_subsequent_operator( self): xqe = XMLQueryEditor.XMLQueryEditor("test") xqe.deprecate_by_id("3") self.assertEquals( xqe.retrieve_node_by_id("4").attrib["operator-suppressed"], "true")
def test_no_operator_for_clause_group_when_all_clauses_deprecated(self): xqe = XMLQueryEditor.XMLQueryEditor("test") xqe.deprecate_by_id("6") xqe.deprecate_by_id("7") self.assertEquals( xqe.retrieve_node_by_id("5").attrib["operator-suppressed"], "true")
def test_serialisation_to_query(self): # the XML needs to be converted appropriately to query form xqe = XMLQueryEditor.XMLQueryEditor("test") serialised_query = xqe.serialise_to_solr_query() expected = "title:\"test title\" AND (-proxy_dc_subject:\"test\" OR proxy_dc_subject:\"l'examen\" OR (CREATOR:\"Leonardo da Vinci\"))" self.assertEquals(serialised_query, expected)
def test_remove_first_clause_has_no_operator_effect_on_third(self): # need to ensure that this effect does not spread too far xqe = XMLQueryEditor.XMLQueryEditor("test") xqe.remove_node_by_id("3") new_first_node = xqe.retrieve_node_by_id("5") self.assertEquals(new_first_node.attrib["operator"], "OR")
def test_unnegate_clause(self): xqe = XMLQueryEditor.XMLQueryEditor("test") xqe.unnegate_by_id("3") el_is_negated = xqe.retrieve_node_by_id("3").attrib["negated"] self.assertEquals(el_is_negated, "false")
def test_negate_clause(self): # the negation (NOT) flag is correctly set and unset on clauses xqe = XMLQueryEditor.XMLQueryEditor("test") xqe.negate_by_id("1") el_is_negated = xqe.retrieve_node_by_id("1").attrib["negated"] self.assertEquals(el_is_negated, "true")
def test_xml_loaded(self): # XML is correctly loaded and parsed xqe = XMLQueryEditor.XMLQueryEditor("test") root_node_name = xqe.get_tree().getroot().tag self.assertEquals(root_node_name, 'query')