[CalendarServer-changes] [7671] CalDAVTester/trunk/src

source_changes at macosforge.org source_changes at macosforge.org
Mon Jun 27 09:08:46 PDT 2011


Revision: 7671
          http://trac.macosforge.org/projects/calendarserver/changeset/7671
Author:   cdaboo at apple.com
Date:     2011-06-27 09:08:45 -0700 (Mon, 27 Jun 2011)
Log Message:
-----------
Add option to print request details. Add option to print request and response on failure.

Modified Paths:
--------------
    CalDAVTester/trunk/src/caldavtest.py
    CalDAVTester/trunk/src/manager.py
    CalDAVTester/trunk/src/request.py
    CalDAVTester/trunk/src/xmlDefs.py

Modified: CalDAVTester/trunk/src/caldavtest.py
===================================================================
--- CalDAVTester/trunk/src/caldavtest.py	2011-06-25 00:52:56 UTC (rev 7670)
+++ CalDAVTester/trunk/src/caldavtest.py	2011-06-27 16:08:45 UTC (rev 7671)
@@ -1,5 +1,5 @@
 ##
-# Copyright (c) 2006-2010 Apple Inc. All rights reserved.
+# Copyright (c) 2006-2011 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.
@@ -27,6 +27,7 @@
 from src.testsuite import testsuite
 from xml.etree.ElementTree import ElementTree, tostring
 import commands
+import httplib
 import os
 import rfc822
 import socket
@@ -36,6 +37,31 @@
 
 STATUSTXT_WIDTH    = 60
 
+"""
+Patch the HTTPConnection.send to record full request details
+"""
+    
+httplib.HTTPConnection._send = httplib.HTTPConnection.send
+
+def recordRequestHeaders(self, str):
+    if not hasattr(self, "requestData"):
+        self.requestData = ""
+    self.requestData += str
+    httplib.HTTPConnection._send(self, str) #@UndefinedVariable
+
+httplib.HTTPConnection.send = recordRequestHeaders
+
+def getVersionStringFromResponse(response):
+    
+    if response.version == 9:
+        return "HTTP/0.9"
+    elif response.version == 10:
+        return "HTTP/1.0"
+    elif response.version == 11:
+        return "HTTP/1.1"
+    else:
+        return "HTTP/?.?"
+
 class caldavtest(object):
     
     def __init__( self, manager, name ):
@@ -527,9 +553,14 @@
             if not result:
                 resulttxt += "Status Code Error: %d" % response.status
         
-        if req.print_response:
+        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"
+        
+        if req.print_response or (self.manager.print_request_response_on_error and not result):
             resulttxt += "\n-------BEGIN:RESPONSE-------\n"
-            resulttxt += "Status = %d\n" % response.status
+            resulttxt += "%s %s %s\n" % (getVersionStringFromResponse(response), response.status, response.reason,)
             resulttxt += str(response.msg) + "\n" + respdata
             resulttxt += "\n--------END:RESPONSE--------\n"
         

Modified: CalDAVTester/trunk/src/manager.py
===================================================================
--- CalDAVTester/trunk/src/manager.py	2011-06-25 00:52:56 UTC (rev 7670)
+++ CalDAVTester/trunk/src/manager.py	2011-06-27 16:08:45 UTC (rev 7671)
@@ -1,5 +1,5 @@
 ##
-# Copyright (c) 2006-2010 Apple Inc. All rights reserved.
+# Copyright (c) 2006-2011 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.
@@ -56,6 +56,9 @@
         self.logFile = log_file
         self.digestCache = {}
         self.postgresLog = ""
+        self.print_request = False
+        self.print_response = False
+        self.print_request_response_on_error = False
     
     def log(self, level, str, indent = 0, indentStr = " ", after = 1, before = 0):
         if self.textMode and level <= self.logLevel:
@@ -127,7 +130,22 @@
         pidfile = "../CalendarServer/logs/caldavd.pid"
         random_order = False
         random_seed = str(random.randint(0, 1000000))
-        options, args = getopt.getopt(sys.argv[1:], "s:mx:", ["all", "subdir=", "exclude=", "pid=", "postgres-log=", "random", "random-seed="])
+        options, args = getopt.getopt(
+            sys.argv[1:],
+            "s:mx:",
+            [
+                "all",
+                "subdir=",
+                "exclude=",
+                "pid=",
+                "postgres-log=",
+                "random",
+                "random-seed=",
+                "print-details-onfail",
+                "always-print-request",
+                "always-print-response",
+            ],
+        )
         
         # Process single options
         for option, value in options:
@@ -147,6 +165,12 @@
                 pidfile = value
             elif option == "--postgres-log":
                 self.postgresLog = value
+            elif option == "--print-details-onfail":
+                self.print_request_response_on_error = True
+            elif option == "--always-print-request":
+                self.print_request = True
+            elif option == "--always-print-response":
+                self.print_response = True
             elif option == "--random":
                 random_order = True
             elif option == "--random-seed":

Modified: CalDAVTester/trunk/src/request.py
===================================================================
--- CalDAVTester/trunk/src/request.py	2011-06-25 00:52:56 UTC (rev 7670)
+++ CalDAVTester/trunk/src/request.py	2011-06-27 16:08:45 UTC (rev 7671)
@@ -1,5 +1,5 @@
 ##
-# Copyright (c) 2006-2010 Apple Inc. All rights reserved.
+# Copyright (c) 2006-2011 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.
@@ -139,6 +139,7 @@
         self.user = ""
         self.pswd = ""
         self.end_delete = False
+        self.print_request = False
         self.print_response = False
         self.require_features = set()
         self.exclude_features = set()
@@ -305,7 +306,8 @@
         self.user = self.manager.server_info.subs(node.get(src.xmlDefs.ATTR_USER, "").encode("utf-8"))
         self.pswd = self.manager.server_info.subs(node.get(src.xmlDefs.ATTR_PSWD, "").encode("utf-8"))
         self.end_delete = getYesNoAttributeValue(node, src.xmlDefs.ATTR_END_DELETE)
-        self.print_response = getYesNoAttributeValue(node, src.xmlDefs.ATTR_PRINT_RESPONSE)
+        self.print_request = self.manager.print_request or getYesNoAttributeValue(node, src.xmlDefs.ATTR_PRINT_REQUEST)
+        self.print_response = self.manager.print_response or getYesNoAttributeValue(node, src.xmlDefs.ATTR_PRINT_RESPONSE)
 
         for child in node.getchildren():
             if child.tag == src.xmlDefs.ELEMENT_REQUIRE_FEATURE:

Modified: CalDAVTester/trunk/src/xmlDefs.py
===================================================================
--- CalDAVTester/trunk/src/xmlDefs.py	2011-06-25 00:52:56 UTC (rev 7670)
+++ CalDAVTester/trunk/src/xmlDefs.py	2011-06-27 16:08:45 UTC (rev 7671)
@@ -1,5 +1,5 @@
 ##
-# Copyright (c) 2006-2010 Apple Inc. All rights reserved.
+# Copyright (c) 2006-2011 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.
@@ -81,6 +81,7 @@
 ATTR_IGNORE_ALL = "ignore-all"
 ATTR_INTERVAL = "interval"
 ATTR_NAME = "name"
+ATTR_PRINT_REQUEST = "print-request"
 ATTR_PRINT_RESPONSE = "print-response"
 ATTR_PSWD = "pswd"
 ATTR_REQUEST_FAILED = "request-failed"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110627/28bcf392/attachment.html>


More information about the calendarserver-changes mailing list