def test_edit_task_make_high_prio(self, loader_mock, saver_mock, mock_out): test_task = { "id": 1, "title": "design blog section", "date": "2018-09-02", "week": "2018W35", "location": "", "project": "", "highPriority": False, "isDone": True } self.mock_args.task_id = 1 saver_mock.return_value = 1 loader_mock.return_value = dict.copy(test_task) self.mock_args.highPriority = True task.edit_task(self.mock_args) expected_new_test_task = dict.copy(test_task) expected_new_test_task["highPriority"] = True formatted_task = output_formatter.format_task(expected_new_test_task) expected = "You've changed task 1 to the following:\n" + formatted_task + "\n" self.assertEqual(mock_out.getvalue(), expected) saver_mock.assert_called()
def test_edit_task_edit_project(self, project_mock, loader_mock, saver_mock, mock_out): test_task = { "id": 1, "title": "design blog section", "date": "2018-09-02", "week": "2018W35", "location": "", "project": "", "highPriority": False, "isDone": True } test_project = { "id": 1, "title": "some proj", "shortcode": "some-proj", "color": "default", "isActive": True } self.mock_args.task_id = 1 saver_mock.return_value = 1 project_mock.return_value = test_project loader_mock.return_value = dict.copy(test_task) self.mock_args.project = "some-proj" task.edit_task(self.mock_args) expected_new_test_task = dict.copy(test_task) expected_new_test_task["project"] = test_project formatted_task = output_formatter.format_task(expected_new_test_task) expected = "You've changed task 1 to the following:\n" + formatted_task + "\n" self.assertEqual(mock_out.getvalue(), expected) saver_mock.assert_called()
def test_edit_task_try_to_add_invalid_project(self, loader_mock, saver_mock, _): test_task = { "id": 1, "title": "design blog section", "date": "2018-09-02", "week": "2018W35", "location": "", "project": "", "highPriority": False, "isDone": True } self.mock_args.task_id = 1 saver_mock.return_value = 1 loader_mock.return_value = dict.copy(test_task) self.mock_args.project = "merp" with self.assertRaises(SystemExit): task.edit_task(self.mock_args)
def test_edit_task_try_to_delete_title(self, loader_mock, saver_mock, mock_out, mock_err): test_task = { "id": 1, "title": "design blog section", "date": "2018-09-02", "week": "2018W35", "location": "", "project": "", "highPriority": False, "isDone": True } self.mock_args.task_id = 1 saver_mock.return_value = 1 loader_mock.return_value = dict.copy(test_task) self.mock_args.title = "" formatted_task = output_formatter.format_task(test_task) expected_err = "The title of a task cannot be empty. This entry will not be saved.\n" expected = "You've changed task 1 to the following:\n" + formatted_task + "\n" task.edit_task(self.mock_args) self.assertEqual(mock_err.getvalue(), expected_err) self.assertEqual(mock_out.getvalue(), expected) saver_mock.assert_called()