imip-agent

Annotated tests/internal/objects.py

1352:3c7f0da08063
2017-10-20 Paul Boddie Added conflicting period computation. Introduced ordering of suggested attendees and periods. Relaxed the attendee editing test. client-editing-simplification
paul@1322 1
#!/usr/bin/env python
paul@1322 2
paul@1322 3
"""
paul@1322 4
Test objects.
paul@1322 5
paul@1322 6
Copyright (C) 2017 Paul Boddie <paul@boddie.org.uk>
paul@1322 7
paul@1322 8
This program is free software; you can redistribute it and/or modify it under
paul@1322 9
the terms of the GNU General Public License as published by the Free Software
paul@1322 10
Foundation; either version 3 of the License, or (at your option) any later
paul@1322 11
version.
paul@1322 12
paul@1322 13
This program is distributed in the hope that it will be useful, but WITHOUT
paul@1322 14
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
paul@1322 15
FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
paul@1322 16
details.
paul@1322 17
paul@1322 18
You should have received a copy of the GNU General Public License along with
paul@1322 19
this program.  If not, see <http://www.gnu.org/licenses/>.
paul@1322 20
"""
paul@1322 21
paul@1322 22
from imiptools.data import parse_string, Object
paul@1322 23
from imiptools.dates import get_datetime
paul@1322 24
paul@1322 25
# Define a parent object plus recurrence instances.
paul@1322 26
paul@1322 27
parent_str = """\
paul@1322 28
BEGIN:VEVENT
paul@1322 29
ORGANIZER:mailto:paul.boddie@example.com
paul@1322 30
ATTENDEE;RSVP=TRUE:mailto:resource-room-confroom@example.com
paul@1322 31
DTSTAMP:20141009T182400Z
paul@1322 32
DTSTART;TZID=Europe/Oslo:20141010
paul@1322 33
DTEND;TZID=Europe/Oslo:20141011
paul@1322 34
RRULE:FREQ=MONTHLY;BYDAY=2FR;COUNT=3
paul@1322 35
SUMMARY:Recurring event
paul@1322 36
UID:event4@example.com
paul@1322 37
END:VEVENT
paul@1322 38
"""
paul@1322 39
paul@1322 40
modification_str = """\
paul@1322 41
BEGIN:VEVENT
paul@1322 42
ORGANIZER:mailto:paul.boddie@example.com
paul@1322 43
ATTENDEE;RSVP=TRUE:mailto:resource-room-confroom@example.com
paul@1322 44
DTSTAMP:20141009T182500Z
paul@1322 45
DTSTART;TZID=Europe/Oslo:20141115
paul@1322 46
DTEND;TZID=Europe/Oslo:20141116
paul@1322 47
SUMMARY:Recurring event
paul@1322 48
UID:event4@example.com
paul@1322 49
RECURRENCE-ID;TZID=Europe/Oslo:20141114
paul@1322 50
SEQUENCE:2
paul@1322 51
END:VEVENT
paul@1322 52
"""
paul@1322 53
paul@1322 54
cancellation_str = """\
paul@1322 55
BEGIN:VEVENT
paul@1322 56
ORGANIZER:mailto:paul.boddie@example.com
paul@1322 57
ATTENDEE;RSVP=TRUE:mailto:resource-room-confroom@example.com
paul@1322 58
DTSTAMP:20141009T182500Z
paul@1328 59
DTSTART;TZID=Europe/Oslo:20141212
paul@1328 60
DTEND;TZID=Europe/Oslo:20141213
paul@1322 61
SUMMARY:Recurring event
paul@1322 62
UID:event4@example.com
paul@1328 63
RECURRENCE-ID;TZID=Europe/Oslo:20141212
paul@1322 64
SEQUENCE:2
paul@1322 65
END:VEVENT
paul@1322 66
"""
paul@1322 67
paul@1322 68
# Parse the objects.
paul@1322 69
paul@1322 70
parent = Object(parse_string(parent_str, "utf-8"))
paul@1322 71
modification = Object(parse_string(modification_str, "utf-8"))
paul@1322 72
cancellation = Object(parse_string(cancellation_str, "utf-8"))
paul@1322 73
paul@1322 74
# Set the recurrence objects in the parent.
paul@1322 75
paul@1322 76
parent.set_modifying([modification])
paul@1322 77
parent.set_cancelling([cancellation])
paul@1322 78
paul@1322 79
# Obtain periods within a window of time.
paul@1322 80
paul@1322 81
tzid = parent.get_tzid()
paul@1322 82
start = get_datetime("20141001T000000", {"TZID" : tzid})
paul@1322 83
end = get_datetime("20151001", {"TZID" : tzid})
paul@1322 84
paul@1322 85
for p in parent.get_periods(start, end):
paul@1322 86
    print p
paul@1322 87
paul@1322 88
print "----"
paul@1322 89
paul@1322 90
for old, new in parent.get_updated_periods(start, end):
paul@1322 91
    print old
paul@1322 92
    print new
paul@1322 93
    print
paul@1322 94
paul@1322 95
print "----"
paul@1322 96
paul@1322 97
for p in parent.get_active_periods(start, end):
paul@1322 98
    print p
paul@1322 99
paul@1322 100
# vim: tabstop=4 expandtab shiftwidth=4