Пример #1
0
    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)
Пример #2
0
 def match_date(self, current_date_string, date_expression,
                expected_date_string):
     current_date_time = datetime.strptime(current_date_string,
                                           CommonVariables().date_format)
     self.date_generator.current_day = Day(current_date_time)
     due_date_list = self.date_generator.get_due_dates(date_expression)
     return due_date_list[0].date_string == expected_date_string
Пример #3
0
    def __init__(self, snapshot_list: list):
        assert type(snapshot_list) is list

        self.__row_limit = CommonVariables().max_snapshot_rows
        self.__page_items = snapshot_list
        self.__item_count = len(self.__page_items)
        self.__page_count = 1
        self.__page_list = list()
Пример #4
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'))
Пример #5
0
 def __init__(self, dt):
     assert type(dt) is datetime
     self.dt = dt
     self.day_number = dt.day
     self.month = dt.month
     self.year = dt.year
     self.timestamp = dt.timestamp()
     self.weekday_number = dt.weekday()
     self.week = self.get_week(self.day_number, self.weekday_number,
                               self.month, self.year)
     self.vars = CommonVariables()
Пример #6
0
 def __init__(self, text="default"):
     super().__init__(self.__class__.__name__)
     self.vars = CommonVariables()
     self.__external_id = str()
     self.__text = text
     self.__label = self.vars.default_label
     self.__deleted = False
     self.__priority = 1
     self.__project = self.vars.default_project_name
     self.__date_expression = self.vars.default_date_expression
     self.__due_date = DueDate()
Пример #7
0
 def __init__(self):
     self.weekday_list = range(0, 7)
     self.month_list = range(1, 13)
     self.weekday_abbrev_list = [{"key": 'su', "value": 6},
                                 {"key": 'm', "value": 0},
                                 {"key": 'tu', "value": 1},
                                 {"key": 'w', "value": 2},
                                 {"key": 'th', "value": 3},
                                 {"key": 'f', "value": 4},
                                 {"key": 'sa', "value": 5}]
     self.today = Today()
     self.vars = CommonVariables()
Пример #8
0
 def __init__(self):
     self.vars = CommonVariables()
     self.__current_day = None
     self.handler_1 = DayOfWeekHandler()
     self.handler_2 = NormalLanguageDateHandler()
     self.handler_3 = RecurringDateHandler()
     self.handler_4 = ShortDateHandler()
     self.handler_5 = YearMonthDateHandler()
     self.handler_6 = DateRangeHandler()
     self.handler_7 = EmptyDateHandler()
     self.handler_list = [
         self.handler_1, self.handler_2, self.handler_3, self.handler_4,
         self.handler_5, self.handler_6, self.handler_7
     ]
Пример #9
0
    def setUp(self):
        self.vars = CommonVariables('test_variables.ini')
        mgr = DatabaseManager(self.vars)

        self.tasks = mgr.get_tasks_model()
        self.client = CliClient(mgr, MockFileManager())
        self.client.remove_all_tasks()
        self.date_generator = DateGenerator()

        self.june4 = Day(datetime.strptime("2021-06-04",
                                           self.vars.date_format))
        self.june7 = Day(datetime.strptime("2021-06-07",
                                           self.vars.date_format))
        self.june9 = Day(datetime.strptime("2021-06-09",
                                           self.vars.date_format))
Пример #10
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)
Пример #11
0
    def setUp(self) -> None:
        self.calendar = Calendar()
        self.vars = CommonVariables()
        self.march1 = Day(
            datetime.strptime('2019-03-01', self.vars.date_format))
        self.march31 = Day(
            datetime.strptime('2019-03-31', self.vars.date_format))
        self.may31 = Day(datetime.strptime('2019-05-31',
                                           self.vars.date_format))
        self.dec1 = Day(datetime.strptime("2019-12-01", self.vars.date_format))
        self.dec31 = Day(datetime.strptime("2019-12-31",
                                           self.vars.date_format))

        self.june4 = Day(datetime.strptime("2021-06-04",
                                           self.vars.date_format))
        self.june7 = Day(datetime.strptime("2021-06-07",
                                           self.vars.date_format))
        self.june9 = Day(datetime.strptime("2021-06-09",
                                           self.vars.date_format))
        self.june11 = Day(
            datetime.strptime("2021-06-11", self.vars.date_format))
        self.june29 = Day(
            datetime.strptime("2021-07-02", self.vars.date_format))
Пример #12
0
    def format_row(self, task):
        """
        Prepares the structure of the table, colors the done column based on status, and shortens
        the text when it exceeds the default length.
        :param task:
        :return: list
        """
        assert type(task) is Task
        text = textwrap.shorten(task.text,
                                CommonVariables().default_text_field_length,
                                placeholder="...")

        if task.is_completed():
            completed_text = fg('green') + str(task.due_date.completed)
        else:
            completed_text = fg('blue') + str(task.due_date.completed)

        if task.deleted:
            text = fg('red') + str(text)

        return [
            task.index, completed_text, text, task.project, task.label,
            task.due_date.date_string
        ]
