Esempio n. 1
0
 def test_bad_id(self):
     """
     A non-int id should raises an exceptions.
     """
     with pytest.raises(TypeError):
         tasks.update(task_id={"dict insted": 1},
                      task=tasks.Task())
Esempio n. 2
0
def test_after_update_db_count_not_change():
    """ Check, that after update count doesn't change """
    tasks.start_tasks_db(str("."), 'tiny')
    before_update_count = tasks.count()
    tasks.update(pytest.task_id, Task(done=True))
    after_update_count = tasks.count()
    assert before_update_count == after_update_count
    tasks.stop_tasks_db()
Esempio n. 3
0
def create_qa_update_task(resource, queue):
    from pylons import config
    import tasks
    if p.toolkit.check_ckan_version(max_version='2.2.99'):
        package = resource.resource_group.package
    else:
        package = resource.package
    task_id = '%s/%s/%s' % (package.name, resource.id[:4], make_uuid()[:4])
    ckan_ini_filepath = os.path.abspath(config.__file__)
    tasks.update(ckan_ini_filepath, resource.id)
Esempio n. 4
0
def update_db():
    update_config = config.UPDATE_DB
    while True:
        time_now = datetime.now()
        hour = time_now.hour
        minute = time_now.minute
        second = time_now.second
        if update_config[0] == hour and update_config[
                1] == minute and update_config[2] == second:
            print(update_config)
            update()
Esempio n. 5
0
def tasks_api():

    if request.method == "GET":
        return tasks.get()
    elif request.method == "POST":
        return tasks.post()
    elif request.method == "PATCH":
        return tasks.update()
    elif request.method == "DELETE":
        return tasks.delete()
Esempio n. 6
0
def set(response, request, params):
    if len(params) >= 5:
        item = params[3]
        action = params[4]
        response.data = {"success": False}
        if item == "board":
            if action == "new":
                response.data = boards.create(request.POST)
            elif action == "update":
                response.data = boards.update(request.POST)
            elif action == "delete":
                response.data = boards.remove(request.POST)
        elif item == "category":
            if action == "new":
                response.data = categories.create(request.POST)
            elif action == "update":
                response.data = categories.update(request.POST)
            elif action == "delete":
                response.data = categories.remove(request.POST)
            elif action == "order":
                response.data = categories.setOrder(request.POST)
        elif item == "task":
            if action == "new":
                response.data = tasks.create(request.POST)
            elif action == "update":
                response.data = tasks.update(request.POST)
            elif action == "delete":
                response.data = tasks.remove(request.POST)
            elif action == "order":
                response.data = tasks.setOrder(request.POST)
        elif item == "user":
            if action == "new":
                response.data = users.create(request.POST)
            elif action == "update":
                response.setOk()
                response.msg = "set update user"
            elif action == "delete":
                response.setOk()
                response.msg = "set delete user"
        response.setOk() if response.data["success"] is True else response.setInvalid()
    else:
        response.setMoreInfo()
    return response
Esempio n. 7
0
 def test_tasks_update(self):
     test1_update_list = [{
         'name': 'First task',
         'time_spent': '0:25',
         'notes': '',
         'completed': False
     }, {
         'name': 'Second task',
         'time_spent': '0:25',
         'notes': '',
         'completed': True
     }, {
         'name': 'Third task',
         'time_spent': '0:25',
         'notes': '',
         'completed': False
     }]
     test1_expected = [{
         'name': 'Number 1',
         'time_spent': '1:00',
         'notes': '',
         'completed': False
     }, {
         'name': 'Second task',
         'time_spent': '0:25',
         'notes': '',
         'completed': True
     }, {
         'name': 'Third task',
         'time_spent': '0:25',
         'notes': '',
         'completed': False
     }]
     test1_updated_task = {
         **test1_update_list[0], 'name': 'Number 1',
         'time_spent': '1:00'
     }
     test1_actual = tasks.update(test1_update_list, test1_updated_task, 0)
     self.assertEqual(test1_expected, test1_actual)
Esempio n. 8
0
 def test_bad_task(self):
     with pytest.raises(TypeError):
         tasks.update(task_id=1, task='not a task')
Esempio n. 9
0
 def test_bad_id(self):
     with pytest.raises(TypeError):
         tasks.update(task_id={'dict instead': 1}, task=tasks.Task())
 def test_bad_task(self):
     """A non-Task task should raise an excption."""
     with pytest.raises(TypeError):
         tasks.update(task_id=1, task='not a task')
 def test_bad_id(self):
     """A non-int id should raise an excption."""
     with pytest.raises(TypeError):
         tasks.update(task_id={'dict instead': 1}, task=tasks.Task())
Esempio n. 12
0
import os

import users
import tasks
import log
from action import Action

if len(sys.argv) != 3:
    print('error: expected 2 argument')
    print('usage: updatetask <path-to-task> <action>')
    sys.exit()

sys.argv[0] = 'updatetask'
taskPath = sys.argv[1]
action = sys.argv[2]

