Пример #1
0
def checking_changing_status(cmd, message, status):
    """
    Before starting tests method create only one task with key 1.
    """

    key = db.incr(f'/tasks/chat_id/{message.chat.id}/last_task_id')

    task = {
        'title': 'TestTitle',
        'description': 'TeskDesc',
        'created': 0,
        'modified': 0,
        'status': Status.DO if status is Status.TODO else Status.TODO,
        'assignee': '',
        'assignee_id': '',
    }

    db.hset(f'/tasks/chat_id/{message.chat.id}', key,
            json.dumps(task).encode())

    if status is Status.DO:
        do(message)
    elif status is Status.TODO:
        todo(message)
    elif status is Status.DONE:
        done(message)
    else:
        assert status in Status.ALL

    assert handlers.bot.reply_to.called
    task = decode(db.hget(f'/tasks/chat_id/{message.chat.id}', key))
    assert task['status'] == status
Пример #2
0
def new(message):
    msg = message.text.replace('/new', '', 1)
    args = msg.split('\n', 1)
    if len(args) == 2:
        title, description = msg.split('\n', 1)
    else:
        title, description = msg, ''

    if len(title) > 256:
        return bot.reply_to(message, f'Title should be less than 256 chars')
    if len(description) > 2048:
        return bot.reply_to(message,
                            f'Description should be less than 2048 chars')

    timestamp = time.time()

    task_id = db.incr(f'/tasks/chat_id/{message.chat.id}/last_task_id')

    task = {
        'title': title.strip().capitalize(),
        'description': description,
        'created': timestamp,
        'modified': timestamp,
        'status': Status.TODO,
        'assignee': '',  # task will be assigned, when someone take it
        'assignee_id': '',
    }

    db.hset(f'/tasks/chat_id/{message.chat.id}', task_id, encode(task))

    return bot.reply_to(message, f'Created new task with id /{task_id}')
Пример #3
0
def update(message):
    msg = message.text.replace('/update', '', 1)
    args = msg.split('\n', 2)

    if len(args) == 3:
        task_id, title, description = msg.split('\n', 2)
    else:
        task_id, title, description = args[0], args[1], ''

    timestamp = time.time()
    task_id = int(task_id)

    task = db.hget(f'/tasks/chat_id/{message.chat.id}', task_id)

    task = decode(task)
    task['title'] = title
    task['description'] = description
    task['modified'] = timestamp

    db.hset(f'/tasks/chat_id/{message.chat.id}', task_id, encode(task))
    return bot.reply_to(message, f'Modified task with id /{task_id}')
Пример #4
0
def change_status_task(chat_id, user_id, username, task_id, status):

    assert status in Status.ALL

    task = db.hget(f'/tasks/chat_id/{chat_id}', task_id)
    if task is None:
        return None

    task = decode(task)
    task['status'] = status
    task['modified'] = time.time()

    if status == Status.TODO:
        task['assignee_id'] = ''
        task['assignee'] = ''
    else:
        task['assignee_id'] = user_id
        task['assignee'] = username

    db.hset(f'/tasks/chat_id/{chat_id}', task_id, encode(task))
    return task