Ejemplo n.º 1
0
    def test_save_task(self):
        key_first = self.manager.get_free_key_task()
        key_second = self.manager.get_free_key_task()
        task = Task(None, 'task', 'andrew', key_first, 3, 'waiting',
                    '2018-08-09 10:20', '', '')
        task.key = key_first
        second_task = Task(None, 'task2', 'andrew', key_second, 3, 'waiting',
                           '2018-08-09 10:20', '', '')
        second_task.key = key_second
        self.manager.save_task(task)
        self.manager.save_task(second_task)

        new_task = self.manager.get_task(key_first)
        self.assertEqual(new_task.host, 'andrew')
        self.assertEqual(new_task.key, key_first)
        self.manager.save_task(new_task)
Ejemplo n.º 2
0
    def check_time(cls, task):
        """Checks the time of the task relative to the current time and translates it if necessary

        :param
        'task': object type of Task
        """
        if not task:
            return
        cur_time = datetime.now().strftime("%H:%M %d/%m/%Y")
        if task.period:
            # if this task has end time and period and end time has passed, we  will move time this step period
            # while end time less then current time
            while datetime.strptime(cur_time,
                                    "%H:%M %d/%m/%Y") > datetime.strptime(
                                        task.time_last_copy, "%H:%M %d/%m/%Y"):
                task.time_last_copy = cls.date_translation(
                    task.time_last_copy, task.period)
                new_task = Task()
                new_task.name = task.name
                new_task.parent = task.parent
                new_task.host = task.host
                new_task.key = cls.get_free_key_task()
                new_task.type_task = task.type_task
                new_task.admins = task.admins.copy()
                new_task.members = task.members.copy()
                new_task.priority = task.priority
                new_task.status = task.status
                new_task.start_time = task.start_time
                new_task.end_time = task.end_time
                new_task.period = ''
                cls.save_task(new_task)