[CalendarServer-changes] [2853] CalDAVTester/branches/users/cdaboo/implicit-2661/verifiers/ calendarDataMatch.py
source_changes at macosforge.org
source_changes at macosforge.org
Sun Aug 24 19:22:35 PDT 2008
Revision: 2853
http://trac.macosforge.org/projects/calendarserver/changeset/2853
Author: cdaboo at apple.com
Date: 2008-08-24 19:22:35 -0700 (Sun, 24 Aug 2008)
Log Message:
-----------
Add a calendar data comparison that normalizes the calendar data into the vobject serialized
format so that comparisons work without having to have an exact octet match in the data file.
Added Paths:
-----------
CalDAVTester/branches/users/cdaboo/implicit-2661/verifiers/calendarDataMatch.py
Added: CalDAVTester/branches/users/cdaboo/implicit-2661/verifiers/calendarDataMatch.py
===================================================================
--- CalDAVTester/branches/users/cdaboo/implicit-2661/verifiers/calendarDataMatch.py (rev 0)
+++ CalDAVTester/branches/users/cdaboo/implicit-2661/verifiers/calendarDataMatch.py 2008-08-25 02:22:35 UTC (rev 2853)
@@ -0,0 +1,73 @@
+##
+# Copyright (c) 2006-2007 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# DRI: Cyrus Daboo, cdaboo at apple.com
+##
+from vobject.base import readOne
+from difflib import unified_diff
+import StringIO
+
+"""
+Verifier that checks the response body for an exact match to data in a file.
+"""
+
+class Verifier(object):
+
+ def verify(self, manager, uri, response, respdata, args): #@UnusedVariable
+ # Get arguments
+ files = args.get("filepath", [])
+
+ # status code must be 200, 207
+ if response.status not in (200,207):
+ return False, " HTTP Status Code Wrong: %d" % (response.status,)
+
+ # look for response data
+ if not respdata:
+ return False, " No response body"
+
+ # look for one file
+ if len(files) != 1:
+ return False, " No file to compare response to"
+
+ # read in all data from specified file
+ fd = open( files[0], "r" )
+ try:
+ try:
+ data = fd.read()
+ finally:
+ fd.close()
+ except:
+ data = None
+
+ if data is None:
+ return False, " Could not read data file"
+
+ data = manager.server_info.subs(data)
+
+ s = StringIO.StringIO(respdata)
+ resp_calendar = readOne(s)
+ respdata = resp_calendar.serialize()
+
+ s = StringIO.StringIO(data)
+ data_calendar = readOne(s)
+ data = data_calendar.serialize()
+
+ result = respdata == data
+
+ if result:
+ return True, ""
+ else:
+ print "\n".join([line for line in unified_diff(data.split("\n"), respdata.split("\n"))])
+ return False, " Response data does not exactly match file data"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080824/7123b88c/attachment-0001.html
More information about the calendarserver-changes
mailing list