[CalendarServer-changes] [15663] CalDAVTester/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu Jun 9 14:06:10 PDT 2016


Revision: 15663
          http://trac.calendarserver.org//changeset/15663
Author:   cdaboo at apple.com
Date:     2016-06-09 14:06:10 -0700 (Thu, 09 Jun 2016)
Log Message:
-----------
Display request/response if requested in the log observer. Provide a way to test for JSON null values.

Modified Paths:
--------------
    CalDAVTester/trunk/README.txt
    CalDAVTester/trunk/src/caldavtest.py
    CalDAVTester/trunk/src/observers/base.py
    CalDAVTester/trunk/src/observers/log.py
    CalDAVTester/trunk/verifiers/jsonPointerMatch.py

Modified: CalDAVTester/trunk/README.txt
===================================================================
--- CalDAVTester/trunk/README.txt	2016-06-09 20:52:09 UTC (rev 15662)
+++ CalDAVTester/trunk/README.txt	2016-06-09 21:06:10 UTC (rev 15663)
@@ -617,9 +617,9 @@
 	is a match, otherwise False.
 	The pointer is the absolute pointer from the root down. A JSON object's
 	string value can be checked by append "~$" and the string value to test
-	to the JSON pointer value. A single "." can be used as a reference-token
-	in the JSON pointer to match against any member or array item at that
-	position in the document.
+	to the JSON pointer value. To test for a null value append "~~". A single
+	"." can be used as a reference-token in the JSON pointer to match against
+	any member or array item at that position in the document.
 	
 	Argument: 'exists'
 		JSON pointer for a JSON item to check the presence of

Modified: CalDAVTester/trunk/src/caldavtest.py
===================================================================
--- CalDAVTester/trunk/src/caldavtest.py	2016-06-09 20:52:09 UTC (rev 15662)
+++ CalDAVTester/trunk/src/caldavtest.py	2016-06-09 21:06:10 UTC (rev 15663)
@@ -769,15 +769,17 @@
                 resulttxt += "Status Code Error: %d" % response.status
 
         if req.print_request or (self.manager.print_request_response_on_error and not result):
-            resulttxt += "\n-------BEGIN:REQUEST-------\n"
-            resulttxt += http.requestData
-            resulttxt += "\n--------END:REQUEST--------\n"
+            requesttxt = "\n-------BEGIN:REQUEST-------\n"
+            requesttxt += http.requestData
+            requesttxt += "\n--------END:REQUEST--------\n"
+            self.manager.message("protocol", requesttxt)
 
         if req.print_response or (self.manager.print_request_response_on_error and not result):
-            resulttxt += "\n-------BEGIN:RESPONSE-------\n"
-            resulttxt += "%s %s %s\n" % (getVersionStringFromResponse(response), response.status, response.reason,)
-            resulttxt += str(response.msg) + "\n" + respdata
-            resulttxt += "\n--------END:RESPONSE--------\n"
+            responsetxt = "\n-------BEGIN:RESPONSE-------\n"
+            responsetxt += "%s %s %s\n" % (getVersionStringFromResponse(response), response.status, response.reason,)
+            responsetxt += str(response.msg) + "\n" + respdata
+            responsetxt += "\n--------END:RESPONSE--------\n"
+            self.manager.message("protocol", responsetxt)
 
         if etags is not None and req.method == "GET":
             hdrs = response.msg.getheaders("Etag")

Modified: CalDAVTester/trunk/src/observers/base.py
===================================================================
--- CalDAVTester/trunk/src/observers/base.py	2016-06-09 20:52:09 UTC (rev 15662)
+++ CalDAVTester/trunk/src/observers/base.py	2016-06-09 21:06:10 UTC (rev 15663)
@@ -28,6 +28,7 @@
     testFile - add a test file
     testSuite - add a test suite
     testResult - add a test result
+    protocol - protocol log
     finish - tests completed
     """
 

Modified: CalDAVTester/trunk/src/observers/log.py
===================================================================
--- CalDAVTester/trunk/src/observers/log.py	2016-06-09 20:52:09 UTC (rev 15662)
+++ CalDAVTester/trunk/src/observers/log.py	2016-06-09 21:06:10 UTC (rev 15663)
@@ -36,6 +36,7 @@
         self.loggedFailures = []
         self.currentFile = None
         self.currentSuite = None
+        self.currentProtocol = []
 
 
     def updateCalls(self):
@@ -46,6 +47,7 @@
             "testFile": self.testFile,
             "testSuite": self.testSuite,
             "testResult": self.testResult,
+            "protocol": self.protocol,
             "finish": self.finish,
         })
 
@@ -101,7 +103,11 @@
             )
             self.loggedFailures.append(failtxt)
 
+        if self.currentProtocol:
+            self.manager.logit("\n".join(self.currentProtocol))
+            self.currentProtocol = []
 
+
     def _logResult(self, name, result):
         if result["result"] is not None:
             result_value = self.RESULT_STRINGS[result["result"]]
@@ -112,6 +118,10 @@
             self.manager.logit(result["details"])
 
 
+    def protocol(self, result):
+        self.currentProtocol.append(result)
+
+
     def finish(self):
         self.manager.logit("")
         if self.manager.totals[manager.RESULT_FAILED] + self.manager.totals[manager.RESULT_ERROR] != 0:

Modified: CalDAVTester/trunk/verifiers/jsonPointerMatch.py
===================================================================
--- CalDAVTester/trunk/verifiers/jsonPointerMatch.py	2016-06-09 20:52:09 UTC (rev 15662)
+++ CalDAVTester/trunk/verifiers/jsonPointerMatch.py	2016-06-09 21:06:10 UTC (rev 15663)
@@ -29,6 +29,13 @@
 
 class Verifier(object):
 
+    class JsonNull(object):
+        pass
+
+
+    null = JsonNull()
+
+
     def verify(self, manager, uri, response, respdata, args): #@UnusedVariable
         # Get arguments
         statusCodes = args.get("status", ["200", ])
@@ -65,6 +72,8 @@
         for jpath in exists:
             if jpath.find("~$") != -1:
                 path, value = jpath.split("~$")
+            elif jpath.find("~~") != -1:
+                path, value = jpath.split("~~")[0], self.null
             else:
                 path, value = jpath, None
             try:
@@ -78,7 +87,7 @@
                     if not jobjs:
                         result = False
                         resulttxt += "        Items not returned in JSON for %s\n" % (path,)
-                    if value and value not in map(str, jobjs):
+                    if value and value not in map(lambda x: self.null if x is None else str(x), jobjs):
                         result = False
                         resulttxt += "        Item values not returned in JSON for %s\n" % (jpath,)
                 except JSONPointerMatchError:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20160609/47d2db67/attachment-0001.html>


More information about the calendarserver-changes mailing list