Add ics_compare and use it in _testRespondTo()

This new class uses vobject.ics_diff() to compare 2 VCALENDAR components.
We should use this instead of textually comparing events for equality
in future tests.
This commit is contained in:
Jean Raby
2013-03-11 11:37:59 -04:00
parent d12c651d59
commit 63ff9751d7
2 changed files with 57 additions and 3 deletions
+4 -3
View File
@@ -681,9 +681,10 @@ class DAVCalendarAclTest(DAVAclTest):
"organizer_line": "ORGANIZER:mailto:someone@nowhere.com\n",
"attendee_line": att_line}
event = self._getEvent(event_class, True)
self.assertEquals(exp_event.strip(), event.strip(),
"'respond to' event does not match:\nreceived:\n"
"/%s/\nexpected:\n/%s/" % (event, exp_event))
ics_diff = utilities.ics_compare(exp_event, event)
self.assertTrue(ics_diff.areEqual(),
"'respond to' event does not match:\n"
"Diff(expected, got):\n %s" % ics_diff.textDiff())
class DAVAddressBookAclTest(DAVAclTest):
resource = '/SOGo/dav/%s/Contacts/test-dav-acl/' % username
+53
View File
@@ -1,9 +1,60 @@
#!/usr/bin/python
import StringIO
import sys
import unittest
import vobject
import vobject.ics_diff
import webdavlib
import xml.sax.saxutils
class ics_compare():
def __init__(self, event1, event2):
self.event1 = event1
self.event2 = event2
self.diffs = None
def _vcalendarComponent(self, event):
event_component = None
for item in vobject.readComponents(event):
if item.name == "VCALENDAR":
event_component = item
return event_component
def areEqual(self):
s_event1 = StringIO.StringIO(self.event1)
s_event2 = StringIO.StringIO(self.event2)
event1_vcalendar = self._vcalendarComponent(s_event1)
if event1_vcalendar is None:
raise Exception("No VCALENDAR component in event1")
event2_vcalendar = self._vcalendarComponent(s_event2)
if event2_vcalendar is None:
raise Exception("No VCALENDAR component in event2")
self.diffs = vobject.ics_diff.diff(event1_vcalendar, event2_vcalendar)
if not self.diffs:
return True
else:
return False
def textDiff(self):
saved_stdout = sys.stdout
out = StringIO.StringIO()
sys.stdout = out
try :
if self.diffs is not None:
for (left, right) in self.diffs:
left.prettyPrint()
right.prettyPrint()
finally:
sys.stdout = saved_stdout
return out.getvalue().strip()
class TestUtility():
def __init__(self, test, client, resource = None):
self.test = test
@@ -144,3 +195,5 @@ class TestAddressBookACLUtility(TestACLUtility):
sogoRights.append(sogoRightsTable[k])
return sogoRights