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
def get_task(chat_id, user_id, username, task_id): task = db.hget(f'/tasks/chat_id/{chat_id}', task_id) if task is None: return 'No task with such id', None task = decode(task) response = f'''Task id: {task_id} Title: {task["title"]} Status: {task["status"]} Created: {readable_time(task["created"])} Modified: {readable_time(task["modified"])} Assignee: {task["assignee"]} Assignee id: {task["assignee_id"]} Description: {task["description"]}''' keyboard = types.InlineKeyboardMarkup(row_width=3) btns = [] for status in Status.ALL: btns.append( types.InlineKeyboardButton( text=status, # cmd, status, user_id, username, task_id=data callback_data=f"set_status_task:{status}:{user_id}:" f"{username}:{task_id}")) keyboard.add(*btns) return response, keyboard
def test_new(cmd, message): new(message) assert handlers.bot.reply_to.called key = db.get(f'/tasks/chat_id/{message.chat.id}/last_task_id') assert int(key) == 1 task = decode(db.hget(f'/tasks/chat_id/{message.chat.id}', key)) assert task['status'] == Status.TODO assert task['title'] == cmd[1].capitalize()
def get_task(chat_id, user_id, username, task_id): task = db.hget(f'/tasks/chat_id/{chat_id}', task_id) if task is None: return 'No task with such id', None task = decode(task) response = f'''Task id: {task_id} Title: {task["title"]} Status: {task["status"]} Created: {readable_time(task["created"])} Modified: {readable_time(task["modified"])} Assignee: {task["assignee"]} Assignee id: {task["assignee_id"]} Description: {task["description"]}''' return response, get_keyboard_change_status(user_id, username, task_id)
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}')
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