1.1 --- a/tests/test_handle.py Mon Apr 18 21:07:41 2016 +0200
1.2 +++ b/tests/test_handle.py Tue Apr 19 00:53:59 2016 +0200
1.3 @@ -25,6 +25,7 @@
1.4 from imiptools.mail import Messenger
1.5 from imiptools.period import RecurringPeriod
1.6 from imiptools.stores import get_store, get_journal
1.7 +from os.path import split
1.8 import sys
1.9
1.10 class TestClient(ClientForObject):
1.11 @@ -36,7 +37,7 @@
1.12
1.13 # Action methods.
1.14
1.15 - def handle_request(self, action, start=None, end=None):
1.16 + def handle_request(self, action, start=None, end=None, recurrenceid=None):
1.17
1.18 """
1.19 Process the current request for the current user. Return whether the
1.20 @@ -44,8 +45,16 @@
1.21
1.22 If 'start' and 'end' are specified, they will be used in any
1.23 counter-proposal.
1.24 +
1.25 + Where 'recurrenceid' is specified and refers to a new recurrence, the
1.26 + action will apply only to this new recurrence.
1.27 """
1.28
1.29 + have_new_recurrence = self.obj.get_recurrenceid() != recurrenceid
1.30 +
1.31 + if have_new_recurrence:
1.32 + self.obj["RECURRENCE-ID"] = [(recurrenceid, {})]
1.33 +
1.34 # Reply only on behalf of this user.
1.35
1.36 if action in ("accept", "decline"):
1.37 @@ -66,9 +75,14 @@
1.38 period = RecurringPeriod(start, end, period.tzid, period.origin, period.get_start_attr(), period.get_end_attr())
1.39 self.obj.set_period(period)
1.40 method = "COUNTER"
1.41 +
1.42 + # Nothing else is supported.
1.43 +
1.44 else:
1.45 return None
1.46
1.47 + # Where no attendees remain, no message is generated.
1.48 +
1.49 if not attendee_attr:
1.50 return None
1.51
1.52 @@ -93,6 +107,8 @@
1.53 # response message to standard output.
1.54
1.55 if __name__ == "__main__":
1.56 + progname = split(sys.argv[0])[-1]
1.57 +
1.58 try:
1.59 action, store_type, store_dir, journal_dir, preferences_dir, user = sys.argv[1:7]
1.60 if action == "counter":
1.61 @@ -104,13 +120,18 @@
1.62 uid, recurrenceid = (sys.argv[i:i+2] + [None] * 2)[:2]
1.63 except ValueError:
1.64 print >>sys.stderr, """\
1.65 +Usage: %s <action> <store type> <store directory> <journal directory>
1.66 + <preferences directory> <user URI> [ <start> <end> ]
1.67 + <uid> <recurrence-id>
1.68 +
1.69 Need 'accept', 'counter' or 'decline', a store type, a store directory, a
1.70 journal directory, a preferences directory, user URI, any counter-proposal
1.71 datetimes (see below), plus the appropriate event UID and RECURRENCE-ID (if a
1.72 recurrence is involved).
1.73
1.74 The RECURRENCE-ID must be in exactly the form employed by the store, not a
1.75 -different but equivalent representation.
1.76 +different but equivalent representation, if the identifier is to refer to an
1.77 +existing recurrence.
1.78
1.79 Alternatively, omit the UID and RECURRENCE-ID and provide event-only details on
1.80 standard input to force the script to handle an event not already present in the
1.81 @@ -127,6 +148,11 @@
1.82 if uid is not None:
1.83 fragment = store.get_event(user, uid, recurrenceid)
1.84
1.85 + # Permit new recurrences by getting the parent object.
1.86 +
1.87 + if not fragment:
1.88 + fragment = store.get_event(user, uid)
1.89 +
1.90 if not fragment:
1.91 print >>sys.stderr, "No such event:", uid, recurrenceid
1.92 sys.exit(1)
1.93 @@ -135,7 +161,7 @@
1.94
1.95 obj = Object(fragment)
1.96 handler = TestClient(obj, user, Messenger(), store, None, journal, preferences_dir)
1.97 - response = handler.handle_request(action, start, end)
1.98 + response = handler.handle_request(action, start, end, recurrenceid)
1.99
1.100 if response:
1.101 if uid is not None: