Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions tests/test_cli_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,33 @@ def test_new_command_with_all_flags(self):
self.assertEqual(args.list, "personal")
self.assertEqual(args.reminder, "9:00")

def test_new_command_with_important(self):
"""Test 'new' command with -I flag"""
args = self.parser.parse_args(["new", "-I", "buy milk"])
self.assertEqual(args.task_name, "buy milk")
self.assertTrue(args.important)

def test_new_command_with_important_long(self):
"""Test 'new' command with --important flag"""
args = self.parser.parse_args(["new", "--important", "buy milk"])
self.assertEqual(args.task_name, "buy milk")
self.assertTrue(args.important)

def test_new_command_without_important(self):
"""Test 'new' command defaults important to False"""
args = self.parser.parse_args(["new", "buy milk"])
self.assertFalse(args.important)

def test_new_command_with_all_flags_including_important(self):
"""Test 'new' command with -l, -r, and -I flags"""
args = self.parser.parse_args(
["new", "-l", "personal", "-r", "9:00", "-I", "buy milk"]
)
self.assertEqual(args.task_name, "buy milk")
self.assertEqual(args.list, "personal")
self.assertEqual(args.reminder, "9:00")
self.assertTrue(args.important)

def test_newl_command(self):
"""Test 'newl' command for creating lists"""
args = self.parser.parse_args(["newl", "shopping"])
Expand Down
8 changes: 7 additions & 1 deletion todocli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ def new(args):
if reminder_date_time_str is not None:
reminder_datetime = parse_datetime(reminder_date_time_str)

wrapper.create_task(name, list_name=task_list, reminder_datetime=reminder_datetime)
wrapper.create_task(
name,
list_name=task_list,
reminder_datetime=reminder_datetime,
important=args.important,
)


def newl(args):
Expand Down Expand Up @@ -136,6 +141,7 @@ def setup_parser():
subparser = subparsers.add_parser("new", help="Add a new task")
subparser.add_argument("task_name", help=helptext_task_name)
subparser.add_argument("-r", "--reminder")
subparser.add_argument("-I", "--important", action="store_true")
subparser.add_argument(
"-l",
"--list",
Expand Down
4 changes: 3 additions & 1 deletion todocli/graphapi/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import Union

from todocli.models.todolist import TodoList
from todocli.models.todotask import Task, TaskStatus
from todocli.models.todotask import Task, TaskImportance, TaskStatus
from todocli.graphapi.oauth import get_oauth_session

from todocli.utils.datetime_util import datetime_to_api_timestamp
Expand Down Expand Up @@ -91,6 +91,7 @@ def create_task(
list_name: str | None = None,
list_id: str | None = None,
reminder_datetime: datetime | None = None,
important: bool = False,
):
assert (list_name is not None) or (
list_id is not None
Expand All @@ -104,6 +105,7 @@ def create_task(
request_body = {
"title": task_name,
"reminderDateTime": datetime_to_api_timestamp(reminder_datetime),
"importance": TaskImportance.HIGH if important else TaskImportance.NORMAL,
}
session = get_oauth_session()
response = session.post(endpoint, json=request_body)
Expand Down