Exemple #1
0
    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()
Exemple #2
0
    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()
Exemple #3
0
    def test_add_task_with_title(self, saver_mock, mock_out):
        saver_mock.return_value = 3

        self.mock_args.title = "New Task"

        formatted_task = output_formatter.format_task(
            _task_from_args(3, "New Task", "", "", "", "", False, False))
        expected = "You've created the following task:\n" + formatted_task + "\n"

        task.add_task(self.mock_args)
        self.assertEqual(mock_out.getvalue(), expected)
        saver_mock.assert_called()
    def test_format_task(self):  #pylint: disable=R0914
        mock_task = {
            "id": 2,
            "title": "finish front-page design",
            "date": "2018-09-02",
            "week": "2018W35",
            "location": "Somewhere",
            "project": {
                "shortcode": "project",
                "color": "blue"
            },
            "highPriority": True,
            "isDone": False
        }

        prio = "\033[33m★" + self.reset
        done = " " + "☐"
        id_val = " " + self.dim + "  2." + self.reset
        title = " finish front-page design" + self.reset
        date = " " + self.bold + "@2018-09-02" + self.reset
        week = " " + self.bold + "@W35" + self.reset
        location = " " + "->Somewhere" + self.reset
        project = " " + self.bold + "\033[34m" + "#project" + self.reset

        self.assertEqual(
            output_formatter.format_task(mock_task),
            prio + done + id_val + title + date + location + project)

        mock_task["isDone"] = True
        done_done = " " + "\033[32m✓" + self.reset
        done_title = " " + self.dim + "finish front-page design" + self.reset
        done_date = " " + self.bold + self.dim + "@2018-09-02" + self.reset
        done_location = " " + self.dim + "->Somewhere" + self.reset
        done_project = " " + self.bold + self.dim + "\033[34m" + "#project" + self.reset
        self.assertEqual(
            output_formatter.format_task(mock_task), prio + done_done +
            id_val + done_title + done_date + done_location + done_project)
        mock_task["isDone"] = False

        mock_task["date"] = ""
        self.assertEqual(
            output_formatter.format_task(mock_task),
            prio + done + id_val + title + week + location + project)
        mock_task["location"] = ""
        self.assertEqual(output_formatter.format_task(mock_task),
                         prio + done + id_val + title + week + project)
        mock_task["project"] = ""
        self.assertEqual(output_formatter.format_task(mock_task),
                         prio + done + id_val + title + week)
        mock_task["week"] = ""
        self.assertEqual(output_formatter.format_task(mock_task),
                         prio + done + id_val + title)
        mock_task["highPriority"] = False
        self.assertEqual(output_formatter.format_task(mock_task),
                         " " + done + id_val + title)
Exemple #5
0
def add_task(args):
    if not args.title:
        print("You cannot create an empty task.", file=sys.stderr)
        return

    task = {}
    task["id"] = ""
    task["title"] = args.title
    task["location"] = args.location
    task["project"] = _parse_project(args.project) or ""
    task["highPriority"] = args.highPriority
    task["isDone"] = False
    parsed_date = _parse_date(args.date)
    task["date"] = parsed_date[0] or ""
    task["week"] = parsed_date[1] or ""

    task["id"] = save_task(task)
    print("You've created the following task:")
    print(format_task(task))
Exemple #6
0
def edit_task(args):
    task = load_task(str(args.task_id))

    task_changes = {}
    task_changes["title"] = _parse_title(args.title)
    task_changes["date"], task_changes["week"] = _parse_date(args.date)
    task_changes["location"] = args.location
    task_changes["project"] = _parse_project(args.project)
    if args.highPriority:
        task["highPriority"] = not task["highPriority"]

    for key, value in task_changes.items():
        if not value is None:
            task[key] = value

    if isinstance(task["project"], int):
        task["project"] = load_project(task["project"])

    save_task(task)
    print("You've changed task " + str(args.task_id) + " to the following:")
    print(format_task(task))
Exemple #7
0
def delete_project(args):
    project_to_delete = load_project_by_shortcode(args.shortcode)

    print("You've selected project " + format_project(project_to_delete) + " for deletion.")

    tasks_to_delete = _get_deletable_tasks(project_to_delete)
    if tasks_to_delete:
        print("This will also delete the following tasks which are attached to the project:")
        for task in tasks_to_delete:
            print(format_task(task))

    print("\nAre you sure? [y/n]")
    confirmation = input()
    if confirmation in ["y", "Y", "yes"]:
        for task in tasks_to_delete:
            remove_task(task)
        remove_project(project_to_delete)
        print("The project " + ("and all attached tasks were" if tasks_to_delete else "was") + " successfully deleted.")
        return

    print("Nothing was deleted.")
Exemple #8
0
    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()
    def test_format_task_block(self):
        mock_tasks = [{
            "id": 2,
            "title": "finish front-page design",
            "date": "2018-09-02",
            "week": "2018W35",
            "location": "Somewhere",
            "project": {
                "shortcode": "project",
                "color": "blue"
            },
            "highPriority": True,
            "isDone": False
        }, {
            "id": 3,
            "title": "finish front-page design",
            "date": "2018-09-02",
            "week": "2018W35",
            "location": "Somewhere",
            "project": {
                "shortcode": "project",
                "color": "blue"
            },
            "highPriority": True,
            "isDone": False
        }]

        context = "this"

        expected_task_format = output_formatter.format_task(
            mock_tasks[0]) + "\n" + output_formatter.format_task(
                mock_tasks[1]) + "\n\n"
        expected_empty_message = self.dim + "   --- No tasks for this " + context + " ---" + self.reset + "\n\n"

        self.assertEqual(output_formatter.format_task_block(context, []),
                         expected_empty_message)
        self.assertEqual(
            output_formatter.format_task_block(context, mock_tasks),
            expected_task_format)

        mock_no_proj = mock_tasks
        mock_no_proj[0]["project"] = ""
        mock_no_proj[1]["project"] = ""
        expected_task_format = output_formatter.format_task(
            mock_no_proj[0]) + "\n" + output_formatter.format_task(
                mock_no_proj[1]) + "\n\n"
        self.assertEqual(
            output_formatter.format_task_block(context,
                                               mock_tasks,
                                               print_project=False),
            expected_task_format)

        mock_no_date = mock_tasks
        mock_no_date[0]["date"] = ""
        mock_no_date[0]["week"] = ""
        mock_no_date[1]["date"] = ""
        mock_no_date[1]["week"] = ""
        expected_task_format = output_formatter.format_task(
            mock_no_date[0]) + "\n" + output_formatter.format_task(
                mock_no_date[1]) + "\n\n"
        self.assertEqual(
            output_formatter.format_task_block(context,
                                               mock_tasks,
                                               print_date=False),
            expected_task_format)

        mock_no_loc = mock_tasks
        mock_no_loc[0]["location"] = ""
        mock_no_loc[1]["location"] = ""
        expected_task_format = output_formatter.format_task(
            mock_no_loc[0]) + "\n" + output_formatter.format_task(
                mock_no_loc[1]) + "\n\n"
        self.assertEqual(
            output_formatter.format_task_block(context,
                                               mock_tasks,
                                               print_location=False),
            expected_task_format)