def test_success_on_valid_options(self): report_processor = MockLibraryReportProcessor() config_structure.validate_ticket_options( report_processor, {"timeout": "10"}, allow_unknown_options=False, ) assert_report_item_list_equal(report_processor.report_item_list, [])
def test_success_on_valid_options(self): report_processor = MockLibraryReportProcessor() config_structure.validate_ticket_options( report_processor, {"timeout": "10"}, allow_unknown_options=False, ) assert_report_item_list_equal(report_processor.report_item_list, [])
def test_unknown_options_are_forceable(self): report_processor = MockLibraryReportProcessor() expected_errors = [ ( severities.ERROR, report_codes.INVALID_OPTION, { "option_name": "site", "option_type": "booth ticket", "allowed": list(config_structure.TICKET_KEYS), }, ), ] assert_raise_library_error( lambda: config_structure.validate_ticket_options( report_processor, { "site": "a", "unknown": "c", }, allow_unknown_options=True, ), *expected_errors) assert_report_item_list_equal( report_processor.report_item_list, expected_errors + [ ( severities.WARNING, report_codes.INVALID_OPTION, { "option_name": "unknown", "option_type": "booth ticket", "allowed": list(config_structure.TICKET_KEYS), }, ), ])
def test_raises_on_invalid_options(self): report_processor = MockLibraryReportProcessor() expected_errors = [ ( severities.ERROR, report_codes.INVALID_OPTION, { "option_name": "site", "option_type": "booth ticket", "allowed": list(config_structure.TICKET_KEYS), }, ), ( severities.ERROR, report_codes.INVALID_OPTION, { "option_name": "port", "option_type": "booth ticket", "allowed": list(config_structure.TICKET_KEYS), }, ), ( severities.ERROR, report_codes.INVALID_OPTION_VALUE, { "option_name": "timeout", "option_value": " ", "allowed_values": "no-empty", }, ), ( severities.ERROR, report_codes.INVALID_OPTION, { "option_name": "unknown", "option_type": "booth ticket", "allowed": list(config_structure.TICKET_KEYS), }, report_codes.FORCE_OPTIONS ), ] assert_raise_library_error( lambda: config_structure.validate_ticket_options( report_processor, { "site": "a", "port": "b", "timeout": " ", "unknown": "c", }, allow_unknown_options=False, ), *expected_errors ) assert_report_item_list_equal( report_processor.report_item_list, expected_errors )
def test_raises_on_invalid_options(self): report_processor = MockLibraryReportProcessor() expected_errors = [ ( severities.ERROR, report_codes.INVALID_OPTIONS, { "option_names": ["site"], "option_type": "booth ticket", "allowed": list(config_structure.TICKET_KEYS), "allowed_patterns": [], }, ), ( severities.ERROR, report_codes.INVALID_OPTIONS, { "option_names": ["port"], "option_type": "booth ticket", "allowed": list(config_structure.TICKET_KEYS), "allowed_patterns": [], }, ), ( severities.ERROR, report_codes.INVALID_OPTION_VALUE, { "option_name": "timeout", "option_value": " ", "allowed_values": "no-empty", "cannot_be_empty": False, "forbidden_characters": None, }, ), (severities.ERROR, report_codes.INVALID_OPTIONS, { "option_names": ["unknown"], "option_type": "booth ticket", "allowed": list(config_structure.TICKET_KEYS), "allowed_patterns": [], }, report_codes.FORCE_OPTIONS), ] assert_raise_library_error( lambda: config_structure.validate_ticket_options( report_processor, { "site": "a", "port": "b", "timeout": " ", "unknown": "c", }, allow_unknown_options=False, ), *expected_errors) assert_report_item_list_equal(report_processor.report_item_list, expected_errors)
def test_unknown_options_are_forceable(self): report_processor = MockLibraryReportProcessor() expected_errors = [ ( severities.ERROR, report_codes.INVALID_OPTIONS, { "option_names": ["site"], "option_type": "booth ticket", "allowed": list(config_structure.TICKET_KEYS), "allowed_patterns": [], }, ), ] assert_raise_library_error( lambda: config_structure.validate_ticket_options( report_processor, { "site": "a", "unknown": "c", }, allow_unknown_options=True, ), *expected_errors ) assert_report_item_list_equal( report_processor.report_item_list, expected_errors + [ ( severities.WARNING, report_codes.INVALID_OPTIONS, { "option_names": ["unknown"], "option_type": "booth ticket", "allowed": list(config_structure.TICKET_KEYS), "allowed_patterns": [], }, ), ] )