Ejemplo n.º 1
0
class TestVariables(unittest.TestCase):

    def setUp(self) -> None:
        self.vars = CommonVariables('test_variables.ini')

    def test_dir_variables(self):
        self.assertIsInstance(self.vars.log_dir, str)
        self.assertIsInstance(self.vars.credentials_dir, str)
        self.assertIsInstance(self.vars.resources_dir, str)

    def test_date_time_variables(self):
        self.assertIsInstance(self.vars.date_format, str)
        self.assertIsInstance(self.vars.date_time_format, str)
        self.assertIsInstance(self.vars.time_format, str)
        self.assertIsInstance(self.vars.rfc3339_date_time_format, str)
        self.assertIsInstance(self.vars.file_name_timestamp, str)

    def test_task_variables(self):
        self.assertIsInstance(self.vars.default_label, str)
        self.assertIsInstance(self.vars.default_project_name, str)
        self.assertIsInstance(self.vars.default_text, str)
        self.assertIsInstance(self.vars.recurring_month_limit, int)
        self.assertIsInstance(self.vars.default_date_expression, str)
        self.assertIsInstance(self.vars.default_text_field_length, int)

    def test_redisdb_variables(self):
        self.assertIsInstance(self.vars.redis_port, int)
        self.assertIsInstance(self.vars.enable_redis, bool)
        self.assertIsInstance(self.vars.redis_host, str)

    def test_set_variable(self):
        self.vars.default_project_name = "work"
        self.assertTrue(self.vars.default_project_name == "work")

        vars = CommonVariables('test_variables.ini')
        self.assertTrue(vars.default_project_name == "work")

        vars.reset()
        self.assertTrue(len(str(vars.default_project_name)) == 0)

    def test_date_format_validation(self):
        self.assertTrue(self.vars.validate_date_format('2020-01-01'))
        self.assertFalse(self.vars.validate_date_format('2020-01-011'))
        self.assertFalse(self.vars.validate_date_format('20201-01-01'))
        self.assertFalse(self.vars.validate_date_format('01-01-2020'))
Ejemplo n.º 2
0
class YearMonthDateHandler(Handler):
    def __init__(self):
        super().__init__()
        self.vars = CommonVariables()

    def validate(self, expression):
        return self.vars.validate_date_format(expression)

    def parse_expression(self, parser):
        parser.handler_name = YearMonthDateHandler.__name__
        parser.day_list = [self.calendar.parse_date(parser.expression)]

    def handle(self, parser):
        if self.validate(parser.expression):
            self.parse_expression(parser)
        else:
            super(YearMonthDateHandler, self).handle(parser)