# HG changeset patch # User Paul Boddie # Date 1432218740 -7200 # Node ID ecb4ce872c01f36092f9dbec3326f1f78339919e # Parent 11c6111300fc5108493a135120a650aa395fe84f Made the test handler usable for declining invitations and added a test of conflicting events that are explicitly declined. diff -r 11c6111300fc -r ecb4ce872c01 tests/templates/event-request-person-conflict.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/templates/event-request-person-conflict.txt Thu May 21 16:32:20 2015 +0200 @@ -0,0 +1,34 @@ +Content-Type: multipart/alternative; boundary="===============0047278175==" +MIME-Version: 1.0 +From: paul.boddie@example.com +To: vincent.vole@example.com +Subject: Invitation! + +--===============0047278175== +Content-Type: text/plain; charset="us-ascii" +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit + +This message contains an event. +--===============0047278175== +MIME-Version: 1.0 +Content-Transfer-Encoding: 7bit +Content-Type: text/calendar; charset="us-ascii"; method="REQUEST" + +BEGIN:VCALENDAR +PRODID:-//imip-agent/test//EN +METHOD:REQUEST +VERSION:2.0 +BEGIN:VEVENT +ORGANIZER:mailto:paul.boddie@example.com +ATTENDEE;ROLE=CHAIR:mailto:paul.boddie@example.com +ATTENDEE;RSVP=TRUE:mailto:vincent.vole@example.com +DTSTAMP:20141125T004600Z +DTSTART;TZID=Europe/Oslo:20141126T160000 +DTEND;TZID=Europe/Oslo:20141126T170000 +SUMMARY:A conflicting meeting at 4pm +UID:event7@example.com +END:VEVENT +END:VCALENDAR + +--===============0047278175==-- diff -r 11c6111300fc -r ecb4ce872c01 tests/test_accept.py --- a/tests/test_accept.py Thu May 21 16:31:38 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,101 +0,0 @@ -#!/usr/bin/env python - -""" -A handler to help with testing. - -Copyright (C) 2014, 2015 Paul Boddie - -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 the Free Software -Foundation; either version 3 of the License, or (at your option) any later -version. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see . -""" - -from imiptools.client import Client -from imiptools.data import Object, get_address -from imiptools.handlers import Handler -from imiptools.mail import Messenger -import imip_store -import sys - -class TestHandler(Handler): - - """ - A content handler for use in testing, as opposed to operating within the - mail processing pipeline. - """ - - def __init__(self, obj, user, messenger): - Handler.__init__(self, messenger=messenger) - Client.__init__(self, user) # this redefines the Handler initialisation - - self.set_object(obj) - - # Action methods. - - def accept_request(self): - - """ - Process the current request for the current user. Return whether any - action was taken. - """ - - # Reply only on behalf of this user. - - attendee_attr = self.update_participation(self.obj, "ACCEPTED") - - if not attendee_attr: - return None - - # NOTE: This is a simpler form of the code in imipweb.handler. - - organiser = get_address(self.obj.get_value("ORGANIZER")) - - self.obj["ATTENDEE"] = [(self.user, attendee_attr)] - self.update_dtstamp() - self.set_sequence(False) - - message = self.messenger.make_outgoing_message( - [self.obj.to_part("REPLY")], - [organiser], - outgoing_bcc=get_address(self.user) - ) - - return message.as_string() - -# A simple main program that attempts to accept a stored request, writing the -# response message to standard output. - -if __name__ == "__main__": - try: - store_dir, user, uid, recurrenceid = (sys.argv[1:5] + [None])[:4] - except ValueError: - print >>sys.stderr, "Need a store directory, user URI, event UID and optional RECURRENCE-ID." - sys.exit(1) - - store = imip_store.FileStore(store_dir) - fragment = store.get_event(user, uid, recurrenceid) - - if not fragment: - print >>sys.stderr, "No such event:", uid, recurrenceid - sys.exit(1) - - obj = Object(fragment) - handler = TestHandler(obj, user, Messenger()) - response = handler.accept_request() - - if response: - store.dequeue_request(user, uid, recurrenceid) - print response - else: - sys.exit(1) - -# vim: tabstop=4 expandtab shiftwidth=4 diff -r 11c6111300fc -r ecb4ce872c01 tests/test_handle.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_handle.py Thu May 21 16:32:20 2015 +0200 @@ -0,0 +1,102 @@ +#!/usr/bin/env python + +""" +A handler to help with testing. + +Copyright (C) 2014, 2015 Paul Boddie + +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 the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +from imiptools.client import Client +from imiptools.data import Object, get_address +from imiptools.handlers import Handler +from imiptools.mail import Messenger +import imip_store +import sys + +class TestHandler(Handler): + + """ + A content handler for use in testing, as opposed to operating within the + mail processing pipeline. + """ + + def __init__(self, obj, user, messenger): + Handler.__init__(self, messenger=messenger) + Client.__init__(self, user) # this redefines the Handler initialisation + + self.set_object(obj) + + # Action methods. + + def handle_request(self, accept): + + """ + Process the current request for the current user. Return whether any + action was taken. + """ + + # Reply only on behalf of this user. + + attendee_attr = self.update_participation(self.obj, accept and "ACCEPTED" or "DECLINED") + + if not attendee_attr: + return None + + # NOTE: This is a simpler form of the code in imipweb.handler. + + organiser = get_address(self.obj.get_value("ORGANIZER")) + + self.obj["ATTENDEE"] = [(self.user, attendee_attr)] + self.update_dtstamp() + self.set_sequence(False) + + message = self.messenger.make_outgoing_message( + [self.obj.to_part("REPLY")], + [organiser], + outgoing_bcc=get_address(self.user) + ) + + return message.as_string() + +# A simple main program that attempts to handle a stored request, writing the +# response message to standard output. + +if __name__ == "__main__": + try: + nargs = 5 + accept, store_dir, user, uid, recurrenceid = (sys.argv[1:nargs+1] + [None])[:nargs] + except ValueError: + print >>sys.stderr, "Need 'accept' or 'decline', a store directory, user URI, event UID and optional RECURRENCE-ID." + sys.exit(1) + + store = imip_store.FileStore(store_dir) + fragment = store.get_event(user, uid, recurrenceid) + + if not fragment: + print >>sys.stderr, "No such event:", uid, recurrenceid + sys.exit(1) + + obj = Object(fragment) + handler = TestHandler(obj, user, Messenger()) + response = handler.handle_request(accept == "accept") + + if response: + store.dequeue_request(user, uid, recurrenceid) + print response + else: + sys.exit(1) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 11c6111300fc -r ecb4ce872c01 tests/test_person_invitation.sh --- a/tests/test_person_invitation.sh Thu May 21 16:31:38 2015 +0200 +++ b/tests/test_person_invitation.sh Thu May 21 16:32:20 2015 +0200 @@ -19,8 +19,11 @@ PYTHONPATH="$THIS_DIR/.." export PYTHONPATH -ACCEPT_SCRIPT="$THIS_DIR/test_accept.py" -ACCEPT_ARGS="$STORE" +ACCEPT_SCRIPT="$THIS_DIR/test_handle.py" +ACCEPT_ARGS="accept $STORE" + +DECLINE_SCRIPT="$THIS_DIR/test_handle.py" +DECLINE_ARGS="decline $STORE" rm -r $STORE rm -r $STATIC @@ -66,3 +69,28 @@ grep -q "^20141126T150000Z${TAB}20141126T160000Z" "$FBFILE" \ && echo "Success" \ || echo "Failed" + + "$PERSON_SCRIPT" $ARGS < "$TEMPLATES/event-request-person-conflict.txt" 2> /dev/null \ +| "$SHOWMAIL" \ +> out4.tmp + + ! grep -q 'METHOD:REPLY' out4.tmp \ +&& echo "Success" \ +|| echo "Failed" + + ! grep -q "event7@example.com" "$FBFILE" \ +&& echo "Success" \ +|| echo "Failed" + + grep -q "event7@example.com" "$FBOTHERFILE" \ +&& echo "Success" \ +|| echo "Failed" + + "$DECLINE_SCRIPT" $DECLINE_ARGS "$USER" "event7@example.com" \ +| tee out5.tmp \ +| "$OUTGOING_SCRIPT" $ARGS + + grep -q "event6@example.com" "$FBFILE" \ +&& ! grep -q "event7@example.com" "$FBFILE" \ +&& echo "Success" \ +|| echo "Failed"