From 9afaff4af42fe6f08762908a67a06a3225db7227 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Tue, 13 Jul 2010 17:36:32 +0000 Subject: [PATCH] Monotone-Parent: e9d4010d6c952c0aa503fa4571a589fb91c356b5 Monotone-Revision: b6518b59a7eb387bb26b065aa4b947048534a96a Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-07-13T17:36:32 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 6 ++ Tests/Integration/config.py.in | 2 + Tests/Integration/ev_generator.py | 92 +++++++++++++++++++++++++++++++ Tests/Integration/test-put.py | 42 ++++++++++++++ 4 files changed, 142 insertions(+) create mode 100644 Tests/Integration/ev_generator.py create mode 100755 Tests/Integration/test-put.py diff --git a/ChangeLog b/ChangeLog index bb194c3b6..90d56719c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2010-07-13 Wolfgang Sourdeau + * Tests/Integration/test-put.py: new test module executing X puts + based on a number of auto-generated events configured in config.py + + * Tests/Integration/ev_generator.py: new module producing + auto-generated events based on a number of days + * Tests/Integration/sogotests.py: new module overriding certain methods from the "unittest" module in order to automatically execute the tests in verbose mode and by displaying diff --git a/Tests/Integration/config.py.in b/Tests/Integration/config.py.in index 4924ecf90..c3c4a0a35 100644 --- a/Tests/Integration/config.py.in +++ b/Tests/Integration/config.py.in @@ -13,3 +13,5 @@ attendee1 = "user@domain.com" attendee1_delegate = "otheruser@domain.com" mailserver = "imaphost" + +testput_nbrdays = 30 diff --git a/Tests/Integration/ev_generator.py b/Tests/Integration/ev_generator.py new file mode 100644 index 000000000..c12dadb24 --- /dev/null +++ b/Tests/Integration/ev_generator.py @@ -0,0 +1,92 @@ +import time + +def hours(nbr): + return nbr * 3600 + +def days(nbr): + return nbr * hours(24) + +class ev_generator: + ev_templ = """ +BEGIN:VCALENDAR\r +VERSION:2.0\r +PRODID:-//Inverse//Event Generator//EN\r +CALSCALE:GREGORIAN\r +BEGIN:VTIMEZONE\r +TZID:America/Montreal\r +BEGIN:DAYLIGHT\r +TZOFFSETFROM:-0500\r +TZOFFSETTO:-0400\r +DTSTART:20070311T020000\r +RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU\r +TZNAME:EDT\r +END:DAYLIGHT\r +BEGIN:STANDARD\r +TZOFFSETFROM:-0400\r +TZOFFSETTO:-0500\r +DTSTART:20071104T020000\r +RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU\r +TZNAME:EST\r +END:STANDARD\r +END:VTIMEZONE\r +BEGIN:VEVENT\r +SEQUENCE:4\r +TRANSP:OPAQUE\r +UID:%(uid)s\r +SUMMARY:%(summary)s\r +DTSTART;TZID=America/Montreal:%(start)s\r +DTEND;TZID=America/Montreal:%(end)s\r +CREATED:20080711T231608Z\r +DTSTAMP:20080711T231640Z\r +END:VEVENT\r +END:VCALENDAR\r +""" + def __init__(self, maxDays): + self.reset(maxDays) + + def reset(self, maxDays): + self.maxDays = maxDays + self.currentDay = 0 + self.currentStart = 0 + today = time.mktime(time.localtime()) + self.firstDay = today - days(maxDays + 30) + + def _calendarDate(self, eventTime): + timeStruct = time.localtime(eventTime) + return time.strftime("%Y%m%dT%H0000", timeStruct) + + def _iterValues(self): + event = None + + if (self.currentDay < self.maxDays): + eventStart = (self.firstDay + + days(self.currentDay) + + hours(self.currentStart + 8)) + eventEnd = eventStart + hours(1) + + thatDay = time.localtime(int(eventStart)) + uid = "Event%d%d" % (eventStart, eventEnd) + summary = "%s - event %d" % (time.strftime("%Y-%m-%d", thatDay), + self.currentStart) + start = self._calendarDate(eventStart) + end = self._calendarDate(eventEnd) + event = {'uid': uid, + 'summary': summary, + 'start': start, + 'end': end} + + self.currentStart = self.currentStart + 1 + if (self.currentStart > 7): + self.currentStart = 0 + self.currentDay = self.currentDay + 1 + + return event + + def iter(self): + hasMore = False + entryValues = self._iterValues() + if (entryValues is not None): + self.event = (self.ev_templ % entryValues).strip() + hasMore = True + + return hasMore diff --git a/Tests/Integration/test-put.py b/Tests/Integration/test-put.py new file mode 100755 index 000000000..3737d4fed --- /dev/null +++ b/Tests/Integration/test-put.py @@ -0,0 +1,42 @@ +#!/usr/bin/python + +from config import hostname, port, username, password, testput_nbrdays + +import ev_generator +import sogotests +import unittest +import webdavlib + +class HTTPUnparsedURLTest(unittest.TestCase): + def __init__(self, arg): + unittest.TestCase.__init__(self, arg) + self.client = webdavlib.WebDAVClient(hostname, port, + username, password) + + def setUp(self): + self.resource = '/SOGo/dav/%s/Calendar/test-dav-put/' % username + delete = webdavlib.WebDAVDELETE(self.resource) + self.client.execute(delete) + mkcol = webdavlib.WebDAVMKCOL(self.resource) + self.client.execute(mkcol) + self.assertEquals(mkcol.response["status"], 201, + "preparation: failure creating collection" + "(code = %d)" % mkcol.response["status"]) + + def testPUT(self): + gen = ev_generator.ev_generator(testput_nbrdays) + counter = 1 + while gen.iter(): + event = gen.event + url = self.resource + "event-%d.ics" % counter + put = webdavlib.HTTPPUT(url, event) + put.content_type = "text/calendar; charset=utf-8" + self.client.execute(put) + counter = counter + 1 + + def tearDown(self): + delete = webdavlib.WebDAVDELETE(self.resource) + self.client.execute(delete) + +if __name__ == "__main__": + sogotests.runTests()