[CalendarServer-changes] [13618] CalDAVTester/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Mon Jun 9 09:03:30 PDT 2014
Revision: 13618
http://trac.calendarserver.org//changeset/13618
Author: cdaboo at apple.com
Date: 2014-06-09 09:03:29 -0700 (Mon, 09 Jun 2014)
Log Message:
-----------
Add the ability to have a set of tests always run before and/or after every regular test (useful for verifying tests have cleaned up after themselves).
Modified Paths:
--------------
CalDAVTester/trunk/src/manager.py
CalDAVTester/trunk/src/request.py
CalDAVTester/trunk/verifiers/multistatusItems.py
Added Paths:
-----------
CalDAVTester/trunk/scripts/tests/CalDAV/pretest.xml
Added: CalDAVTester/trunk/scripts/tests/CalDAV/pretest.xml
===================================================================
--- CalDAVTester/trunk/scripts/tests/CalDAV/pretest.xml (rev 0)
+++ CalDAVTester/trunk/scripts/tests/CalDAV/pretest.xml 2014-06-09 16:03:29 UTC (rev 13618)
@@ -0,0 +1,165 @@
+<?xml version="1.0" standalone="no"?>
+
+<!DOCTYPE caldavtest SYSTEM "caldavtest.dtd">
+
+<!--
+ 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.
+ -->
+
+<caldavtest ignore-all="yes">
+ <require-feature>
+ <feature>caldav</feature>
+ </require-feature>
+
+ <start/>
+
+ <test-suite name='User calendars and inboxes are empty'>
+ <test name='1'>
+ <description>PROPFIND of basic properties depth=0</description>
+ <request>
+ <method>PROPFIND</method>
+ <ruri>$calendarpath1:/</ruri>
+ <header>
+ <name>Depth</name>
+ <value>1</value>
+ </header>
+ <data>
+ <content-type>text/xml; charset=utf-8</content-type>
+ <filepath>Resource/Common/PROPFIND/count.xml</filepath>
+ </data>
+ <verify>
+ <callback>multistatusItems</callback>
+ <arg>
+ <name>count</name>
+ <value>0</value>
+ </arg>
+ </verify>
+ </request>
+ </test>
+ <test name='1'>
+ <description>PROPFIND of basic properties depth=0</description>
+ <request>
+ <method>PROPFIND</method>
+ <ruri>$inboxpath1:/</ruri>
+ <header>
+ <name>Depth</name>
+ <value>1</value>
+ </header>
+ <data>
+ <content-type>text/xml; charset=utf-8</content-type>
+ <filepath>Resource/Common/PROPFIND/count.xml</filepath>
+ </data>
+ <verify>
+ <callback>multistatusItems</callback>
+ <arg>
+ <name>count</name>
+ <value>0</value>
+ </arg>
+ </verify>
+ </request>
+ </test>
+ <test name='3'>
+ <description>PROPFIND of basic properties depth=0</description>
+ <request user="$userid2:" pswd="$pswd2:">
+ <method>PROPFIND</method>
+ <ruri>$calendarpath2:/</ruri>
+ <header>
+ <name>Depth</name>
+ <value>1</value>
+ </header>
+ <data>
+ <content-type>text/xml; charset=utf-8</content-type>
+ <filepath>Resource/Common/PROPFIND/count.xml</filepath>
+ </data>
+ <verify>
+ <callback>multistatusItems</callback>
+ <arg>
+ <name>count</name>
+ <value>0</value>
+ </arg>
+ </verify>
+ </request>
+ </test>
+ <test name='4'>
+ <description>PROPFIND of basic properties depth=0</description>
+ <request user="$userid2:" pswd="$pswd2:">
+ <method>PROPFIND</method>
+ <ruri>$inboxpath2:/</ruri>
+ <header>
+ <name>Depth</name>
+ <value>1</value>
+ </header>
+ <data>
+ <content-type>text/xml; charset=utf-8</content-type>
+ <filepath>Resource/Common/PROPFIND/count.xml</filepath>
+ </data>
+ <verify>
+ <callback>multistatusItems</callback>
+ <arg>
+ <name>count</name>
+ <value>0</value>
+ </arg>
+ </verify>
+ </request>
+ </test>
+ <test name='5'>
+ <description>PROPFIND of basic properties depth=0</description>
+ <request user="$userid3:" pswd="$pswd3:">
+ <method>PROPFIND</method>
+ <ruri>$calendarpath3:/</ruri>
+ <header>
+ <name>Depth</name>
+ <value>1</value>
+ </header>
+ <data>
+ <content-type>text/xml; charset=utf-8</content-type>
+ <filepath>Resource/Common/PROPFIND/count.xml</filepath>
+ </data>
+ <verify>
+ <callback>multistatusItems</callback>
+ <arg>
+ <name>count</name>
+ <value>0</value>
+ </arg>
+ </verify>
+ </request>
+ </test>
+ <test name='6'>
+ <description>PROPFIND of basic properties depth=0</description>
+ <request user="$userid3:" pswd="$pswd3:">
+ <method>PROPFIND</method>
+ <ruri>$inboxpath3:/</ruri>
+ <header>
+ <name>Depth</name>
+ <value>1</value>
+ </header>
+ <data>
+ <content-type>text/xml; charset=utf-8</content-type>
+ <filepath>Resource/Common/PROPFIND/count.xml</filepath>
+ </data>
+ <verify>
+ <callback>multistatusItems</callback>
+ <arg>
+ <name>count</name>
+ <value>0</value>
+ </arg>
+ </verify>
+ </request>
+ </test>
+ </test-suite>
+
+ <end/>
+
+</caldavtest>
Modified: CalDAVTester/trunk/src/manager.py
===================================================================
--- CalDAVTester/trunk/src/manager.py 2014-06-09 15:07:45 UTC (rev 13617)
+++ CalDAVTester/trunk/src/manager.py 2014-06-09 16:03:29 UTC (rev 13618)
@@ -48,6 +48,8 @@
def __init__(self, text=True):
self.server_info = serverinfo()
+ self.pretest = None
+ self.posttest = None
self.tests = []
self.textMode = text
self.pid = 0
@@ -162,33 +164,45 @@
self.server_info.addsubs(moresubs)
- for ctr, testfile in enumerate(testfiles):
- self.message("load", testfile, ctr + 1, len(testfiles))
-
+ from src.caldavtest import caldavtest
+ def _loadFile(fname, ignore_root=True):
# Open and parse the config file
try:
- tree = ElementTree(file=testfile)
+ tree = ElementTree(file=fname)
except ExpatError, e:
- raise RuntimeError("Unable to parse file '%s' because: %s" % (testfile, e,))
-
- # Verify that top-level element is correct
- from src.caldavtest import caldavtest
+ raise RuntimeError("Unable to parse file '%s' because: %s" % (fname, e,))
caldavtest_node = tree.getroot()
if caldavtest_node.tag != src.xmlDefs.ELEMENT_CALDAVTEST:
- self.message("trace", "Ignoring file \"{}\" because it is not a test file".format(testfile))
- continue
+ if ignore_root:
+ self.message("trace", "Ignoring file \"{}\" because it is not a test file".format(fname))
+ return None
+ else:
+ raise EX_INVALID_CONFIG_FILE
if not len(caldavtest_node):
raise EX_INVALID_CONFIG_FILE
- self.message("Reading Test Details from \"{}\"".format(testfile))
- # parse all the config data
- test = caldavtest(self, testfile)
+ self.message("Reading Test Details from \"{}\"".format(fname))
+ test = caldavtest(self, fname)
test.parseXML(caldavtest_node)
+ return test
+ for ctr, testfile in enumerate(testfiles):
+ self.message("load", testfile, ctr + 1, len(testfiles))
+
+ # Open and parse the config file
+ test = _loadFile(testfile)
+ if test is None:
+ continue
+
# ignore if all mode and ignore-all is set
if not all or not test.ignore_all:
self.tests.append(test)
+ if self.pretest is not None:
+ self.pretest = _loadFile(self.pretest, False)
+ if self.posttest is not None:
+ self.posttest = _loadFile(self.posttest, False)
+
self.message("load", None, ctr + 1, len(testfiles))
@@ -213,6 +227,8 @@
"all",
"subdir=",
"exclude=",
+ "pretest=",
+ "posttest=",
"observer=",
"pid=",
"postgres-log=",
@@ -239,6 +255,10 @@
subdir = value + "/"
elif option == "--exclude":
excludes.add(value)
+ elif option == "--pretest":
+ self.pretest = value
+ elif option == "--posttest":
+ self.posttest = value
elif option == "-m":
self.memUsage = True
elif option == "-o":
@@ -273,8 +293,7 @@
# Remove any server info file from files enumerated by --all
fnames[:] = [x for x in fnames if (x != sname)]
- # Process any file arguments as test configs
- for f in args:
+ def _normPath(f):
# paths starting with . or .. or /
if f[0] in ('.', '/'):
f = os.path.abspath(f)
@@ -287,8 +306,17 @@
# relative paths
else:
f = os.path.join(dname, f)
- fnames.append(f)
+ return f
+ # Process any file arguments as test configs
+ for f in args:
+ fnames.append(_normPath(f))
+
+ if self.pretest is not None:
+ self.pretest = _normPath(self.pretest)
+ if self.posttest is not None:
+ self.posttest = _normPath(self.posttest)
+
# Randomize file list
if random_order and len(fnames) > 1:
random.seed(random_seed)
@@ -317,6 +345,16 @@
ignored = 0
try:
for test in self.tests:
+ if self.pretest is not None:
+ o, f, i = self.pretest.run()
+ ok += o
+ failed += f
+ ignored += i
+
+ # Always stop the tests if the pretest fails
+ if failed != 0:
+ break
+
o, f, i = test.run()
ok += o
failed += f
@@ -324,6 +362,17 @@
if failed != 0 and self.stoponfail:
break
+
+ if self.posttest is not None:
+ o, f, i = self.posttest.run()
+ ok += o
+ failed += f
+ ignored += i
+
+ # Always stop the tests if the posttest fails
+ if failed != 0:
+ break
+
except:
failed += 1
import traceback
Modified: CalDAVTester/trunk/src/request.py
===================================================================
--- CalDAVTester/trunk/src/request.py 2014-06-09 15:07:45 UTC (rev 13617)
+++ CalDAVTester/trunk/src/request.py 2014-06-09 16:03:29 UTC (rev 13618)
@@ -519,9 +519,13 @@
verifierClass = self._importName("verifiers." + self.callback, "Verifier")
verifier = verifierClass()
- return verifier.verify(self.manager, uri, response, respdata, self.args)
+ # 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 verifier.verify(self.manager, uri, response, respdata, args)
+
+
def _importName(self, modulename, name):
"""
Import a named object from a module in the context of this function.
Modified: CalDAVTester/trunk/verifiers/multistatusItems.py
===================================================================
--- CalDAVTester/trunk/verifiers/multistatusItems.py 2014-06-09 15:07:45 UTC (rev 13617)
+++ CalDAVTester/trunk/verifiers/multistatusItems.py 2014-06-09 16:03:29 UTC (rev 13618)
@@ -50,9 +50,6 @@
okhrefs = [(prefix + i).rstrip("/") for i in okhrefs]
nohrefs = [(prefix + i).rstrip("/") for i in nohrefs]
badhrefs = [(prefix + i).rstrip("/") for i in badhrefs]
- for k, v in args.items():
- v = [prefix + i for i in v]
- args[k] = v
count = [int(eval(i)) for i in count]
totalcount = [int(eval(i)) for i in totalcount]
responsecount = [int(eval(i)) for i in responsecount]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140609/8f5240f9/attachment-0001.html>
More information about the calendarserver-changes
mailing list