def test_list_invalid_status_task(): # FIXME: Student's task """ If the `list_tasks` method receives an invalid status, it should raise an `InvalidTaskStatus` Exception """ tasks = [{ 'task': 'Email team updates', 'description': 'Some more details', 'due_on': datetime(2018, 3, 1, 9), 'status': 'pending' }, { 'task': 'Update project plan', 'description': 'Important before investors meeting', 'due_on': datetime(2018, 2, 28, 9), 'status': 'done' }, { 'task': 'Book conference room', 'description': None, 'due_on': datetime(2018, 3, 1, 8, 30), 'status': 'pending' }] with pytest.raises(InvalidTaskStatus): todos.list_tasks(tasks, status='INVALID TYPE')
def list(ctx, status): tasks = todos.list_tasks(ctx.obj['json_data'], status=status) summary = todos.summary(ctx.obj['json_data']) click.echo('{} tasks. {} pending. {} done.'.format(summary['total'], summary['pending'], summary['done'])) print('-' * 60) tpl = "{:>10} | {:^30} | {:>10}" print(tpl.format('| #', 'Task', 'Status |')) print('-' * 60) for task in tasks: idx, name, due_on, status = task print(tpl.format(idx, name, status)) print('-' * 60)
def test_list_completed_tasks(): tasks = [{ 'task': 'Email team updates', 'description': 'Some more details', 'due_on': datetime(2018, 3, 1, 9), 'status': 'pending' }, { 'task': 'Update project plan', 'description': 'Important before investors meeting', 'due_on': datetime(2018, 2, 28, 9), 'status': 'done' }, { 'task': 'Book conference room', 'description': None, 'due_on': datetime(2018, 3, 1, 8, 30), 'status': 'pending' }] task_list = todos.list_tasks(tasks, status='done') assert task_list == [ (2, 'Update project plan', '2018-02-28 09:00:00', 'done'), ]
import todos from pprint import pprint with open('sample_todos.json', 'r') as fp: tasks = todos.unserialize(fp.read()) # List tasks task_list = todos.list_tasks(tasks) pprint(task_list) # Create task """ todos.create_task(tasks, 'Take out the trash') pprint(tasks) """ # Complete task """ new_tasks = todos.complete_task(tasks, 'Review AWS proposal') pprint(new_tasks) """