def _validate_port_map_list(options_list, id_provider, force_options): allowed_options = [ "id", "port", "internal-port", "range", ] 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, allow_extra_values=force_options), ] 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(), "port-map", report_codes.FORCE_OPTIONS, force_options)) return report_list
def test_returns_no_report_when_second_is_present(self): assert_report_item_list_equal( validate.is_required_some_of(["first", "second"], "type")({ "second": "value", }), [] )
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 test_returns_report_when_missing(self): assert_report_item_list_equal( validate.is_required_some_of(["first", "second"], "type")({ "third": "value", }), [ (severities.ERROR, report_codes.REQUIRED_OPTION_OF_ALTERNATIVES_IS_MISSING, { "option_names": ["first", "second"], "option_type": "type", }, None), ])
def test_returns_report_when_missing(self): assert_report_item_list_equal( validate.is_required_some_of(["first", "second"], "type")({ "third": "value", }), [ ( severities.ERROR, report_codes.REQUIRED_OPTION_OF_ALTERNATIVES_IS_MISSING, { "option_names": ["first", "second"], "option_type": "type", }, None ), ] )
def test_returns_no_report_when_second_is_present(self): assert_report_item_list_equal( validate.is_required_some_of(["first", "second"], "type")({ "second": "value", }), [])