summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Brox <tobias@redpill-linpro.com>2020-06-05 01:15:38 +0200
committerTobias Brox <tobias@redpill-linpro.com>2020-06-05 01:15:38 +0200
commit202825548178e61e2abc0d956ae386bb250cc919 (patch)
tree77e03a2813997169389d63675083d9e37e2430cd
parent863bf6f280d6d714c46deb55c93e99106083e8cc (diff)
downloadcalendar-cli-202825548178e61e2abc0d956ae386bb250cc919.zip
make it possible to create a calendar, resolves https://github.com/tobixen/calendar-cli/issues/69 - automated tests towards radicale, ref https://github.com/tobixen/calendar-cli/issues/68
-rw-r--r--README.md2
-rwxr-xr-xcalendar-cli.py26
-rw-r--r--tests/README7
-rwxr-xr-xtests/test_calendar-cli.sh29
-rwxr-xr-xtests/tests.sh (renamed from tests/script_test.sh)22
5 files changed, 74 insertions, 12 deletions
diff --git a/README.md b/README.md
index f4e2b8b..9a09585 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@ Other tools
There is another project out there, "Command-line Interface for Google Calendar", previously located at pypi under the calendar-cli name. It has now been renamed to gcalendar-cli to avoid name conflict, and is available at https://pypi.python.org/pypi/gcalendar-cli/
-There is a "competing" project at https://github.com/geier/khal - you may want to check it out - it's more mature but probably more complex. It's using a "vsyncdir" backend - if I've understood it correctly, that involves building a local copy of the calendar. The philosophy behind calendar-cli is slightly different, calendar-cli is supposed to be a simple cli-based caldav+ical client. No synchronization, no local storage.
+There is a "competing" project at https://github.com/geier/khal - you may want to check it out - it's more mature but probably more complex. It's using a "vsyncdir" backend - if I've understood it correctly, that involves building a local copy of the calendar. The philosophy behind calendar-cli is slightly different, calendar-cli is supposed to be a simple cli-based caldav+ical client. No synchronization, no local storage, just client-side operations.
Installation
------------
diff --git a/calendar-cli.py b/calendar-cli.py
index b08eb19..d138fd1 100755
--- a/calendar-cli.py
+++ b/calendar-cli.py
@@ -2,7 +2,7 @@
"""
calendar-cli.py - high-level cli against caldav servers
-Copyright (C) 2013-2019 Tobias Brox and other contributors
+Copyright (C) 2013-2020 Tobias Brox and other contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -149,9 +149,12 @@ def find_calendar(caldav_conn, args):
if '/' in args.calendar_url:
return caldav.Calendar(client=caldav_conn, url=args.calendar_url)
else:
- return caldav.Principal(caldav_conn).calendar(name=args.calendar_url)
+ return caldav.Principal(caldav_conn).calendar(cal_id=args.calendar_url)
else:
## Find default calendar
+ calendars = caldav.Principal(caldav_conn).calendars()
+ if not calendars:
+ sys.stderr.write("no calendar url given and no default calendar found - can't proceed. You will need to create a calendar first")
return caldav.Principal(caldav_conn).calendars()[0]
def _calendar_addics(caldav_conn, ics, uid, args):
@@ -523,6 +526,16 @@ def calendar_agenda(caldav_conn, args):
event[attr] = to_normal_str(event[attr])
print(args.event_template.format(**event))
+def create_calendar(caldav_conn, args):
+ cal_obj = caldav.Principal(caldav_conn).make_calendar(cal_id=args.cal_id)
+ if cal_obj:
+ print("Created a calendar with id " + args.cal_id)
+
+def create_tasklist(caldav_conn, args):
+ cal_obj = caldav.Principal(caldav_conn).make_calendar(cal_id=args.cal_id, supported_calendar_component_set=['VTODO'])
+ if cal_obj:
+ print("Created a task list with id " + args.tasklist_id)
+
def todo_select(caldav_conn, args):
if args.top+args.limit+args.offset+args.offsetn and args.todo_uid:
raise ValueError("It doesn't make sense to combine --todo-uid with --top/--limit/--offset/--offsetn")
@@ -832,6 +845,10 @@ def main():
#todo_parser.add_argument('--due-before', ....)
todo_parser.set_defaults(print_help=todo_parser.print_help)
todo_subparsers = todo_parser.add_subparsers(title='tasks subcommand')
+ todo_create_parser = todo_subparsers.add_parser('createlist')
+ todo_create_parser.add_argument('tasklist_id')
+ todo_create_parser.set_defaults(func=create_tasklist)
+
todo_add_parser = todo_subparsers.add_parser('add')
todo_add_parser.add_argument('summaryline', nargs='+')
todo_add_parser.add_argument('--set-dtstart', default=date.today()+timedelta(1))
@@ -883,6 +900,11 @@ def main():
calendar_parser = subparsers.add_parser('calendar')
calendar_parser.set_defaults(print_help=calendar_parser.print_help)
calendar_subparsers = calendar_parser.add_subparsers(title='cal subcommand')
+
+ calendar_create_parser = calendar_subparsers.add_parser('create')
+ calendar_create_parser.add_argument('cal_id')
+ calendar_create_parser.set_defaults(func=create_calendar)
+
calendar_add_parser = calendar_subparsers.add_parser('add')
calendar_add_parser.add_argument('event_time', help="Timestamp and duration of the event. See the documentation for event_time specifications")
calendar_add_parser.add_argument('summary', nargs='+')
diff --git a/tests/README b/tests/README
new file mode 100644
index 0000000..406ea8e
--- /dev/null
+++ b/tests/README
@@ -0,0 +1,7 @@
+TL;DR: run test_calendar-cli.sh, don't run tests.sh.
+
+Probably we should add some standard python test code here that can be run through nose or tox, but after all this is a command line utility - hence I found it appropriate to start with functional tests written to be executed from through a shell.
+
+The file tests.sh will run towards whatever calendar server is configured in .config/calendar.conf, and it has potential side effects, it will wipe out any prior events within the time range 2010-10-10 and 2010-10-14.
+
+The file test_calendar-cli.sh will set up a radicale calendar server, run the tests.sh towards radicale, then set up xandikos and run tests.sh towards xandikos.
diff --git a/tests/test_calendar-cli.sh b/tests/test_calendar-cli.sh
new file mode 100755
index 0000000..be2717e
--- /dev/null
+++ b/tests/test_calendar-cli.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+########################################################################
+## RADICALE
+########################################################################
+storage=$(mktemp -d)
+python3 -m radicale --storage-filesystem-folder=$storage &
+sleep 0.3
+jobs -l
+radicale_pid=$(jobs -l | perl -ne '/^\[\d+\]\+\s+(\d+)\s+Running/ && print $1')
+if [ -n "$radicale_pid" ]
+then
+ echo "## Radicale now running on pid $radicale_pid"
+ calendar_cli="../calendar-cli --caldav-url=http://localhost:5232/ --caldav-user=testuser --calendar-url=/testuser/calendar-cli-test-calendar"
+ $calendar_cli calendar create calendar-cli-test-calendar
+ export calendar_cli
+ ./tests.sh
+ kill $radicale_pid
+ rm -rf $storage
+else
+ echo "## Could not start up radicale (is it installed?). Will skip running tests towards radicale"
+fi
+
+
+########################################################################
+## XANDIKOS
+########################################################################
+## TODO! work in progress
+
diff --git a/tests/script_test.sh b/tests/tests.sh
index 3a3f91a..d496d8a 100755
--- a/tests/script_test.sh
+++ b/tests/tests.sh
@@ -1,20 +1,18 @@
#!/bin/bash
-## Sorry - I have no idea how much of this script is compatible with
-## POSIX shell and how much is bashisms ... been using bash for too
-## long.
-
set -e
+########################################################################
## SETUP
+########################################################################
error() {
echo "$1"
exit 255
}
-[ -x ./calendar-cli.py ] && calendar_cli=./calendar-cli.py
-[ -x ../calendar-cli.py ] && calendar_cli=../calendar-cli.py
+[ -z "$calendar_cli" ] && [ -x ./calendar-cli.py ] && calendar_cli=./calendar-cli.py
+[ -z "$calendar_cli" ] && [ -x ../calendar-cli.py ] && calendar_cli=../calendar-cli.py
[ -z "$calendar_cli" ] && error "couldn't find ./calendar_cli.py nor ../calendar_cli.py"
calendar_cli() {
@@ -28,7 +26,9 @@ calendar_cli() {
for uid in $($calendar_cli calendar agenda --from-time=2010-10-10 --agenda-days=4 --event-template='{uid}') ; do calendar_cli calendar delete --event-uid=$uid ; done
calendar_cli todo --categories scripttest delete
-## TESTING
+########################################################################
+## TEST CODE FOLLOWS
+########################################################################
## EVENTS
@@ -36,12 +36,16 @@ echo "## testing $calendar_cli"
echo "## this is a very simple test script without advanced error handling"
echo "## if this test script doesn't output 'all tests completed' in the end, something went wrong"
-echo "## Attempting to add a past event at 2010-10-09 20:00:00, 2 hours duration"
+echo "## Attempting to add an event at 2010-10-09 20:00:00, 2 hours duration"
calendar_cli calendar add '2010-10-09 20:00:00+2h' 'testing testing'
uid=$(echo $output | perl -ne '/uid=(.*)$/ && print $1')
-echo "## Attempting to add a past event at 2010-10-10 20:00:00, CET (1 hour duration is default)"
+[ -n "$uid" ] || error "got no UID back"
+
+echo "## Attempting to add an event at 2010-10-10 20:00:00, CET (1 hour duration is default), with description and non-ascii location"
calendar_cli calendar add '2010-10-10 20:00:00+01:00' 'testing testing' --set-description='this is a test calendar event' --set-location='Москва'
uid2=$(echo $output | perl -ne '/uid=(.*)$/ && print $1')
+[ -n "$uid2" ] || error "got no UID back"
+
echo "## Attempting to add a past event at 2010-10-11 20:00:00, CET, 3h duration"
calendar_cli calendar add '2010-10-11 20:00:00+01:00+3h' 'testing testing'
uid3=$(echo $output | perl -ne '/uid=(.*)$/ && print $1')