def test_success(self):
     assert_report_item_list_equal(
         config_validators.add_ticket(
             self.conf, "ticketB", {"timeout": "10"}
         ),
         []
     )
Exemple #2
0
def config_ticket_add(env,
                      ticket_name,
                      options,
                      instance_name=None,
                      allow_unknown_options=False):
    """
    add a ticket to booth configuration

    LibraryEnvironment env
    string ticket_name -- the name of the ticket to be created
    dict options -- options for the ticket
    string instance_name -- booth instance name
    bool allow_unknown_options -- allow using options unknown to pcs
    """
    report_processor = SimpleReportProcessor(env.report_processor)
    booth_env = env.get_booth_env(instance_name)
    try:
        booth_conf = booth_env.config.read_to_facade()
        report_processor.report_list(
            config_validators.add_ticket(
                booth_conf,
                ticket_name,
                options,
                allow_unknown_options=allow_unknown_options))
        if report_processor.has_errors:
            raise LibraryError()
        booth_conf.add_ticket(ticket_name, options)
        booth_env.config.write_facade(booth_conf, can_overwrite=True)
    except RawFileError as e:
        report_processor.report(raw_file_error_report(e))
    except ParserErrorException as e:
        report_processor.report_list(
            booth_env.config.parser_exception_to_report_list(e))
    if report_processor.has_errors:
        raise LibraryError()
 def test_duplicate_ticket_name(self):
     assert_report_item_list_equal(
         config_validators.add_ticket(self.conf, "ticketA", {}),
         [
             fixture.error(
                 report_codes.BOOTH_TICKET_DUPLICATE,
                 ticket_name="ticketA",
             ),
         ]
     )
 def test_bad_ticket_name(self):
     assert_report_item_list_equal(
         config_validators.add_ticket(self.conf, "@ticketB", {}),
         [
             fixture.error(
                 report_codes.BOOTH_TICKET_NAME_INVALID,
                 ticket_name="@ticketB",
             ),
         ]
     )
 def test_success(self):
     for ticket in (
             "abcdefghij01234567890123456789012345678901234567890123456789012",
             "ticketB",
             "ticket-C",
     ):
         with self.subTest(ticket=ticket):
             assert_report_item_list_equal(
                 config_validators.add_ticket(self.conf, ticket,
                                              {"timeout": "10"}),
                 [],
             )
 def test_options(self):
     assert_report_item_list_equal(
         config_validators.add_ticket(
             self.conf,
             "ticketB",
             {
                 "site": "a",
                 "port": "b",
                 "timeout": " ",
                 "unknown": " ",
                 "mode": "special",
             },
         ),
         [
             fixture.error(
                 report_codes.INVALID_OPTIONS,
                 force_code=report_codes.FORCE,
                 option_names=["unknown"],
                 **self.invalid_option_report_args,
             ),
             fixture.error(
                 report_codes.INVALID_OPTIONS,
                 option_names=["port", "site"],
                 **self.invalid_option_report_args,
             ),
             fixture.error(
                 report_codes.INVALID_OPTION_VALUE,
                 option_value=" ",
                 option_name="timeout",
                 allowed_values=None,
                 cannot_be_empty=True,
                 forbidden_characters=None,
             ),
             fixture.error(
                 report_codes.INVALID_OPTION_VALUE,
                 option_value=" ",
                 option_name="unknown",
                 allowed_values=None,
                 cannot_be_empty=True,
                 forbidden_characters=None,
             ),
             fixture.error(
                 report_codes.INVALID_OPTION_VALUE,
                 force_code=report_codes.FORCE,
                 option_value="special",
                 option_name="mode",
                 allowed_values=["auto", "manual"],
                 cannot_be_empty=False,
                 forbidden_characters=None,
             ),
         ],
     )
 def test_bad_ticket_name(self):
     for ticket in (
             # too long
             "abcdefghij012345678901234567890123456789012345678901234567890123",
             # disallowed characters
             "my_ticket",
             "@ticketB",
     ):
         with self.subTest(ticket=ticket):
             assert_report_item_list_equal(
                 config_validators.add_ticket(self.conf, ticket, {}),
                 [
                     fixture.error(
                         report_codes.BOOTH_TICKET_NAME_INVALID,
                         ticket_name=ticket,
                     ),
                 ],
             )
 def test_unknown_options_forced(self):
     assert_report_item_list_equal(
         config_validators.add_ticket(
             self.conf,
             "ticketB",
             {
                 "site": "a",
                 "unknown": "c",
             },
             allow_unknown_options=True
         ),
         [
             fixture.warn(
                 report_codes.INVALID_OPTIONS,
                 option_names=["unknown"],
                 **self.invalid_option_report_args
             ),
             fixture.error(
                 report_codes.INVALID_OPTIONS,
                 option_names=["site"],
                 **self.invalid_option_report_args
             ),
         ]
     )
 def test_success_no_options(self):
     assert_report_item_list_equal(
         config_validators.add_ticket(self.conf, "ticketB", {}),
         []
     )