Пример #13
0
 def get_date_count(self, current_date_string, date_expression):
     current_date_time = datetime.strptime(current_date_string,
                                           CommonVariables().date_format)
     self.date_generator.current_day = Day(current_date_time)
     due_date_list = self.date_generator.get_due_dates(date_expression)
     return len(due_date_list)
Пример #14
0
 def __init__(self):
     super().__init__()
     self.vars = CommonVariables()
Пример #15
0
 def setUp(self):
     self.today = Today()
     self.vars = CommonVariables()
     self.date_generator = DateGenerator()
     self.march1 = datetime.strptime('2019-03-01', self.vars.date_format)
Пример #16
0
 def setUp(self) -> None:
     self.vars = CommonVariables('test_variables.ini')
Пример #17
0
 def rfc3339_to_date_string(rfc3339_string) -> str:
     dt = datetime.strptime(rfc3339_string,
                            CommonVariables().rfc3339_date_time_format)
     return Day(dt).to_date_string()
Пример #18
0
 def date_string_to_rfc3339(date_string) -> str:
     variables = CommonVariables()
     if len(date_string) > 0:
         dt = datetime.strptime(date_string, variables.date_format)
         return dt.strftime(variables.rfc3339_date_time_format)
     return date_string
Пример #19
0
 def get_variables_list():
     return dict(CommonVariables()).items()
Пример #20
0
 def get_dir():
     log_dir = CommonVariables().log_dir
     os.makedirs(f"{log_dir}", 0o777, exist_ok=True)
     return log_dir
Пример #21
0
 def get_timestamp():
     return time.strftime(CommonVariables().file_name_timestamp)
Пример #22
0
 def __init__(self):
     self.__output_dir = CommonVariables().resources_dir
Пример #23
0
 def __init__(self, variables=None):
     self.logger = AppLogger("database_manager").get_logger()
     if variables is None:
         self.variables = CommonVariables()
     else:
         self.variables = variables
Пример #24
0
    def setUp(self):
        self.vars = CommonVariables()
        self.db = JsonFileDatabase()
        self.db.initialize(Task())
        self.tasks = Tasks(self.db)
        self.task1 = Task("Task1")
        self.task1.label = "waiting"
        self.task1.date_expression = "may 2"
        self.task1.external_id = 1
        self.tasks.append(self.task1)

        self.task2 = Task("Task2")
        self.task2.label = "computer"
        self.task2.date_expression = "may 3"
        self.tasks.append(self.task2)

        self.task3 = Task("Task3")
        self.task3.label = "office"
        self.task3.date_expression = "may 4"
        self.tasks.append(self.task3)

        self.task4 = Task("Task4")
        self.task4.label = "waiting"
        self.task4.date_expression = "may 5"
        self.tasks.append(self.task4)

        self.task5 = Task("Task5")
        self.task5.label = "office"
        self.task5.date_expression = "may 6"
        self.tasks.append(self.task5)

        self.task6 = Task("Task6")
        self.task6.label = "call"
        self.task6.date_expression = "may 7"
        self.tasks.append(self.task6)

        self.task7 = Task("Task7")
        self.task7.label = "computer"
        self.task7.date_expression = "may 8"
        self.tasks.append(self.task7)

        self.task8 = Task("Task8")
        self.task8.label = "call"
        self.task8.date_expression = "may 9"
        self.tasks.append(self.task8)

        self.task9 = Task("Task9")
        self.task9.label = "office"
        self.task9.date_expression = "may 10"
        self.tasks.append(self.task9)

        self.task10 = Task("Task10")
        self.task10.label = "waiting"
        self.task10.date_expression = "may 11"
        self.tasks.append(self.task10)

        self.future_task = Task("Future Task")
        future_datetime = datetime.now() + timedelta(days=1)
        date_string = future_datetime.strftime(self.vars.date_format)
        self.future_task.due_date = DueDate(date_string)
        self.tasks.append(self.future_task)
Пример #25
0
    def __init__(self, db_manager):
        assert isinstance(db_manager, DatabaseManager)

        self.tasks = db_manager.get_tasks_model()
        self.__date_generator = DateGenerator()
        self.__variables = CommonVariables()
Пример #26
0
 def __init__(self):
     self.next_handler = None
     self.calendar = Calendar()
     self.vars = CommonVariables()
Пример #27
0
 def __init__(self, database):
     super().__init__(database, Task())
     self.__calendar = Calendar()
     self.__vars = CommonVariables()
     self.__date_generator = DateGenerator()
Пример #28
0
 def __init__(self, date_string=""):
     self.__completed = False
     self.__date_string = date_string
     self.vars = CommonVariables()