1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tests/internal/objects.py Mon Oct 16 18:37:33 2017 +0200
1.3 @@ -0,0 +1,100 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +Test objects.
1.8 +
1.9 +Copyright (C) 2017 Paul Boddie <paul@boddie.org.uk>
1.10 +
1.11 +This program is free software; you can redistribute it and/or modify it under
1.12 +the terms of the GNU General Public License as published by the Free Software
1.13 +Foundation; either version 3 of the License, or (at your option) any later
1.14 +version.
1.15 +
1.16 +This program is distributed in the hope that it will be useful, but WITHOUT
1.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.19 +details.
1.20 +
1.21 +You should have received a copy of the GNU General Public License along with
1.22 +this program. If not, see <http://www.gnu.org/licenses/>.
1.23 +"""
1.24 +
1.25 +from imiptools.data import parse_string, Object
1.26 +from imiptools.dates import get_datetime
1.27 +
1.28 +# Define a parent object plus recurrence instances.
1.29 +
1.30 +parent_str = """\
1.31 +BEGIN:VEVENT
1.32 +ORGANIZER:mailto:paul.boddie@example.com
1.33 +ATTENDEE;RSVP=TRUE:mailto:resource-room-confroom@example.com
1.34 +DTSTAMP:20141009T182400Z
1.35 +DTSTART;TZID=Europe/Oslo:20141010
1.36 +DTEND;TZID=Europe/Oslo:20141011
1.37 +RRULE:FREQ=MONTHLY;BYDAY=2FR;COUNT=3
1.38 +SUMMARY:Recurring event
1.39 +UID:event4@example.com
1.40 +END:VEVENT
1.41 +"""
1.42 +
1.43 +modification_str = """\
1.44 +BEGIN:VEVENT
1.45 +ORGANIZER:mailto:paul.boddie@example.com
1.46 +ATTENDEE;RSVP=TRUE:mailto:resource-room-confroom@example.com
1.47 +DTSTAMP:20141009T182500Z
1.48 +DTSTART;TZID=Europe/Oslo:20141115
1.49 +DTEND;TZID=Europe/Oslo:20141116
1.50 +SUMMARY:Recurring event
1.51 +UID:event4@example.com
1.52 +RECURRENCE-ID;TZID=Europe/Oslo:20141114
1.53 +SEQUENCE:2
1.54 +END:VEVENT
1.55 +"""
1.56 +
1.57 +cancellation_str = """\
1.58 +BEGIN:VEVENT
1.59 +ORGANIZER:mailto:paul.boddie@example.com
1.60 +ATTENDEE;RSVP=TRUE:mailto:resource-room-confroom@example.com
1.61 +DTSTAMP:20141009T182500Z
1.62 +DTSTART;TZID=Europe/Oslo:20141213
1.63 +DTEND;TZID=Europe/Oslo:20141214
1.64 +SUMMARY:Recurring event
1.65 +UID:event4@example.com
1.66 +RECURRENCE-ID;TZID=Europe/Oslo:20141213
1.67 +SEQUENCE:2
1.68 +END:VEVENT
1.69 +"""
1.70 +
1.71 +# Parse the objects.
1.72 +
1.73 +parent = Object(parse_string(parent_str, "utf-8"))
1.74 +modification = Object(parse_string(modification_str, "utf-8"))
1.75 +cancellation = Object(parse_string(cancellation_str, "utf-8"))
1.76 +
1.77 +# Set the recurrence objects in the parent.
1.78 +
1.79 +parent.set_modifying([modification])
1.80 +parent.set_cancelling([cancellation])
1.81 +
1.82 +# Obtain periods within a window of time.
1.83 +
1.84 +tzid = parent.get_tzid()
1.85 +start = get_datetime("20141001T000000", {"TZID" : tzid})
1.86 +end = get_datetime("20151001", {"TZID" : tzid})
1.87 +
1.88 +for p in parent.get_periods(start, end):
1.89 + print p
1.90 +
1.91 +print "----"
1.92 +
1.93 +for old, new in parent.get_updated_periods(start, end):
1.94 + print old
1.95 + print new
1.96 + print
1.97 +
1.98 +print "----"
1.99 +
1.100 +for p in parent.get_active_periods(start, end):
1.101 + print p
1.102 +
1.103 +# vim: tabstop=4 expandtab shiftwidth=4