<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[14201] CalDAVTester/trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/14201">14201</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2014-12-08 11:33:43 -0800 (Mon, 08 Dec 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add an option for programmatic generation of request data using pluggable modules.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalDAVTestertrunkscriptstestsCalDAVcaldavtestdtd">CalDAVTester/trunk/scripts/tests/CalDAV/caldavtest.dtd</a></li>
<li><a href="#CalDAVTestertrunkscriptstestsCardDAVcaldavtestdtd">CalDAVTester/trunk/scripts/tests/CardDAV/caldavtest.dtd</a></li>
<li><a href="#CalDAVTestertrunkscriptstestspodCalDAVcaldavtestdtd">CalDAVTester/trunk/scripts/tests-pod/CalDAV/caldavtest.dtd</a></li>
<li><a href="#CalDAVTestertrunksrcmanagerpy">CalDAVTester/trunk/src/manager.py</a></li>
<li><a href="#CalDAVTestertrunksrcrequestpy">CalDAVTester/trunk/src/request.py</a></li>
<li><a href="#CalDAVTestertrunksrcxmlDefspy">CalDAVTester/trunk/src/xmlDefs.py</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li>CalDAVTester/trunk/generators/</li>
<li><a href="#CalDAVTestertrunkgenerators__init__py">CalDAVTester/trunk/generators/__init__.py</a></li>
<li><a href="#CalDAVTestertrunkgeneratorsexamplepy">CalDAVTester/trunk/generators/example.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalDAVTestertrunkgenerators__init__py"></a>
<div class="addfile"><h4>Added: CalDAVTester/trunk/generators/__init__.py (0 => 14201)</h4>
<pre class="diff"><span>
<span class="info">--- CalDAVTester/trunk/generators/__init__.py                                (rev 0)
+++ CalDAVTester/trunk/generators/__init__.py        2014-12-08 19:33:43 UTC (rev 14201)
</span><span class="lines">@@ -0,0 +1,19 @@
</span><ins>+##
+# Copyright (c) 2014 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
+# 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 &quot;AS IS&quot; 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__ = [
+    &quot;example&quot;,
+]
</ins></span></pre></div>
<a id="CalDAVTestertrunkgeneratorsexamplepy"></a>
<div class="addfile"><h4>Added: CalDAVTester/trunk/generators/example.py (0 => 14201)</h4>
<pre class="diff"><span>
<span class="info">--- CalDAVTester/trunk/generators/example.py                                (rev 0)
+++ CalDAVTester/trunk/generators/example.py        2014-12-08 19:33:43 UTC (rev 14201)
</span><span class="lines">@@ -0,0 +1,29 @@
</span><ins>+##
+# Copyright (c) 2006-2013 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
+# 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 &quot;AS IS&quot; 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.
+##
+
+&quot;&quot;&quot;
+Example generator api.
+&quot;&quot;&quot;
+
+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 &quot;&quot;
</ins></span></pre></div>
<a id="CalDAVTestertrunkscriptstestsCalDAVcaldavtestdtd"></a>
<div class="modfile"><h4>Modified: CalDAVTester/trunk/scripts/tests/CalDAV/caldavtest.dtd (14200 => 14201)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -46,11 +46,12 @@
</span><span class="cx">                 &lt;!ELEMENT header (name, value)&gt;
</span><span class="cx">                         &lt;!ELEMENT name (#PCDATA)&gt;
</span><span class="cx">                         &lt;!ELEMENT value (#PCDATA)&gt;
</span><del>-                &lt;!ELEMENT data (content-type, filepath, substitute*)&gt;
</del><ins>+                &lt;!ELEMENT data (content-type, (filepath | generator), substitute*)&gt;
</ins><span class="cx">                         &lt;!ATTLIST data substitutions (yes|no) &quot;yes&quot;
</span><span class="cx">                                        generate      (yes|no) &quot;no&quot;&gt;
</span><span class="cx">                         &lt;!ELEMENT content-type (#PCDATA)&gt;
</span><span class="cx">                         &lt;!ELEMENT filepath (#PCDATA)&gt;
</span><ins>+                        &lt;!ELEMENT generator (callback, arg*)&gt;
</ins><span class="cx">                         &lt;!ELEMENT substitute (name, value)&gt;
</span><span class="cx"> 
</span><span class="cx">                 &lt;!ELEMENT verify (require-feature?, exclude-feature?, callback, arg*)&gt;
</span></span></pre></div>
<a id="CalDAVTestertrunkscriptstestsCardDAVcaldavtestdtd"></a>
<div class="modfile"><h4>Modified: CalDAVTester/trunk/scripts/tests/CardDAV/caldavtest.dtd (14200 => 14201)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -46,11 +46,12 @@
</span><span class="cx">                 &lt;!ELEMENT header (name, value)&gt;
</span><span class="cx">                         &lt;!ELEMENT name (#PCDATA)&gt;
</span><span class="cx">                         &lt;!ELEMENT value (#PCDATA)&gt;
</span><del>-                &lt;!ELEMENT data (content-type, filepath, substitute*)&gt;
</del><ins>+                &lt;!ELEMENT data (content-type, (filepath | generator), substitute*)&gt;
</ins><span class="cx">                         &lt;!ATTLIST data substitutions (yes|no) &quot;yes&quot;
</span><span class="cx">                                        generate      (yes|no) &quot;no&quot;&gt;
</span><span class="cx">                         &lt;!ELEMENT content-type (#PCDATA)&gt;
</span><span class="cx">                         &lt;!ELEMENT filepath (#PCDATA)&gt;
</span><ins>+                        &lt;!ELEMENT generator (callback, arg*)&gt;
</ins><span class="cx">                         &lt;!ELEMENT substitute (name, value)&gt;
</span><span class="cx"> 
</span><span class="cx">                 &lt;!ELEMENT verify (require-feature?, exclude-feature?, callback, arg*)&gt;
</span></span></pre></div>
<a id="CalDAVTestertrunkscriptstestspodCalDAVcaldavtestdtd"></a>
<div class="modfile"><h4>Modified: CalDAVTester/trunk/scripts/tests-pod/CalDAV/caldavtest.dtd (14200 => 14201)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -46,11 +46,12 @@
</span><span class="cx">                 &lt;!ELEMENT header (name, value)&gt;
</span><span class="cx">                         &lt;!ELEMENT name (#PCDATA)&gt;
</span><span class="cx">                         &lt;!ELEMENT value (#PCDATA)&gt;
</span><del>-                &lt;!ELEMENT data (content-type, filepath, substitute*)&gt;
</del><ins>+                &lt;!ELEMENT data (content-type, (filepath | generator), substitute*)&gt;
</ins><span class="cx">                         &lt;!ATTLIST data substitutions (yes|no) &quot;yes&quot;
</span><span class="cx">                                        generate      (yes|no) &quot;no&quot;&gt;
</span><span class="cx">                         &lt;!ELEMENT content-type (#PCDATA)&gt;
</span><span class="cx">                         &lt;!ELEMENT filepath (#PCDATA)&gt;
</span><ins>+                        &lt;!ELEMENT generator (callback, arg*)&gt;
</ins><span class="cx">                         &lt;!ELEMENT substitute (name, value)&gt;
</span><span class="cx"> 
</span><span class="cx">                 &lt;!ELEMENT verify (require-feature?, exclude-feature?, callback, arg*)&gt;
</span></span></pre></div>
<a id="CalDAVTestertrunksrcmanagerpy"></a>
<div class="modfile"><h4>Modified: CalDAVTester/trunk/src/manager.py (14200 => 14201)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -261,6 +261,10 @@
</span><span class="cx">                 sname = os.path.join(basedir, &quot;serverinfo.xml&quot;)
</span><span class="cx">                 dname = os.path.join(basedir, &quot;tests&quot;)
</span><span class="cx">                 self.data_dir = os.path.join(basedir, &quot;data&quot;)
</span><ins>+
+                # Also add parent to PYTHON path
+                sys.path.append(os.path.dirname(basedir))
+
</ins><span class="cx">             elif option == &quot;--subdir&quot;:
</span><span class="cx">                 subdir = value + &quot;/&quot;
</span><span class="cx">             elif option == &quot;--exclude&quot;:
</span><span class="lines">@@ -425,3 +429,7 @@
</span><span class="cx">         lines = data.split(&quot;\n&quot;)
</span><span class="cx">         procdata = lines[1].split()
</span><span class="cx">         return int(procdata[6]), int(procdata[7])
</span><ins>+
+
+    def getDataPath(self, fpath):
+        return os.path.join(self.data_dir, fpath) if self.data_dir else fpath
</ins></span></pre></div>
<a id="CalDAVTestertrunksrcrequestpy"></a>
<div class="modfile"><h4>Modified: CalDAVTester/trunk/src/request.py (14200 => 14201)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -300,7 +300,7 @@
</span><span class="cx">         if self.data != None:
</span><span class="cx">             if len(self.data.value) != 0:
</span><span class="cx">                 data = self.data.value
</span><del>-            else:
</del><ins>+            elif self.data.filepath:
</ins><span class="cx">                 # read in the file data
</span><span class="cx">                 fd = open(self.data.nextpath if hasattr(self.data, &quot;nextpath&quot;) else self.getFilePath(), &quot;r&quot;)
</span><span class="cx">                 try:
</span><span class="lines">@@ -315,6 +315,8 @@
</span><span class="cx">             if self.data.generate:
</span><span class="cx">                 if self.data.content_type.startswith(&quot;text/calendar&quot;):
</span><span class="cx">                     data = self.generateCalendarData(data)
</span><ins>+            elif self.data.generator:
+                data = self.data.generator.doGenerate()
</ins><span class="cx">         return data
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -483,6 +485,7 @@
</span><span class="cx">         self.manager = manager
</span><span class="cx">         self.content_type = &quot;&quot;
</span><span class="cx">         self.filepath = &quot;&quot;
</span><ins>+        self.generator = None
</ins><span class="cx">         self.value = &quot;&quot;
</span><span class="cx">         self.substitutions = {}
</span><span class="cx">         self.substitute = False
</span><span class="lines">@@ -499,6 +502,9 @@
</span><span class="cx">                 self.content_type = child.text.encode(&quot;utf-8&quot;)
</span><span class="cx">             elif child.tag == src.xmlDefs.ELEMENT_FILEPATH:
</span><span class="cx">                 self.filepath = child.text.encode(&quot;utf-8&quot;)
</span><ins>+            elif child.tag == src.xmlDefs.ELEMENT_GENERATOR:
+                self.generator = generator(self.manager)
+                self.generator.parseXML(child)
</ins><span class="cx">             elif child.tag == src.xmlDefs.ELEMENT_SUBSTITUTE:
</span><span class="cx">                 self.parseSubstituteXML(child)
</span><span class="cx"> 
</span><span class="lines">@@ -516,6 +522,67 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+class generator(object):
+    &quot;&quot;&quot;
+    Defines a dynamically generated request body.
+    &quot;&quot;&quot;
+
+    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, &quot;Generator&quot;)
+        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):
+        &quot;&quot;&quot;
+        Import a named object from a module in the context of this function.
+        &quot;&quot;&quot;
+        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(&quot;utf-8&quot;)
+            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(&quot;utf-8&quot;)
+            elif child.tag == src.xmlDefs.ELEMENT_VALUE:
+                if child.text is not None:
+                    values.append(self.manager.server_info.subs(child.text.encode(&quot;utf-8&quot;)))
+                else:
+                    values.append(&quot;&quot;)
+        if name:
+            self.args[name] = values
+
+
+
</ins><span class="cx"> class verify(object):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Defines how the result of a request should be verified. This is done
</span></span></pre></div>
<a id="CalDAVTestertrunksrcxmlDefspy"></a>
<div class="modfile"><h4>Modified: CalDAVTester/trunk/src/xmlDefs.py (14200 => 14201)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -30,6 +30,7 @@
</span><span class="cx"> ELEMENT_FEATURES = &quot;features&quot;
</span><span class="cx"> ELEMENT_FEATURE = &quot;feature&quot;
</span><span class="cx"> ELEMENT_FILEPATH = &quot;filepath&quot;
</span><ins>+ELEMENT_GENERATOR = &quot;generator&quot;
</ins><span class="cx"> ELEMENT_GRABCALPROP = &quot;grabcalproperty&quot;
</span><span class="cx"> ELEMENT_GRABCALPARAM = &quot;grabcalparameter&quot;
</span><span class="cx"> ELEMENT_GRABCOUNT = &quot;grabcount&quot;
</span></span></pre>
</div>
</div>

</body>
</html>