if not os.path.exists(taskPath):
    print('error: ' + taskPath + ' does not exist')
    sys.exit()

try:
    action = Action[action]
except:
    print('error: action ' + action + ' does not exist')
    sys.exit()

print("updating task: %s by %s" % (action.name, users.current))
tasks.update(taskPath, users.current, action)
log.add(' '.join(sys.argv))
print('task updated.')
Esempio n. 13
0
 def test_bad_task(self):
     """non-Task задача должна поднять exception."""
     with pytest.raises(TypeError):
         tasks.update(task_id=1, task='not a task')
Esempio n. 14
0
 def test_bad_id(self):
     """non-int id должен поднять exception."""
     with pytest.raises(TypeError):
         tasks.update(task_id={'dict instead': 1}, task=tasks.Task())
Esempio n. 15
0
 def update(self):
     tasks.update()
Esempio n. 16
0
 def test_bad_task(self):
     """A non-task task should raise an exception"""
     with pytest.raises(TypeError):
         tasks.update(task_id=1, task="not a task")
 def test_bad_id(self):
     with pytest.raises(TypeError):
         tasks.update(task_id={"dict instead": 1})
Esempio n. 18
0
def main_menu(task_lists: dict[str, list], current_list: str,
              arguments: Namespace):
    verbose = False
    active_tasks = task_lists.get(current_list)
    while True:
        task_lists[current_list] = active_tasks
        data = format_all_tasks_to_plaintext(task_lists, current_list)
        save_data(data, os.getenv('TOD_FP'))

        print_all_tasks(current_list, active_tasks, verbose)
        raw_command = input('► ')

        cls()
        parsed_command = re.match(r'([A-Za-z]*)(\d+)?:?(\d+)?',
                                  raw_command).groups()
        command, selected_number, dest_number = parsed_command
        if selected_number:
            selected_number = int(selected_number)
        if dest_number:
            dest_number = int(dest_number)
        number_of_tasks = len(active_tasks)
        if selected_number is not None \
                and selected_number >= number_of_tasks \
                and command != 'a':
            print(C.RED + "No such task.\n" + C.NORMAL)
            continue

        cls()

        if raw_command == '':
            show_help()
        elif not command and selected_number is not None:
            task = active_tasks[selected_number]
            time_spent_in_seconds = spend_time_on_task(task.get('name'),
                                                       task.get('notes'),
                                                       arguments.pomodoro)
            prev_time_spent_in_seconds = convert_time_spent_to_seconds(
                task.get('time_spent'))
            total_time_spent = prev_time_spent_in_seconds + time_spent_in_seconds
            formatted_time_spent = format_seconds_to_time_spent(
                total_time_spent)
            updated_task = {**task, 'time_spent': formatted_time_spent}
            tasks.update(active_tasks, updated_task, selected_number)
            print(C.PURPLE + 'Elapsed time added.' + C.NORMAL)
        elif command == 'aa':
            cls()
            while True:
                task_name, task_notes = task_name_input()
                if not task_name:
                    break
                new_task = {
                    'name': task_name,
                    'time_spent': '0:00',
                    'notes': task_notes,
                    'completed': False
                }
                active_tasks = tasks.add(active_tasks, new_task,
                                         selected_number)
            cls()
            print(C.PURPLE + 'Tasks added.' + C.NORMAL)
        elif command == 'al':
            cls()
            new_list_name = list_name_input()
            cls()
            if not new_list_name:
                print(C.RED + 'No name entered.' + C.NORMAL)
                continue
            task_lists[new_list_name] = list()
            current_list = new_list_name
            active_tasks = task_lists[current_list]
            print(C.PURPLE + 'List created.' + C.NORMAL)
        elif command == 'a':
            task_name, task_notes = task_name_input()
            cls()
            if not task_name:
                print(C.RED + 'Cannot add empty task.' + C.NORMAL)
                continue
            new_task = {
                'name': task_name,
                'time_spent': '0:00',
                'notes': task_notes,
                'completed': False
            }
            active_tasks = tasks.add(active_tasks, new_task, selected_number)
            print(C.PURPLE + 'Task added.' + C.NORMAL)
        elif command == 'b':
            if selected_number is None:
                selected_number = task_number_input(number_of_tasks)
            timestamp_before = int(time.time())
            current_number = selected_number
            current_task = active_tasks[selected_number]
            print(C.YELLOW + current_task.get('name') + C.NORMAL + '\n')
            if current_task.get('notes'):
                print(C.GRAY + current_task.get('notes') + C.NORMAL + '\n')
            print('Enter your new broken down tasks:\n')
            while True:
                current_number += 1
                task_name, task_notes = task_name_input()
                if not task_name:
                    break
                new_task = {
                    'name': task_name,
                    'time_spent': '0:00',
                    'notes': task_notes,
                    'completed': False
                }
                active_tasks = tasks.add(active_tasks, new_task,
                                         current_number)
            timestamp_after = int(time.time())
            time_spent_in_seconds = timestamp_after - timestamp_before
            prev_time_spent_in_seconds = convert_time_spent_to_seconds(
                current_task.get('time_spent'))
            total_time_spent = prev_time_spent_in_seconds + time_spent_in_seconds
            formatted_time_spent = format_seconds_to_time_spent(
                total_time_spent)
            updated_task = {**current_task, 'time_spent': formatted_time_spent}
            tasks.update(active_tasks, updated_task, selected_number)
            cls()
            print(C.PURPLE + 'Tasks added.' + C.NORMAL)
        elif command == 'c':
            if selected_number is None:
                selected_number = task_number_input(number_of_tasks)
            cls()
            if selected_number is not None:
                active_tasks = tasks.set_completion(active_tasks,
                                                    selected_number)
                print(C.PURPLE + 'Task updated.' + C.NORMAL)
        elif command == 'dd':
            active_tasks = []
            print(C.PURPLE + 'Tasks deleted.' + C.NORMAL)
        elif command == 'dl':
            list_names = list(task_lists.keys())
            print_all_lists(list_names)
            selected_number = list_number_input(len(list_names))
            cls()
            selected_list = list_names[selected_number]
            del task_lists[selected_list]
            if selected_list == current_list:
                current_list = list_names[0]
            print(C.PURPLE + 'List deleted.' + C.NORMAL)
        elif command == 'd':
            if selected_number is None:
                selected_number = task_number_input(number_of_tasks)
            cls()
            active_tasks = tasks.delete(active_tasks, selected_number)
            print(C.PURPLE + 'Task deleted.' + C.NORMAL)
        elif command == 'e':
            if number_of_tasks == 0:
                print(C.PURPLE + 'No tasks to edit.' + C.NORMAL)
                continue
            if selected_number is None:
                print_all_tasks(current_list, active_tasks)
                selected_number = task_number_input(number_of_tasks)
                cls()
            task = active_tasks[selected_number]
            print('\n' + C.BLUE + "Original Task:" + C.NORMAL)
            name = task['name']
            notes = ': ' + task.get('notes') if task.get('notes') else ''
            time_spent = task['time_spent']
            print(f"\n{name}{notes}\n({time_spent})\n")
            updated_task_name, updated_task_notes = task_name_input(
                name, task['notes'])
            updated_time_spent = task_time_input(time_spent)
            cls()
            updated_task = {
                **task, 'name': updated_task_name,
                'notes': updated_task_notes,
                'time_spent': updated_time_spent
            }
            active_tasks = tasks.update(active_tasks, updated_task,
                                        selected_number)
            print(C.PURPLE + 'Task updated.' + C.NORMAL)
        elif command == 'h':
            show_help()
        elif command == 'l':
            print_all_lists(task_lists)
            list_names = task_lists.keys()
            selected_number = list_number_input(len(list_names))
            cls()
            current_list = list(list_names)[selected_number]
            active_tasks = task_lists.get(current_list)
            print(C.PURPLE + 'List selected.' + C.NORMAL)
        elif command == 'ml':
            if number_of_tasks == 0:
                print(C.PURPLE + 'No tasks to move.' + C.NORMAL)
                continue
            print_all_tasks(current_list, active_tasks)
            if selected_number is None:
                selected_number = task_number_input(number_of_tasks)
            cls()
            list_names = list(task_lists.keys())
            print_all_lists(list_names)
            destination_list_number = int(
                input(f'Move task {selected_number} to which list? '))
            destination_list = task_lists[list_names[destination_list_number]]
            cls()
            active_tasks, destination_list = tasks.move_to_list(
                active_tasks, destination_list, selected_number)
            task_lists[list_names[destination_list_number]] = destination_list
            print(C.PURPLE + 'Task moved.' + C.NORMAL)
        elif command == 'm':
            if number_of_tasks == 0:
                print(C.PURPLE + 'No tasks to move.' + C.NORMAL)
                continue
            print_all_tasks(current_list, active_tasks)
            if selected_number is None:
                selected_number = task_number_input(number_of_tasks)
            if dest_number is None:
                dest_number = input(f'Move task {selected_number} to where? ')
            if not type(dest_number) == int:
                cls()
                print(C.RED + 'Invalid number.' + C.NORMAL)
                continue
            cls()
            dest_number = int(dest_number)
            active_tasks = tasks.move(active_tasks, selected_number,
                                      dest_number)
            print(C.PURPLE + 'Tasks updated.' + C.NORMAL)
        elif command == 'n':
            verbose = True if not verbose else False
            message = 'Notes are now fully visible.' if verbose else 'Notes are now truncated.'
            print(C.PURPLE + message + C.NORMAL)
        elif command == 'q':
            sys.exit()
        elif command == 'r':
            active_tasks = tasks.reduce(active_tasks)
            print(C.PURPLE + 'Tasks reduced.' + C.NORMAL)
        elif command == 's':
            print('Starting new task list...\n')
            active_tasks = start_new_task_list()
            cls()
        elif command == 't':
            spend_time_on_task('Timer', None)
            cls()
        else:
            print(C.WHITE + "Try 'help' for more information." + C.NORMAL)