Skip to content
Permalink
Browse files

Display request/response if requested in the log observer. Provide a …

…way to test for JSON null values.

git-svn-id: https://svn.calendarserver.org/repository/calendarserver/CalDAVTester/trunk@15663 e27351fd-9f3e-4f54-a53b-843176b1656c
  • Loading branch information
cyrusdaboo committed Jun 9, 2016
1 parent efb9600 commit 4129fef01e2e3f1542bc6d4d3b73ed876fb35847
Showing with 33 additions and 11 deletions.
  1. +3 −3 README.txt
  2. +9 −7 src/caldavtest.py
  3. +1 −0 src/observers/base.py
  4. +10 −0 src/observers/log.py
  5. +10 −1 verifiers/jsonPointerMatch.py
@@ -617,9 +617,9 @@ jsonPointerMatch:
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
@@ -769,15 +769,17 @@ def dorequest(self, req, details=False, doverify=True, forceverify=False, stats=
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")
@@ -28,6 +28,7 @@ class BaseResultsObserver(object):
testFile - add a test file
testSuite - add a test suite
testResult - add a test result
protocol - protocol log
finish - tests completed
"""

@@ -36,6 +36,7 @@ def __init__(self, manager):
self.loggedFailures = []
self.currentFile = None
self.currentSuite = None
self.currentProtocol = []


def updateCalls(self):
@@ -46,6 +47,7 @@ def updateCalls(self):
"testFile": self.testFile,
"testSuite": self.testSuite,
"testResult": self.testResult,
"protocol": self.protocol,
"finish": self.finish,
})

@@ -101,6 +103,10 @@ def testResult(self, result):
)
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:
@@ -112,6 +118,10 @@ def _logResult(self, name, result):
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:
@@ -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 @@ def _splitPathTests(path):
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 @@ def _splitPathTests(path):
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:

0 comments on commit 4129fef

Please sign in to comment.
You can’t perform that action at this time.