[CalendarServer-changes] [14201] CalDAVTester/trunk

source_changes at macosforge.org source_changes at macosforge.org
Mon Dec 8 11:33:43 PST 2014


Revision: 14201
          http://trac.calendarserver.org//changeset/14201
Author:   cdaboo at apple.com
Date:     2014-12-08 11:33:43 -0800 (Mon, 08 Dec 2014)
Log Message:
-----------
Add an option for programmatic generation of request data using pluggable modules.

Modified Paths:
--------------
    CalDAVTester/trunk/scripts/tests/CalDAV/caldavtest.dtd
    CalDAVTester/trunk/scripts/tests/CardDAV/caldavtest.dtd
    CalDAVTester/trunk/scripts/tests-pod/CalDAV/caldavtest.dtd
    CalDAVTester/trunk/src/manager.py
    CalDAVTester/trunk/src/request.py
    CalDAVTester/trunk/src/xmlDefs.py

Added Paths:
-----------
    CalDAVTester/trunk/generators/
    CalDAVTester/trunk/generators/__init__.py
    CalDAVTester/trunk/generators/example.py

Added: CalDAVTester/trunk/generators/__init__.py
===================================================================
--- CalDAVTester/trunk/generators/__init__.py	                        (rev 0)
+++ CalDAVTester/trunk/generators/__init__.py	2014-12-08 19:33:43 UTC (rev 14201)
@@ -0,0 +1,19 @@
+##
+# Copyright (c) 2014 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.
+##
+
+__all__ = [
+    "example",
+]

Added: CalDAVTester/trunk/generators/example.py
===================================================================
--- CalDAVTester/trunk/generators/example.py	                        (rev 0)
+++ CalDAVTester/trunk/generators/example.py	2014-12-08 19:33:43 UTC (rev 14201)
@@ -0,0 +1,29 @@
+##
+# Copyright (c) 2006-2013 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.
+##
+
+"""
+Example generator api.
+"""
+
+class Generator(object):
+
+    def generate(self, manager, args): #@UnusedVariable
+
+        # Extract args needed by the generator: args = {name: [values]}
+
+        # Generate the appropriate data and return it
+
+        return ""

