예제 #1
0
 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()))
예제 #2
0
 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()))
예제 #3
0
 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")}),
         [],
     )
예제 #4
0
 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")}
         ),
         [],
     )
예제 #5
0
 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")}
         ),
         [],
     )
예제 #6
0
 def test_returns_empty_report_on_valid_normalized_option(self):
     self.assertEqual(
         [],
         validate.value_in("a", ["b"])({
             "a":
             validate.ValuePair(original="C", normalized="b")
         }),
     )
예제 #7
0
 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")
         }),
     )
예제 #8
0
 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",
             }
         ),
     )
예제 #9
0
 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),
         ])
예제 #10
0
 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),
         ])
예제 #11
0
 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,
             ),
         ])
예제 #12
0
 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,
                 ),
             ])
예제 #13
0
 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",
             ),
         ])
예제 #14
0
 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",
             ),
         ],
     )
예제 #15
0
 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,
             )
         ],
     )
예제 #16
0
 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),
         ])
예제 #17
0
 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),
         ])