3 #======================================================================
10 # $Id: test.py,v 1.24 2002-10-24 13:44:31 acampi Exp $
13 # (C) COPYRIGHT 2001, Eric Busboom <eric@softwarestudio.org>
14 # (C) COPYRIGHT 2001, Patrick Lewis <plewis@inetarena.com>
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of either:
19 # The LGPL as published by the Free Software Foundation, version
20 # 2.1, available at: http://www.fsf.org/copyleft/lesser.html
24 # The Mozilla Public License Version 1.0. You may obtain a copy of
25 # the License at http://www.mozilla.org/MPL/
26 #======================================================================
32 error = icalerror_perror()
33 return error[:index(error,':')]
38 PRODID:-//ABC Corporation//NONSGML My Product//EN
41 ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com
42 COMMENT: When in the course of writting comments and nonsense text\, it
43 becomes necessary to insert a newline
44 DTSTART:19972512T120000
45 DTSTART:19970101T120000Z
48 FREEBUSY:19970101T120000/19970101T120000
49 FREEBUSY:19970101T120000/PT3H
50 FREEBUSY:19970101T120000/PT3H
57 print "--------------------------- Test Property ----------------------"
61 icalprop = liw.icalproperty_new_from_string("ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com")
63 print liw.icalproperty_as_ical_string(icalprop)
65 p = Property(ref=icalprop)
70 for param in p.parameters():
71 print " ", param, " = ", p[param]
75 p['ROLE'] = 'INDIVIDUAL'
79 p['ROLE'] = 'GROFROMBLATZ'
85 p['X-MAN-FAVOURITE'] = 'Wolverine'
86 p['X-FILES-FAVOURITE'] = 'Mulder'
88 print p['X-MAN-FAVOURITE']
90 assert(p['X-MAN-FAVOURITE'] == 'Wolverine')
91 assert(p['X-FILES-FAVOURITE'] == 'Mulder')
92 assert(p['X-FILES-FAVOURITE'] != 'Scully')
95 p.value("mailto:Bob@bob.com")
99 print p.as_ical_string()
101 del p['X-MAN-FAVOURITE']
103 print p.as_ical_string()
108 except Property.ConstructorFailedError:
114 p = Property("X-COMMENT")
116 p.value("This is a sentence, with punctuation; indeed: it is")
119 p.value("This is not approved by the Ministry of Silly Walks")
123 assert(test_enum('METHOD','PUBLISH'))
124 assert(not test_enum('METHOD','FOO'))
126 assert(test_enum('ACTION','AUDIO'))
127 assert(not test_enum('ACTION','OPAQUE'))
132 print"-------------------Test Time --------------------------------"
134 t = Time("19970325T123010Z",'DTSTART')
136 assert(t.year == 1997)
140 assert(t.minute == 30)
141 assert(t.second == 10)
143 assert(not t.is_date())
147 t.timezone("America/Los_Angeles")
150 #assert(str(t)=='DTSTART;TZID=America/Los_Angeles:19970325T123010')
151 assert(str(t)=='DTSTART;TZID=/freeassociation.sourceforge.net/Tzfile/America/Los_Angeles:19970325T053010')
153 t.second = t.second+80
156 print t.minute, t.second
157 assert(t.minute == 31)
158 assert(t.second == 30)
160 d = Duration(3600,"DURATION")
164 assert(t2.hour == 13)
169 assert(isinstance(t2,Time))
170 assert(t2.hour == 11)
182 print"-------------------Test Period--------------------------------"
184 p = Period("19970101T180000Z/19970101T233000Z")
188 assert(str(p) == 'FREEBUSY:19970101T180000Z/19970101T233000Z')
191 assert(str(p.start()) == 'DTSTART:19970101T180000Z')
194 assert(str(p.end()) == 'DTEND:19970101T233000Z')
197 assert(str(p.duration()) == 'DURATION:PT5H30M')
200 p = Period("19970101T180000Z/PT5H30M")
204 assert(str(p.start()) == 'DTSTART:19970101T180000Z')
207 assert(str(p.end()) == 'DTEND:19970101T233000Z')
210 assert(str(p.duration()) == 'DURATION:PT5H30M')
215 print "-------------- Test Duration ----------------"
219 d = Duration("P3DT4H25M")
223 assert(str(d) == "DURATION:P3DT4H25M")
227 assert(d.seconds() == 275100)
231 d = Duration(-275100)
235 assert(str(d) == "DURATION:-P3DT4H25M")
239 assert(d.seconds() == -275100)
244 d = Duration("P10WT7M")
250 d = Duration("Pgiberish")
260 file = open('littlefile.txt')
261 attachProp = Attach(file)
263 attachProp.fmttype('text/ascii')
264 print "\n" + attachProp.name()
265 print attachProp.value_type()
266 print attachProp.fmttype()
267 attachProp['fmttype']=None
268 print "Calling value()"
269 print attachProp.value()
270 print "Calling asIcalString()"
271 print attachProp.as_ical_string()
274 def test_component():
276 print "------------------- Test Component ----------------------"
279 c = NewComponent(comp_str);
281 props = c.properties()
284 print p.as_ical_string()
286 inner = c.components()[0]
292 props = inner.properties()
295 print p.as_ical_string()
297 dtstart = inner.properties('DTSTART')[0]
301 print "\n Orig hour: ", dtstart.hour
302 assert(dtstart.hour == 12)
304 dtstart.hour = dtstart.hour + 5
306 print "\n New hour: ", dtstart.hour
307 assert(dtstart.hour == 17)
309 attendee = inner.properties('ATTENDEE')[0]
313 t = Time("20011111T123030")
316 inner.add_property(t)
321 dtstart1 = inner.properties('DTSTART')[0]
322 dtstart2 = inner.properties('DTSTART')[0]
323 dtstart3 = inner.property('DTSTART')
325 assert(dtstart1 is dtstart2)
326 assert(dtstart1 == dtstart2)
328 assert(dtstart1 is dtstart3)
329 assert(dtstart1 == dtstart3)
332 p = Property(type="SUMMARY");
333 p.value("This is a summary")
335 inner.properties().append(p)
337 print inner.as_ical_string()
339 p = inner.properties("SUMMARY")[0]
342 assert(str(p) == "SUMMARY:This is a summary")
344 inner.properties()[:] = [p]
346 print inner.as_ical_string()
352 event.sequence("foo")
357 print event.sequence()
361 print event.sequence()
364 print "------------ Event Class ----------------------"
368 event.method('REQUEST')
371 event.created("20010313T123000Z")
372 print "created =", event.created()
373 assert (event.created() == Time("20010313T123000Z"))
375 event.organizer("MAILTO:j_doe@nowhere.com")
376 org = event.organizer()
379 assert (isinstance(org, Organizer))
380 print "organizer =", event.organizer()
381 assert (event.organizer().value() == "MAILTO:j_doe@nowhere.com")
383 event.dtstart("20010401T183000Z")
384 print "dtstart =", event.dtstart()
385 assert (event.dtstart()== Time("20010401T183000Z"))
387 dtend = Time('20010401T190000Z', 'DTEND')
389 assert (event.dtend() ==dtend )
390 assert (event.dtend() == Time('20010401T190000Z'))
393 att.value('jsmith@nothere.com')
394 event.attendees(('ef_hutton@listenup.com', att))
396 event.x_properties('X-TEST',('foo', 'bar'))
397 event.x_properties('X-TEST2',('foo, biz', 'bar, biz'))
399 inner = event.components()[0]
400 for e in inner.properties('X-TEST'):
401 print " ", e.as_ical_string()
403 assert(len(event.x_properties('X-TEST'))==2)
405 event.description("A short description. Longer ones break things. Really. What does it break. The code is supposed to handle realy long lines, longer, in fact, than any sane person would create except by writting a random text generator or by excerpting text from a less sane person. Actually, it did \"break\" and I had to remove an \n assert to fix it.")
406 event.status('TeNtAtIvE')
408 print event.as_ical_string()
411 def test_derivedprop():
413 print "------------ Derived Properties -----------------"
415 p = RDate("20011111T123030")
420 p = RDate("19970101T120000/19970101T123000")
425 p = RDate("P3DT4H25M")
431 p = Trigger("P3DT4H25M")
435 p = Trigger("20011111T123030")
440 p = Trigger("19970101T120000/19970101T123000")
446 print "------------ Gauge -----------------"
449 event.method('REQUEST')
451 event.created("20010313T123000Z")
452 event.organizer("MAILTO:j_doe@nowhere.com")
453 org = event.organizer()
455 event.dtstart("20010401T183000Z")
456 dtend = Time('20010401T190000Z', 'DTEND')
458 event.description("A short description.")
459 event.status('TeNtAtIvE')
461 print event.as_ical_string()
463 gauge = Gauge(sql="SELECT * FROM VEVENT WHERE DTSTART > '20010401T180000Z'")
465 assert(gauge.compare(event) == 1)
467 gauge = Gauge(sql="SELECT * FROM VEVENT WHERE DTSTART > '20010401T190000Z'")
469 assert(gauge.compare(event) == 0)
471 def do_test_store(storeobj=None, *args):
472 assert(storeobj != None)
473 store = storeobj(*args)
474 assert(store != None)
476 print ">------------ ",
477 print store.__class__,
478 print "Store -----------------"
485 event.method('REQUEST')
487 event.created("20010313T123000Z")
488 event.organizer("MAILTO:j_doe@nowhere.com")
489 event.dtstart("20010401T183000Z")
490 event.duration('PT3H')
492 event.description("A short description.")
496 # munge uid and increment month
497 for i in range(1,11):
498 newevent = event.clone()
499 newevent.uid("%d@localhost" % (i,))
500 newevent.dtstart().month = newevent.dtstart().month + i
503 store.add_component(newevent)
507 assert(store.count_components("VCALENDAR") == 10)
512 store = storeobj(*args)
513 # assert count of components = 10
514 assert(store.count_components("VCALENDAR") == 10)
518 n7 = store.fetch("7@localhost")
522 n7m = store.fetchMatch(n7)
523 assert(str(n7) == str(n7m))
526 n7.uid("42@localhost")
530 store = storeobj(*args)
531 assert(store.fetch("42@localhost") == None)
532 n7 = store.fetch("7@localhost")
533 n7.uid("42@localhost")
537 store = storeobj(*args)
538 assert(store.fetch("7@localhost") == None)
542 gauge = Gauge(sql="SELECT * FROM VEVENT WHERE DTSTART > '20010601T000000Z' AND DTSTART < '20010901T000000Z'")
548 c = store.first_component()
554 c = store.next_component()
561 c = store.first_component()
564 store.remove_component(c)
565 c = store.first_component()
567 assert(store.count_components("VCALENDAR") == 0)
569 assert(store.count_components("VCALENDAR") == 0)
571 # assert count of components = 0
575 print "------------ Store -----------------"
576 do_test_store(FileStore,"filesetout.ics")
579 print "Running unit tests for:", ICAL_PACKAGE, ICAL_VERSION
604 if __name__ == "__main__":