def test_unique_id_2(): """unique_id() should return an unused id.""" ids = [] ids.append(tasks.add(Task('one'))) ids.append(tasks.add(Task('two'))) ids.append(tasks.add(Task('three'))) # grab a unique id uid = tasks.unique_id() # make sure it isn't in the list of existing ids assert uid not in ids
def test_asdict(): """_asdict() should return a dictionary.""" t_task = Task('do something', 'okken', True, 21) t_dict = t_task._asdict() expected = { 'summary': 'do something', 'owner': 'okken', 'done': True, 'id': 21 } assert t_dict == expected
def tasks_mult_per_owner(): """Several owners with several tasks each.""" return (Task('Make a cookie', 'Raphael'), Task('Use an emoji', 'Raphael'), Task('Move to Berlin', 'Raphael'), Task('Create', 'Michelle'), Task('Inspire', 'Michelle'), Task('Encourage', 'Michelle'), Task('Do a handstand', 'Daniel'), Task('Write some books', 'Daniel'), Task('Eat ice cream', 'Daniel'))
def create_new_task(self): title = raw_input("Enter task title: ") status = "to-do" task_id = len(todo_list)+1 valid = Validation.validate_task(title) if valid: print(valid) else: new_task = Task(task_id, title, status) if(new_task.create_task()): print("successfully added task") print(" ") self.show_tasks() else: print("Failed to add task")
def test_list_print_many_items(no_db, mocker): many_tasks = ( Task('write chapter', 'Brian', True, 1), Task('edit chapter', 'Katie', False, 2), Task('modify chapter', 'Brian', False, 3), Task('finalize chapter', 'Katie', False, 4), ) mocker.patch.object(tasks, 'list_tasks', return_value=many_tasks) runner = CliRunner() result = runner.invoke(cli.tasks_cli, ['list']) expected_output = (" ID owner done summary\n" " -- ----- ---- -------\n" " 1 Brian True write chapter\n" " 2 Katie False edit chapter\n" " 3 Brian False modify chapter\n" " 4 Katie False finalize chapter\n") assert result.output == expected_output
def test_add_returns_valid_id(tasks_db): """tasks.add(<valid task>) should return an integer.""" # GIVEN an initialized tasks db # WHEN a new task is added # THEN returned task_id is of type int new_task = Task('do something') task_id = tasks.add(new_task) assert isinstance(task_id, int)
def test_add_increases_count(db_with_3_tasks): """Test tasks.add() affect on tasks.count().""" # GIVEN a db with 3 tasks # WHEN another task is added tasks.add(Task('throw a party')) # THEN the count increases by 1 assert tasks.count() == 4
def delete_a_task(self): task_id = raw_input("Enter Task Id: ") valid = Validation.validate_id_type(task_id) if valid: print(valid) else: if (Task.delete_task(task_id)): print("successfully deleted Task") else: print("Task Not Deleted or doest exist")
def finish_a_task(self): task_id = raw_input("Enter Task Id: ") valid = Validation.validate_id_type(task_id) if valid: print(valid) else: if (Task.mark_as_finished(task_id)): print("successfully finished Task") self.show_tasks() else: print("Task Not Updated or doest exist")
def test_added_task_has_id_set(tasks_db): """Make sure the task_id field is set by tasks.add().""" # GIVEN an initialized tasks db # AND a new task is added new_task = Task('sit in chair', owner='me', done=True) task_id = tasks.add(new_task) # WHEN task is retrieved task_from_db = tasks.get(task_id) # THEN task_id matches id field assert task_from_db.id == task_id # AND contents are equivalent (except for id) # the [:-1] syntax returns a list with all but the last element assert task_from_db[:-1] == new_task[:-1]
def test_adding_task(self): task = Task(self.task_id, self.title, self.status) new_task = task.create_task() self.assertEquals(new_task, True)
def delete_all_tasks(self): if (Task.delete_all_tasks()): print("successfully deleted all Tasks") else: print("No Task Deleted")
def test_defaults(): """Using no parameters should invoke defaults.""" t1 = Task() t2 = Task(None, None, False, None) assert t1 == t2
def test_member_access(): """Check .field functionality of namedtuple.""" t = Task('buy milk', 'brian') assert t.summary == 'buy milk' assert t.owner == 'brian' assert (t.done, t.id) == (False, None)
def tasks_just_a_few(): """All summaries and owners are unique.""" return (Task('Write some code', 'Brian', True), Task("Code review Brian's code", 'Katie', False), Task('Fix what Brian did', 'Michelle', False))
import pytest from src import tasks from src.tasks import Task tasks_to_try = (Task('sleep', done=True), Task('wake', 'brian'), Task('breathe', 'BRIAN', True), Task('exercise', 'BrIaN', False)) task_ids = [ 'Task({},{},{})'.format(t.summary, t.owner, t.done) for t in tasks_to_try ] def equivalent(t1, t2): """Check two tasks for equivalence.""" return ((t1.summary == t2.summary) and (t1.owner == t2.owner) and (t1.done == t2.done)) @pytest.fixture(params=tasks_to_try) def a_task(request): """Using no ids.""" return request.param def test_add_a(tasks_db, a_task): """Using a_task fixture (no ids).""" task_id = tasks.add(a_task) t_from_db = tasks.get(task_id) assert equivalent(t_from_db, a_task)
def test_finishing_task(self): task = Task(self.task_id, self.title, self.status) new_task = task.create_task() finish_task = Task.mark_as_finished(self.task_id) self.assertEquals(finish_task, True)
def test_deleting_all_task(self): task = Task(self.task_id, self.title, self.status) new_task = task.create_task() delete_all_tasks = Task.delete_all_tasks() self.assertEquals(delete_all_tasks, True)
def test_replace(): """replace() should change passed in fields.""" t_before = Task('finish book', 'brian', False) t_after = t_before._replace(id=10, done=True) t_expected = Task('finish book', 'brian', True, 10) assert t_after == t_expected
def test_task_equality(): t1 = Task('sit there', 'brain') t2 = Task('do something', 'okken') assert t1 == t2
def test_dict_equality(): """Different tasks compared as dicts should not be equal.""" t1_dict = Task('make sandwich', 'okken')._asdict() t2_dict = Task('make sandwich', 'okken')._asdict() assert t1_dict == t2_dict