Modified: CalDAVTester/trunk/scripts/tests/CalDAV/caldavtest.dtd
===================================================================
--- CalDAVTester/trunk/scripts/tests/CalDAV/caldavtest.dtd	2014-12-05 20:50:55 UTC (rev 14200)
+++ CalDAVTester/trunk/scripts/tests/CalDAV/caldavtest.dtd	2014-12-08 19:33:43 UTC (rev 14201)
@@ -46,11 +46,12 @@
 		<!ELEMENT header (name, value)>
 			<!ELEMENT name (#PCDATA)>
 			<!ELEMENT value (#PCDATA)>
-		<!ELEMENT data (content-type, filepath, substitute*)>
+		<!ELEMENT data (content-type, (filepath | generator), substitute*)>
 			<!ATTLIST data substitutions (yes|no) "yes"
 			               generate      (yes|no) "no">
 			<!ELEMENT content-type (#PCDATA)>
 			<!ELEMENT filepath (#PCDATA)>
+			<!ELEMENT generator (callback, arg*)>
 			<!ELEMENT substitute (name, value)>
 
 		<!ELEMENT verify (require-feature?, exclude-feature?, callback, arg*)>

Modified: CalDAVTester/trunk/scripts/tests/CardDAV/caldavtest.dtd
===================================================================
--- CalDAVTester/trunk/scripts/tests/CardDAV/caldavtest.dtd	2014-12-05 20:50:55 UTC (rev 14200)
+++ CalDAVTester/trunk/scripts/tests/CardDAV/caldavtest.dtd	2014-12-08 19:33:43 UTC (rev 14201)
@@ -46,11 +46,12 @@
 		<!ELEMENT header (name, value)>
 			<!ELEMENT name (#PCDATA)>
 			<!ELEMENT value (#PCDATA)>
-		<!ELEMENT data (content-type, filepath, substitute*)>
+		<!ELEMENT data (content-type, (filepath | generator), substitute*)>
 			<!ATTLIST data substitutions (yes|no) "yes"
 			               generate      (yes|no) "no">
 			<!ELEMENT content-type (#PCDATA)>
 			<!ELEMENT filepath (#PCDATA)>
+			<!ELEMENT generator (callback, arg*)>
 			<!ELEMENT substitute (name, value)>
 
 		<!ELEMENT verify (require-feature?, exclude-feature?, callback, arg*)>

Modified: CalDAVTester/trunk/scripts/tests-pod/CalDAV/caldavtest.dtd
===================================================================
--- CalDAVTester/trunk/scripts/tests-pod/CalDAV/caldavtest.dtd	2014-12-05 20:50:55 UTC (rev 14200)
+++ CalDAVTester/trunk/scripts/tests-pod/CalDAV/caldavtest.dtd	2014-12-08 19:33:43 UTC (rev 14201)
@@ -46,11 +46,12 @@
 		<!ELEMENT header (name, value)>
 			<!ELEMENT name (#PCDATA)>
 			<!ELEMENT value (#PCDATA)>
-		<!ELEMENT data (content-type, filepath, substitute*)>
+		<!ELEMENT data (content-type, (filepath | generator), substitute*)>
 			<!ATTLIST data substitutions (yes|no) "yes"
 			               generate      (yes|no) "no">
 			<!ELEMENT content-type (#PCDATA)>
 			<!ELEMENT filepath (#PCDATA)>
+			<!ELEMENT generator (callback, arg*)>
 			<!ELEMENT substitute (name, value)>
 
 		<!ELEMENT verify (require-feature?, exclude-feature?, callback, arg*)>

Modified: CalDAVTester/trunk/src/manager.py
===================================================================
--- CalDAVTester/trunk/src/manager.py	2014-12-05 20:50:55 UTC (rev 14200)
+++ CalDAVTester/trunk/src/manager.py	2014-12-08 19:33:43 UTC (rev 14201)
@@ -261,6 +261,10 @@
                 sname = os.path.join(basedir, "serverinfo.xml")
                 dname = os.path.join(basedir, "tests")
                 self.data_dir = os.path.join(basedir, "data")
+
+                # Also add parent to PYTHON path
+                sys.path.append(os.path.dirname(basedir))
+
             elif option == "--subdir":
                 subdir = value + "/"
             elif option == "--exclude":
@@ -425,3 +429,7 @@
         lines = data.split("\n")
         procdata = lines[1].split()
         return int(procdata[6]), int(procdata[7])
+
+
+    def getDataPath(self, fpath):
+        return os.path.join(self.data_dir, fpath) if self.data_dir else fpath

Modified: CalDAVTester/trunk/src/request.py
===================================================================
--- CalDAVTester/trunk/src/request.py	2014-12-05 20:50:55 UTC (rev 14200)
+++ CalDAVTester/trunk/src/request.py	2014-12-08 19:33:43 UTC (rev 14201)
@@ -300,7 +300,7 @@
         if self.data != None:
             if len(self.data.value) != 0:
                 data = self.data.value
-            else:
+            elif self.data.filepath:
                 # read in the file data
                 fd = open(self.data.nextpath if hasattr(self.data, "nextpath") else self.getFilePath(), "r")
                 try:
@@ -315,6 +315,8 @@
             if self.data.generate:
                 if self.data.content_type.startswith("text/calendar"):
                     data = self.generateCalendarData(data)
+            elif self.data.generator:
+                data = self.data.generator.doGenerate()
         return data
 
 
@@ -483,6 +485,7 @@
         self.manager = manager
         self.content_type = ""
         self.filepath = ""
+        self.generator = None
         self.value = ""
         self.substitutions = {}
         self.substitute = False
@@ -499,6 +502,9 @@
                 self.content_type = child.text.encode("utf-8")
             elif child.tag == src.xmlDefs.ELEMENT_FILEPATH:
                 self.filepath = child.text.encode("utf-8")
+            elif child.tag == src.xmlDefs.ELEMENT_GENERATOR:
+                self.generator = generator(self.manager)
+                self.generator.parseXML(child)
             elif child.tag == src.xmlDefs.ELEMENT_SUBSTITUTE:
                 self.parseSubstituteXML(child)
 
@@ -516,6 +522,67 @@
 
 
 
+class generator(object):
+    """
+    Defines a dynamically generated request body.
+    """
+
+    def __init__(self, manager):
+        self.manager = manager
+        self.callback = None
+        self.args = {}
+
+
+    def doGenerate(self):
+
+        # Re-do substitutions from values generated during the current test run
+        if self.manager.server_info.hasextrasubs():
+            for name, values in self.args.iteritems():
+                newvalues = [self.manager.server_info.extrasubs(value) for value in values]
+                self.args[name] = newvalues
+
+        generatorClass = self._importName(self.callback, "Generator")
+        gen = generatorClass()
+
+        # Always clone the args as this verifier may be called multiple times
+        args = dict((k, list(v)) for k, v in self.args.items())
+
+        return gen.generate(self.manager, args)
+
+
+    def _importName(self, modulename, name):
+        """
+        Import a named object from a module in the context of this function.
+        """
+        module = __import__(modulename, globals(), locals(), [name])
+        return getattr(module, name)
+
+
+    def parseXML(self, node):
+
+        for child in node.getchildren():
+            if child.tag == src.xmlDefs.ELEMENT_CALLBACK:
+                self.callback = child.text.encode("utf-8")
+            elif child.tag == src.xmlDefs.ELEMENT_ARG:
+                self.parseArgXML(child)
+
+
+    def parseArgXML(self, node):
+        name = None
+        values = []
+        for child in node.getchildren():
+            if child.tag == src.xmlDefs.ELEMENT_NAME:
+                name = child.text.encode("utf-8")
+            elif child.tag == src.xmlDefs.ELEMENT_VALUE:
+                if child.text is not None:
+                    values.append(self.manager.server_info.subs(child.text.encode("utf-8")))
+                else:
+                    values.append("")
+        if name:
+            self.args[name] = values
+
+
+
 class verify(object):
     """
     Defines how the result of a request should be verified. This is done

Modified: CalDAVTester/trunk/src/xmlDefs.py
===================================================================
--- CalDAVTester/trunk/src/xmlDefs.py	2014-12-05 20:50:55 UTC (rev 14200)
+++ CalDAVTester/trunk/src/xmlDefs.py	2014-12-08 19:33:43 UTC (rev 14201)
@@ -30,6 +30,7 @@
 ELEMENT_FEATURES = "features"
 ELEMENT_FEATURE = "feature"
 ELEMENT_FILEPATH = "filepath"
+ELEMENT_GENERATOR = "generator"
 ELEMENT_GRABCALPROP = "grabcalproperty"
 ELEMENT_GRABCALPARAM = "grabcalparameter"
 ELEMENT_GRABCOUNT = "grabcount"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20141208/97738253/attachment-0001.html>


More information about the calendarserver-changes mailing list