1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tests/templates/event-request-person-conflict.txt Thu May 21 16:32:20 2015 +0200
1.3 @@ -0,0 +1,34 @@
1.4 +Content-Type: multipart/alternative; boundary="===============0047278175=="
1.5 +MIME-Version: 1.0
1.6 +From: paul.boddie@example.com
1.7 +To: vincent.vole@example.com
1.8 +Subject: Invitation!
1.9 +
1.10 +--===============0047278175==
1.11 +Content-Type: text/plain; charset="us-ascii"
1.12 +MIME-Version: 1.0
1.13 +Content-Transfer-Encoding: 7bit
1.14 +
1.15 +This message contains an event.
1.16 +--===============0047278175==
1.17 +MIME-Version: 1.0
1.18 +Content-Transfer-Encoding: 7bit
1.19 +Content-Type: text/calendar; charset="us-ascii"; method="REQUEST"
1.20 +
1.21 +BEGIN:VCALENDAR
1.22 +PRODID:-//imip-agent/test//EN
1.23 +METHOD:REQUEST
1.24 +VERSION:2.0
1.25 +BEGIN:VEVENT
1.26 +ORGANIZER:mailto:paul.boddie@example.com
1.27 +ATTENDEE;ROLE=CHAIR:mailto:paul.boddie@example.com
1.28 +ATTENDEE;RSVP=TRUE:mailto:vincent.vole@example.com
1.29 +DTSTAMP:20141125T004600Z
1.30 +DTSTART;TZID=Europe/Oslo:20141126T160000
1.31 +DTEND;TZID=Europe/Oslo:20141126T170000
1.32 +SUMMARY:A conflicting meeting at 4pm
1.33 +UID:event7@example.com
1.34 +END:VEVENT
1.35 +END:VCALENDAR
1.36 +
1.37 +--===============0047278175==--
2.1 --- a/tests/test_accept.py Thu May 21 16:31:38 2015 +0200
2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2.3 @@ -1,101 +0,0 @@
2.4 -#!/usr/bin/env python
2.5 -
2.6 -"""
2.7 -A handler to help with testing.
2.8 -
2.9 -Copyright (C) 2014, 2015 Paul Boddie <paul@boddie.org.uk>
2.10 -
2.11 -This program is free software; you can redistribute it and/or modify it under
2.12 -the terms of the GNU General Public License as published by the Free Software
2.13 -Foundation; either version 3 of the License, or (at your option) any later
2.14 -version.
2.15 -
2.16 -This program is distributed in the hope that it will be useful, but WITHOUT
2.17 -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
2.18 -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
2.19 -details.
2.20 -
2.21 -You should have received a copy of the GNU General Public License along with
2.22 -this program. If not, see <http://www.gnu.org/licenses/>.
2.23 -"""
2.24 -
2.25 -from imiptools.client import Client
2.26 -from imiptools.data import Object, get_address
2.27 -from imiptools.handlers import Handler
2.28 -from imiptools.mail import Messenger
2.29 -import imip_store
2.30 -import sys
2.31 -
2.32 -class TestHandler(Handler):
2.33 -
2.34 - """
2.35 - A content handler for use in testing, as opposed to operating within the
2.36 - mail processing pipeline.
2.37 - """
2.38 -
2.39 - def __init__(self, obj, user, messenger):
2.40 - Handler.__init__(self, messenger=messenger)
2.41 - Client.__init__(self, user) # this redefines the Handler initialisation
2.42 -
2.43 - self.set_object(obj)
2.44 -
2.45 - # Action methods.
2.46 -
2.47 - def accept_request(self):
2.48 -
2.49 - """
2.50 - Process the current request for the current user. Return whether any
2.51 - action was taken.
2.52 - """
2.53 -
2.54 - # Reply only on behalf of this user.
2.55 -
2.56 - attendee_attr = self.update_participation(self.obj, "ACCEPTED")
2.57 -
2.58 - if not attendee_attr:
2.59 - return None
2.60 -
2.61 - # NOTE: This is a simpler form of the code in imipweb.handler.
2.62 -
2.63 - organiser = get_address(self.obj.get_value("ORGANIZER"))
2.64 -
2.65 - self.obj["ATTENDEE"] = [(self.user, attendee_attr)]
2.66 - self.update_dtstamp()
2.67 - self.set_sequence(False)
2.68 -
2.69 - message = self.messenger.make_outgoing_message(
2.70 - [self.obj.to_part("REPLY")],
2.71 - [organiser],
2.72 - outgoing_bcc=get_address(self.user)
2.73 - )
2.74 -
2.75 - return message.as_string()
2.76 -
2.77 -# A simple main program that attempts to accept a stored request, writing the
2.78 -# response message to standard output.
2.79 -
2.80 -if __name__ == "__main__":
2.81 - try:
2.82 - store_dir, user, uid, recurrenceid = (sys.argv[1:5] + [None])[:4]
2.83 - except ValueError:
2.84 - print >>sys.stderr, "Need a store directory, user URI, event UID and optional RECURRENCE-ID."
2.85 - sys.exit(1)
2.86 -
2.87 - store = imip_store.FileStore(store_dir)
2.88 - fragment = store.get_event(user, uid, recurrenceid)
2.89 -
2.90 - if not fragment:
2.91 - print >>sys.stderr, "No such event:", uid, recurrenceid
2.92 - sys.exit(1)
2.93 -
2.94 - obj = Object(fragment)
2.95 - handler = TestHandler(obj, user, Messenger())
2.96 - response = handler.accept_request()
2.97 -
2.98 - if response:
2.99 - store.dequeue_request(user, uid, recurrenceid)
2.100 - print response
2.101 - else:
2.102 - sys.exit(1)
2.103 -
2.104 -# vim: tabstop=4 expandtab shiftwidth=4
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/tests/test_handle.py Thu May 21 16:32:20 2015 +0200
3.3 @@ -0,0 +1,102 @@
3.4 +#!/usr/bin/env python
3.5 +
3.6 +"""
3.7 +A handler to help with testing.
3.8 +
3.9 +Copyright (C) 2014, 2015 Paul Boddie <paul@boddie.org.uk>
3.10 +
3.11 +This program is free software; you can redistribute it and/or modify it under
3.12 +the terms of the GNU General Public License as published by the Free Software
3.13 +Foundation; either version 3 of the License, or (at your option) any later
3.14 +version.
3.15 +
3.16 +This program is distributed in the hope that it will be useful, but WITHOUT
3.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
3.18 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
3.19 +details.
3.20 +
3.21 +You should have received a copy of the GNU General Public License along with
3.22 +this program. If not, see <http://www.gnu.org/licenses/>.
3.23 +"""
3.24 +
3.25 +from imiptools.client import Client
3.26 +from imiptools.data import Object, get_address
3.27 +from imiptools.handlers import Handler
3.28 +from imiptools.mail import Messenger
3.29 +import imip_store
3.30 +import sys
3.31 +
3.32 +class TestHandler(Handler):
3.33 +
3.34 + """
3.35 + A content handler for use in testing, as opposed to operating within the
3.36 + mail processing pipeline.
3.37 + """
3.38 +
3.39 + def __init__(self, obj, user, messenger):
3.40 + Handler.__init__(self, messenger=messenger)
3.41 + Client.__init__(self, user) # this redefines the Handler initialisation
3.42 +
3.43 + self.set_object(obj)
3.44 +
3.45 + # Action methods.
3.46 +
3.47 + def handle_request(self, accept):
3.48 +
3.49 + """
3.50 + Process the current request for the current user. Return whether any
3.51 + action was taken.
3.52 + """
3.53 +
3.54 + # Reply only on behalf of this user.
3.55 +
3.56 + attendee_attr = self.update_participation(self.obj, accept and "ACCEPTED" or "DECLINED")
3.57 +
3.58 + if not attendee_attr:
3.59 + return None
3.60 +
3.61 + # NOTE: This is a simpler form of the code in imipweb.handler.
3.62 +
3.63 + organiser = get_address(self.obj.get_value("ORGANIZER"))
3.64 +
3.65 + self.obj["ATTENDEE"] = [(self.user, attendee_attr)]
3.66 + self.update_dtstamp()
3.67 + self.set_sequence(False)
3.68 +
3.69 + message = self.messenger.make_outgoing_message(
3.70 + [self.obj.to_part("REPLY")],
3.71 + [organiser],
3.72 + outgoing_bcc=get_address(self.user)
3.73 + )
3.74 +
3.75 + return message.as_string()
3.76 +
3.77 +# A simple main program that attempts to handle a stored request, writing the
3.78 +# response message to standard output.
3.79 +
3.80 +if __name__ == "__main__":
3.81 + try:
3.82 + nargs = 5
3.83 + accept, store_dir, user, uid, recurrenceid = (sys.argv[1:nargs+1] + [None])[:nargs]
3.84 + except ValueError:
3.85 + print >>sys.stderr, "Need 'accept' or 'decline', a store directory, user URI, event UID and optional RECURRENCE-ID."
3.86 + sys.exit(1)
3.87 +
3.88 + store = imip_store.FileStore(store_dir)
3.89 + fragment = store.get_event(user, uid, recurrenceid)
3.90 +
3.91 + if not fragment:
3.92 + print >>sys.stderr, "No such event:", uid, recurrenceid
3.93 + sys.exit(1)
3.94 +
3.95 + obj = Object(fragment)
3.96 + handler = TestHandler(obj, user, Messenger())
3.97 + response = handler.handle_request(accept == "accept")
3.98 +
3.99 + if response:
3.100 + store.dequeue_request(user, uid, recurrenceid)
3.101 + print response
3.102 + else:
3.103 + sys.exit(1)
3.104 +
3.105 +# vim: tabstop=4 expandtab shiftwidth=4
4.1 --- a/tests/test_person_invitation.sh Thu May 21 16:31:38 2015 +0200
4.2 +++ b/tests/test_person_invitation.sh Thu May 21 16:32:20 2015 +0200
4.3 @@ -19,8 +19,11 @@
4.4 PYTHONPATH="$THIS_DIR/.."
4.5 export PYTHONPATH
4.6
4.7 -ACCEPT_SCRIPT="$THIS_DIR/test_accept.py"
4.8 -ACCEPT_ARGS="$STORE"
4.9 +ACCEPT_SCRIPT="$THIS_DIR/test_handle.py"
4.10 +ACCEPT_ARGS="accept $STORE"
4.11 +
4.12 +DECLINE_SCRIPT="$THIS_DIR/test_handle.py"
4.13 +DECLINE_ARGS="decline $STORE"
4.14
4.15 rm -r $STORE
4.16 rm -r $STATIC
4.17 @@ -66,3 +69,28 @@
4.18 grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBFILE" \
4.19 && echo "Success" \
4.20 || echo "Failed"
4.21 +
4.22 + "$PERSON_SCRIPT" $ARGS < "$TEMPLATES/event-request-person-conflict.txt" 2> /dev/null \
4.23 +| "$SHOWMAIL" \
4.24 +> out4.tmp
4.25 +
4.26 + ! grep -q 'METHOD:REPLY' out4.tmp \
4.27 +&& echo "Success" \
4.28 +|| echo "Failed"
4.29 +
4.30 + ! grep -q "event7@example.com" "$FBFILE" \
4.31 +&& echo "Success" \
4.32 +|| echo "Failed"
4.33 +
4.34 + grep -q "event7@example.com" "$FBOTHERFILE" \
4.35 +&& echo "Success" \
4.36 +|| echo "Failed"
4.37 +
4.38 + "$DECLINE_SCRIPT" $DECLINE_ARGS "$USER" "event7@example.com" \
4.39 +| tee out5.tmp \
4.40 +| "$OUTGOING_SCRIPT" $ARGS
4.41 +
4.42 + grep -q "event6@example.com" "$FBFILE" \
4.43 +&& ! grep -q "event7@example.com" "$FBFILE" \
4.44 +&& echo "Success" \
4.45 +|| echo "Failed"