def test_create_from_plain_values(self): self.assertEqual( { "first": validate.ValuePair("A", "a"), "second": validate.ValuePair("B", "b"), }, validate.values_to_pairs({ "first": "A", "second": "B", }, lambda key, value: value.lower()))
def test_keep_pair_if_is_already_there(self): self.assertEqual( { "first": validate.ValuePair("A", "aaa"), "second": validate.ValuePair("B", "b"), }, validate.values_to_pairs( { "first": validate.ValuePair("A", "aaa"), "second": "B", }, lambda key, value: value.lower()))
def test_pair_success(self): id_provider = IdProvider(etree.fromstring("<a><test id='used' /></a>")) assert_report_item_list_equal( validate.ValueId("id", id_provider=id_provider).validate( {"id": validate.ValuePair("correct", "correct")}), [], )
def test_returns_empty_report_on_valid_normalized_option(self): assert_report_item_list_equal( validate.ValueIn("a", ["b"]).validate( {"a": validate.ValuePair(original="C", normalized="b")} ), [], )
def test_returns_empty_report_on_valid_normalized_option(self): assert_report_item_list_equal( ValuePredicateImplementation("a").validate( {"a": validate.ValuePair(original="C", normalized="b")} ), [], )
def test_returns_empty_report_on_valid_normalized_option(self): self.assertEqual( [], validate.value_in("a", ["b"])({ "a": validate.ValuePair(original="C", normalized="b") }), )
def test_returns_empty_report_on_valid_normalized_option(self): self.assertEqual( [], validate.value_cond("a", self.predicate, "test")({ "a": validate.ValuePair(original="C", normalized="b") }), )
def test_extract_normalized_values(self): self.assertEqual( {"first": "aaa", "second": "B",}, validate.pairs_to_values( { "first": validate.ValuePair(original="A", normalized="aaa"), "second": "B", } ), )
def test_support_OptionValuePair(self): assert_report_item_list_equal( validate.value_in("a", ["b"])({ "a": validate.ValuePair(original="C", normalized="c") }), [ (severities.ERROR, report_codes.INVALID_OPTION_VALUE, { "option_name": "a", "option_value": "C", "allowed_values": ["b"], }, None), ])
def test_support_option_value_pair(self): assert_report_item_list_equal( validate.value_cond("a", self.predicate, "test")({ "a": validate.ValuePair(original="b", normalized="c") }), [ (severities.ERROR, report_codes.INVALID_OPTION_VALUE, { "option_name": "a", "option_value": "b", "allowed_values": "test", }, None), ])
def test_pair_invalid(self): assert_report_item_list_equal( validate.ValueId("id").validate( {"id": validate.ValuePair("@&#", "")}), [ fixture.error( report_codes.EMPTY_ID, # TODO: This should be "@&#". However an old validator # is used and it doesn't work with pairs. id="", id_description=None, ), ])
def test_support_option_value_pair(self): assert_report_item_list_equal( validate.ValueIn("a", ["b"]).validate( {"a": validate.ValuePair(original="C", normalized="c")}), [ fixture.error( report_codes.INVALID_OPTION_VALUE, option_name="a", option_value="C", allowed_values=["b"], cannot_be_empty=False, forbidden_characters=None, ), ])
def test_pair_used_id(self): id_provider = IdProvider(etree.fromstring("<a><test id='used' /></a>")) assert_report_item_list_equal( validate.ValueId("id", id_provider=id_provider).validate( {"id": validate.ValuePair("not-used", "used")}), [ fixture.error( report_codes.ID_ALREADY_EXISTS, # TODO: This should be "not-used". However an old # validator is used and it doesn't work with pairs. id="used", ), ])
def test_pair_invalid(self): assert_report_item_list_equal( validate.ValueId("id").validate( {"id": validate.ValuePair("@&#", "")}), [ fixture.error( reports.codes.INVALID_ID_IS_EMPTY, # TODO: This should be INVALID_ID_BAD_CHAR with value # "@&#". However an old validator is used and it doesn't # work with pairs and therefore the empty string is used. id_description="id", ), ], )
def test_support_option_value_pair(self): assert_report_item_list_equal( ValuePredicateImplementation("a").validate( {"a": validate.ValuePair(original="b", normalized="c")}), [ fixture.error( reports.codes.INVALID_OPTION_VALUE, option_name="a", option_value="b", allowed_values="allowed values", cannot_be_empty=False, forbidden_characters=None, ) ], )
def test_pair_used_id(self): id_provider = IdProvider(etree.fromstring("<a><test id='used' /></a>")) assert_report_item_list_equal( validate.value_id("id", "test id", id_provider)({ "id": validate.ValuePair("not-used", "used") }), [ ( severities.ERROR, report_codes.ID_ALREADY_EXISTS, { # TODO: This should be "not-used". However an old # validator is used and it doesn't work with pairs. "id": "used", }, None), ])
def test_pair_invalid(self): assert_report_item_list_equal( validate.value_id("id", "test id")({ "id": validate.ValuePair("@&#", "") }), [ ( severities.ERROR, report_codes.EMPTY_ID, { # TODO: This should be "@&#". However an old validator # is used and it doesn't work with pairs. "id": "", "id_description": "test id", }, None), ])