diff options
author | Hans Petter <hansp@src.gnome.org> | 2003-09-12 06:04:44 +0800 |
---|---|---|
committer | Hans Petter <hansp@src.gnome.org> | 2003-09-12 06:04:44 +0800 |
commit | 697761cc337aa77a47140c8df50ed84bc25e23f6 (patch) | |
tree | b785830f72e9938cceaa016a419c7b6d9892bada /libical/src/python/test.py | |
parent | 733d77e657516f9a59b5c1a7b62acb87b03ec86f (diff) | |
download | gsoc2013-evolution-697761cc337aa77a47140c8df50ed84bc25e23f6.tar gsoc2013-evolution-697761cc337aa77a47140c8df50ed84bc25e23f6.tar.gz gsoc2013-evolution-697761cc337aa77a47140c8df50ed84bc25e23f6.tar.bz2 gsoc2013-evolution-697761cc337aa77a47140c8df50ed84bc25e23f6.tar.lz gsoc2013-evolution-697761cc337aa77a47140c8df50ed84bc25e23f6.tar.xz gsoc2013-evolution-697761cc337aa77a47140c8df50ed84bc25e23f6.tar.zst gsoc2013-evolution-697761cc337aa77a47140c8df50ed84bc25e23f6.zip |
Import new libical from mainline HEAD and make appropriate changes to
Evolution.
svn path=/trunk/; revision=22538
Diffstat (limited to 'libical/src/python/test.py')
-rw-r--r-- | libical/src/python/test.py | 294 |
1 files changed, 262 insertions, 32 deletions
diff --git a/libical/src/python/test.py b/libical/src/python/test.py index 1fdf515408..4047e78c95 100644 --- a/libical/src/python/test.py +++ b/libical/src/python/test.py @@ -25,6 +25,7 @@ # the License at http://www.mozilla.org/MPL/ #====================================================================== +import LibicalWrap from Libical import * def error_type(): @@ -32,6 +33,10 @@ def error_type(): return error[:index(error,':')] comp_str = """ +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//ABC Corporation//NONSGML My Product//EN +METHOD:REQUEST BEGIN:VEVENT ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com COMMENT: When in the course of writting comments and nonsense text\, it @@ -43,13 +48,15 @@ DURATION:P3DT4H25M FREEBUSY:19970101T120000/19970101T120000 FREEBUSY:19970101T120000/PT3H FREEBUSY:19970101T120000/PT3H -END:VEVENT""" +END:VEVENT +END:VCALENDAR""" def test_property(): print "--------------------------- Test Property ----------------------" - + + liw = LibicalWrap icalprop = liw.icalproperty_new_from_string("ATTENDEE;RSVP=TRUE;ROLE=REQ-PARTICIPANT;CUTYPE=GROUP:MAILTO:employee-A@host.com") @@ -58,19 +65,43 @@ def test_property(): p = Property(ref=icalprop) print p.name() - print p.parameters() + print + print "Parameters:" + for param in p.parameters(): + print " ", param, " = ", p[param] + print print p['ROLE'] p['ROLE'] = 'INDIVIDUAL' print p['ROLE'] + p['ROLE'] = 'GROFROMBLATZ' + + print p['ROLE'] + + print + + p['X-MAN-FAVOURITE'] = 'Wolverine' + p['X-FILES-FAVOURITE'] = 'Mulder' + + print p['X-MAN-FAVOURITE'] + + assert(p['X-MAN-FAVOURITE'] == 'Wolverine') + assert(p['X-FILES-FAVOURITE'] == 'Mulder') + assert(p['X-FILES-FAVOURITE'] != 'Scully') + print p.value() p.value("mailto:Bob@bob.com") print p.value() print p.as_ical_string() + del p['ROLE'] + del p['X-MAN-FAVOURITE'] + + print p.as_ical_string() + try: p = Property() @@ -79,6 +110,22 @@ def test_property(): else: assert(0) + # X Property + p = Property("X-COMMENT") + + p.value("This is a sentence, with punctuation; indeed: it is") + print p + + p.value("This is not approved by the Ministry of Silly Walks") + print p + + + assert(test_enum('METHOD','PUBLISH')) + assert(not test_enum('METHOD','FOO')) + + assert(test_enum('ACTION','AUDIO')) + assert(not test_enum('ACTION','OPAQUE')) + def test_time(): "Test routine" @@ -99,12 +146,13 @@ def test_time(): t.timezone("America/Los_Angeles") print str(t) - assert(str(t)=='DTSTART;TZID=America/Los_Angeles:19970325T123010Z') + print t.timezone() + #assert(str(t)=='DTSTART;TZID=America/Los_Angeles:19970325T123010') + assert(str(t)=='DTSTART;TZID=/softwarestudio.org/Olson_20010626_2/America/Los_Angeles:19970325T043010') t.second(t.second()+80) - print t - + t.timezone("UTC") assert(t.minute() == 31) assert(t.second() == 30) @@ -120,6 +168,13 @@ def test_time(): assert(isinstance(t2,Time)) assert(t2.hour() == 11) + # test int args + t = Time(2) + print t + + # test float args + t = Time(2.5) + print t def test_period(): @@ -129,7 +184,6 @@ def test_period(): print p - assert(str(p) == 'FREEBUSY:19970101T180000Z/19970101T233000Z') print p.start() @@ -221,14 +275,25 @@ def test_component(): print "------------------- Test Component ----------------------" - c = Component(comp_str); - + c = NewComponent(comp_str); + props = c.properties() for p in props: print p.as_ical_string() + + inner = c.components()[0] + + print inner + print type(inner) + + + props = inner.properties() + + for p in props: + print p.as_ical_string() - dtstart = c.properties('DTSTART')[0] + dtstart = inner.properties('DTSTART')[0] print dtstart @@ -240,21 +305,21 @@ def test_component(): print "\n New hour: ", dtstart.hour() assert(dtstart.hour() == 17) - attendee = c.properties('ATTENDEE')[0] + attendee = inner.properties('ATTENDEE')[0] print attendee t = Time("20011111T123030") t.name('DTEND') - c.add_property(t) + inner.add_property(t) print c - dtstart1 = c.properties('DTSTART')[0] - dtstart2 = c.properties('DTSTART')[0] - dtstart3 = c.property('DTSTART') + dtstart1 = inner.properties('DTSTART')[0] + dtstart2 = inner.properties('DTSTART')[0] + dtstart3 = inner.property('DTSTART') assert(dtstart1 is dtstart2) assert(dtstart1 == dtstart2) @@ -266,53 +331,81 @@ def test_component(): p = Property(type="SUMMARY"); p.value("This is a summary") - c.properties().append(p) + inner.properties().append(p) - print c.as_ical_string() + print inner.as_ical_string() - p = c.properties("SUMMARY")[0] + p = inner.properties("SUMMARY")[0] assert(p!=None); print str(p) assert(str(p) == "SUMMARY:This is a summary") - c.properties()[:] = [p] + inner.properties()[:] = [p] + + print inner.as_ical_string() + + # test sequence + event = Event() - print c.as_ical_string() + try: + event.sequence("foo") + except TypeError: + pass + event.sequence(-1) + print event.sequence() + event.sequence(1) + event.sequence(88) + print event.sequence() + def test_event(): print "------------ Event Class ----------------------" + event = Event() + + event.method('REQUEST') + event.version('2.0') + event.created("20010313T123000Z") - #print "created =", event.created() - assert (event.created() == "20010313T123000Z") + print "created =", event.created() + assert (event.created() == Time("20010313T123000Z")) event.organizer("MAILTO:j_doe@nowhere.com") - org = event.properties('ORGANIZER')[0] - #print org.cn() + org = event.organizer() + print org.cn() org.cn('Jane Doe') assert (isinstance(org, Organizer)) - #print "organizer =", event.organizer() - assert (event.organizer() == "MAILTO:j_doe@nowhere.com") + print "organizer =", event.organizer() + assert (event.organizer().value() == "MAILTO:j_doe@nowhere.com") event.dtstart("20010401T183000Z") - #print "dtstart =", event.dtstart() - assert (event.dtstart()=="20010401T183000Z") + print "dtstart =", event.dtstart() + assert (event.dtstart()== Time("20010401T183000Z")) dtend = Time('20010401T190000Z', 'DTEND') event.dtend(dtend) - assert (event.dtend()==dtend.value()) - assert (event.dtend() == '20010401T190000Z') + assert (event.dtend() ==dtend ) + assert (event.dtend() == Time('20010401T190000Z')) att = Attendee() att.value('jsmith@nothere.com') event.attendees(('ef_hutton@listenup.com', att)) + + event.x_properties('X-TEST',('foo', 'bar')) + event.x_properties('X-TEST2',('foo, biz', 'bar, biz')) + + inner = event.components()[0] + for e in inner.properties('X-TEST'): + print " ", e.as_ical_string() + + assert(len(event.x_properties('X-TEST'))==2) - event.description("A short description. Longer ones break things.") + 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.") event.status('TeNtAtIvE') print event.as_ical_string() - + def test_derivedprop(): @@ -348,6 +441,138 @@ def test_derivedprop(): assert(0) except: pass +def test_gauge(): + print "------------ Gauge -----------------" + event = Event() + + event.method('REQUEST') + event.version('2.0') + event.created("20010313T123000Z") + event.organizer("MAILTO:j_doe@nowhere.com") + org = event.organizer() + org.cn('Jane Doe') + event.dtstart("20010401T183000Z") + dtend = Time('20010401T190000Z', 'DTEND') + event.dtend(dtend) + event.description("A short description.") + event.status('TeNtAtIvE') + + print event.as_ical_string() + + gauge = Gauge(sql="SELECT * FROM VEVENT WHERE DTSTART > '20010401T180000Z'") + + assert(gauge.compare(event) == 1) + + gauge = Gauge(sql="SELECT * FROM VEVENT WHERE DTSTART > '20010401T190000Z'") + + assert(gauge.compare(event) == 0) + +def do_test_store(storeobj=None, *args): + assert(storeobj != None) + store = storeobj(*args) + assert(store != None) + + print ">------------ ", + print store.__class__, + print "Store -----------------" + + + # create fileset + + event = Event() + + event.method('REQUEST') + event.version('2.0') + event.created("20010313T123000Z") + event.organizer("MAILTO:j_doe@nowhere.com") + event.dtstart("20010401T183000Z") + event.duration('PT3H') + + event.description("A short description.") + + # for i = 1 to 10 + # copy event + # munge uid and increment month + for i in range(1,11): + newevent = event.clone() + newevent.uid("%d@localhost" % (i,)) + newevent.dtstart().month( newevent.dtstart().month() + i ) + + #print ne + store.add_component(newevent) + + # commit + store.commit() + assert(store.count_components("VCALENDAR") == 10) + # free + del(store) + + # open again + store = storeobj(*args) + # assert count of components = 10 + assert(store.count_components("VCALENDAR") == 10) + + # print them out + # fetch by uid + n7 = store.fetch("7@localhost") + print n7 + # fetch by match + + n7m = store.fetchMatch(n7) + assert(str(n7) == str(n7m)) + + # modify in memory + n7.uid("42@localhost") + del(store) + del(n7) + + store = storeobj(*args) + assert(store.fetch("42@localhost") == None) + n7 = store.fetch("7@localhost") + n7.uid("42@localhost") + store.mark() + store.commit() + del(store) + store = storeobj(*args) + assert(store.fetch("7@localhost") == None) + + # fetch by gauge + + gauge = Gauge(sql="SELECT * FROM VEVENT WHERE DTSTART > '20010601T000000Z' AND DTSTART < '20010901T000000Z'") + + store.select(gauge) + + count = 0 + + c = store.first_component() + while c != None: + print c.uid() + print c.dtstart() + print + count = count + 1 + c = store.next_component() + + store.clearSelect() + + assert(count == 3) + + # remove all of them + c = store.first_component() + while c != None: + print c.uid() + store.remove_component(c) + c = store.first_component() + + assert(store.count_components("VCALENDAR") == 0) + store.commit() + assert(store.count_components("VCALENDAR") == 0) + # print them out + # assert count of components = 0 + + +def test_store(): + print "------------ Store -----------------" + do_test_store(FileStore,"filesetout.ics") def run_tests(): test_property() @@ -366,6 +591,11 @@ def run_tests(): #test_attach() + test_gauge() + + test_store() + + if __name__ == "__main__": |