summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattori Birnbaum <mattori.birnbaum@gmail.com>2021-05-08 15:51:47 +0900
committerChristian Geier <geier@lostpackets.de>2023-10-28 16:40:56 +0200
commit3809a3183a41b30ba1177718ed547e44d8967902 (patch)
tree6dd2be0284976932c8f429583e217820e80a5ae5
parent01f44c8b5a6316d688973b727206e2137faa0c0c (diff)
added cli tests
-rw-r--r--khal/cli.py6
-rw-r--r--tests/cli_test.py27
2 files changed, 31 insertions, 2 deletions
diff --git a/khal/cli.py b/khal/cli.py
index 99e60ea7..ade17dab 100644
--- a/khal/cli.py
+++ b/khal/cli.py
@@ -315,11 +315,12 @@ def _get_cli():
)
@click.option('--notstarted', help=('Print only events that have not started.'),
is_flag=True)
+ @click.option('--json', help=("Fields to output in json"), multiple=True)
@click.argument('DATERANGE', nargs=-1, required=False,
metavar='[DATETIME [DATETIME | RANGE]]')
@click.pass_context
def klist(ctx, include_calendar, exclude_calendar,
- daterange, once, notstarted, format, day_format):
+ daterange, once, notstarted, json, format, day_format):
"""List all events between a start (default: today) and (optional)
end datetime."""
try:
@@ -334,7 +335,8 @@ def _get_cli():
once=once,
notstarted=notstarted,
conf=ctx.obj['conf'],
- env={"calendars": ctx.obj['conf']['calendars']}
+ env={"calendars": ctx.obj['conf']['calendars']},
+ json=json
)
if event_column:
click.echo('\n'.join(event_column))
diff --git a/tests/cli_test.py b/tests/cli_test.py
index f2b82710..870397a5 100644
--- a/tests/cli_test.py
+++ b/tests/cli_test.py
@@ -387,6 +387,19 @@ def test_at(runner):
assert result.output.startswith('myevent')
+def test_at_json(runner):
+ runner = runner(days=2)
+ now = dt.datetime.now().strftime('%d.%m.%Y')
+ end_date = dt.datetime.now() + dt.timedelta(days=10)
+ result = runner.invoke(
+ main_khal,
+ 'new {} {} 18:00 myevent'.format(now, end_date.strftime('%d.%m.%Y')).split())
+ args = ['--color', 'at', '--json', 'start-time', '--json', 'title', '18:30']
+ result = runner.invoke(main_khal, args)
+ assert not result.exception
+ assert result.output.startswith('[{"start-time": "", "title": "myevent"}]')
+
+
def test_at_day_format(runner):
runner = runner(days=2)
now = dt.datetime.now().strftime('%d.%m.%Y')
@@ -414,6 +427,20 @@ def test_list(runner):
assert result.output.startswith(expected)
+def test_list_json(runner):
+ runner = runner(days=2)
+ now = dt.datetime.now().strftime('%d.%m.%Y')
+ result = runner.invoke(
+ main_khal,
+ 'new {} 18:00 myevent'.format(now).split())
+ args = ['list', '--json', 'start-end-time-style',
+ '--json', 'title', '--json', 'description', '18:30']
+ result = runner.invoke(main_khal, args)
+ expected = '[{"start-end-time-style": "18:00-19:00", "title": "myevent", "description": ""}]'
+ assert not result.exception
+ assert result.output.startswith(expected)
+
+
def test_search(runner):
runner = runner(days=2)
now = dt.datetime.now().strftime('%d.%m.%Y')