def test_pair_success(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("correct", "correct") }), [] )
def test_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": "used"}), [ ( severities.ERROR, report_codes.ID_ALREADY_EXISTS, { "id": "used", }, None ), ] )
def test_empty_id(self): assert_report_item_list_equal( validate.value_id("id", "test id")({"id": ""}), [ ( severities.ERROR, report_codes.EMPTY_ID, { "id": "", "id_description": "test id", }, None ), ] )
def test_invalid_char(self): assert_report_item_list_equal( validate.value_id("id", "test id")({"id": "te#st"}), [ ( severities.ERROR, report_codes.INVALID_ID, { "id": "te#st", "id_description": "test id", "invalid_character": "#", "is_first_char": False, }, 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), ])
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_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 ), ] )
def _validate_port_map_list(options_list, id_provider, force_options): validators = [ validate.value_id("id", "port-map id", id_provider), validate.depends_on_option("internal-port", "port", "port-map", "port-map"), validate.is_required_some_of(["port", "range"], "port-map"), validate.mutually_exclusive(["port", "range"], "port-map"), validate.value_port_number("port"), validate.value_port_number("internal-port"), validate.value_port_range( "range", code_to_allow_extra_values=report_codes.FORCE_OPTIONS, extra_values_allowed=force_options), ] report_list = [] for options in options_list: report_list.extend( validate.run_collection_of_option_validators(options, validators) + validate.names_in(PORT_MAP_OPTIONS, options.keys(), "port-map", report_codes.FORCE_OPTIONS, force_options)) return report_list
def _validate_storage_map_list(options_list, id_provider, force_options): allowed_options = [ "id", "options", "source-dir", "source-dir-root", "target-dir", ] source_dir_options = ["source-dir", "source-dir-root"] validators = [ validate.value_id("id", "storage-map id", id_provider), validate.is_required_some_of(source_dir_options, "storage-map"), validate.mutually_exclusive(source_dir_options, "storage-map"), validate.is_required("target-dir", "storage-map"), ] report_list = [] for options in options_list: report_list.extend( validate.run_collection_of_option_validators(options, validators) + validate.names_in(allowed_options, options.keys(), "storage-map", report_codes.FORCE_OPTIONS, force_options)) return report_list
def validate_operation_list(operation_list, allowed_operation_name_list, allow_invalid=False): options_validators = [ validate.is_required("name", "resource operation"), validate.value_in("role", ROLE_VALUES), validate.value_in("on-fail", ON_FAIL_VALUES), validate.value_in("record-pending", BOOLEAN_VALUES), validate.value_in("enabled", BOOLEAN_VALUES), validate.mutually_exclusive(["interval-origin", "start-delay"], "resource operation"), validate.value_in( "name", allowed_operation_name_list, option_name_for_report="operation name", code_to_allow_extra_values=report_codes.FORCE_OPTIONS, allow_extra_values=allow_invalid, ), validate.value_id("id", option_name_for_report="operation id"), ] report_list = [] for operation in operation_list: report_list.extend(validate_operation(operation, options_validators)) return report_list
def test_success(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": "correct" }), [])