summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-07-13 14:47:01 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-07-13 14:47:01 +0100
commitce7e7072857d3122c89de30543051ef3c5fad2e9 (patch)
treec1df52013b63247af419961169c0393203ddc7f7 /tests
parent01abb8447a1f52bbba181c2abacbe916d60b2793 (diff)
downloadpykolab-ce7e7072857d3122c89de30543051ef3c5fad2e9.tar.gz
Make sure timezone handling is implemented for start and end dates
Also, do not accidentally convert dates to datetimes
Diffstat (limited to 'tests')
-rw-r--r--tests/test-003-event.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/tests/test-003-event.py b/tests/test-003-event.py
index 031f4a1..c18523a 100644
--- a/tests/test-003-event.py
+++ b/tests/test-003-event.py
@@ -1,4 +1,6 @@
import datetime
+import pytz
+import sys
import unittest
from pykolab.xml import Attendee
@@ -14,7 +16,7 @@ class TestEventXML(unittest.TestCase):
self.assertRaises(EventIntegrityError, self.event.__str__)
def test_001_minimal(self):
- self.event.set_start(datetime.datetime.now())
+ self.event.set_start(datetime.datetime.now(pytz.timezone("Europe/London")))
self.assertIsInstance(self.event.get_start(), datetime.datetime)
self.assertIsInstance(self.event.__str__(), basestring)
@@ -73,5 +75,25 @@ class TestEventXML(unittest.TestCase):
self.event.delegate("jane@doe.org", "john@doe.org")
self.assertEqual(len(self.event.get_attendee("jane@doe.org").get_delegated_to()), 2)
+ def test_015_timezone(self):
+ _tz = self.event.get_start()
+ self.assertIsInstance(_tz.tzinfo, datetime.tzinfo)
+
+ def test_016_start_with_timezone(self):
+ _start = datetime.datetime(2012, 05, 23, 11, 58, 00, tzinfo=pytz.timezone("Europe/Zurich"))
+ _start_utc = _start.astimezone(pytz.utc)
+ self.assertEqual(_start.__str__(), "2012-05-23 11:58:00+01:00")
+ self.assertEqual(_start_utc.__str__(), "2012-05-23 10:58:00+00:00")
+ self.event.set_start(_start)
+ self.assertIsInstance(_start.tzinfo, datetime.tzinfo)
+ self.assertEqual(_start.tzinfo, pytz.timezone("Europe/Zurich"))
+
+ def test_017_allday_without_timezone(self):
+ _start = datetime.date(2012, 05, 23)
+ self.assertEqual(_start.__str__(), "2012-05-23")
+ self.event.set_start(_start)
+ self.assertEqual(hasattr(_start,'tzinfo'), False)
+ self.assertEqual(self.event.get_start().__str__(), "2012-05-23")
+
if __name__ == '__main__':
unittest.main()