def test_add_item2(self): quarter = TodoQuarter() date = datetime(2017, 7, 4) quarter.add_item('implement Quarter Class', date) self.assertEqual(quarter.todo_items[0].deadline, date) self.assertEqual(quarter.todo_items[0].title, 'implement Quarter Class')
def test_remove_item(self): quarter = TodoQuarter() date = datetime(2017, 7, 4) date2 = datetime(2017, 6, 14) date3 = datetime(2017, 9, 24) quarter.add_item('go to Codecool', date) quarter.add_item('make a coffee', date2) quarter.add_item('code', date3) quarter.remove_item(1) self.assertEqual(len(quarter.todo_items), 2, 'Incorrect lenght of todo_items list') self.assertEqual(quarter.todo_items[1].title, 'code', 'Incorrect item')
def test_str(self): quarter = TodoQuarter() date = datetime(2017, 6, 16) date2 = datetime(2017, 6, 14) date3 = datetime(2017, 7, 24) quarter.add_item('go to Codecool', date) quarter.add_item('make a coffee', date2) quarter.add_item('code', date3) quarter.todo_items[1].mark() quarter_string = quarter.__str__() self.assertIsInstance(quarter_string, str, msg='it\'s not a string!') self.assertEqual(quarter_string[0:6], '1. [ ]') self.assertEqual(quarter_string[26:32], '2. [x]')
def test_archive_items(self): quarter = TodoQuarter() date = datetime(2017, 6, 16) date2 = datetime(2017, 6, 14) date3 = datetime(2017, 7, 24) quarter.add_item('go to Codecool', date) quarter.add_item('make a coffee', date2) quarter.add_item('code', date3) quarter.todo_items[0].mark() quarter.archive_items() self.assertEqual(len(quarter.todo_items), 2, 'Incorrect lenght of todo_items list') self.assertEqual(quarter.todo_items[0].title, 'go to Codecool', 'Incorrect item')
def test_sort_items(self): quarter = TodoQuarter() date1 = datetime(2017, 6, 14) date2 = datetime(2017, 5, 24) date3 = datetime(2017, 6, 4) date4 = datetime(2017, 7, 3) date5 = datetime(2017, 6, 23) quarter.add_item('go to Codecool', date1) quarter.add_item('make a coffee', date2) quarter.add_item('start coding', date3) quarter.add_item('more coffee', date4) quarter.add_item('more coding', date5) self.assertEqual(quarter.todo_items[0].deadline, date2) self.assertEqual(quarter.todo_items[1].deadline, date3) self.assertEqual(quarter.todo_items[2].deadline, date1) self.assertEqual(quarter.todo_items[3].deadline, date5) self.assertEqual(quarter.todo_items[4].deadline, date4)
def test_add_item_error(self): quarter = TodoQuarter() with self.assertRaises(ValueError, msg='Incorrect deadline'): quarter.add_item('implement Quarter Class', 'error date')
def test_get_item(self): date = datetime(2017, 7, 4) quarter = TodoQuarter() quarter.add_item('implement Quarter Class', date) item = quarter.get_item(0) self.assertIsInstance(item, TodoItem)