Author: reebalazs
Date: Fri Mar 28 19:05:49 2008
New Revision: 53060
Modified:
kukit/kss.demo/branch/1.4-kss-test/kss/demo/browser/registry.py
kukit/kss.demo/branch/1.4-kss-test/kss/demo/interfaces.py
kukit/kss.demo/branch/1.4-kss-test/kss/demo/registry.py
kukit/kss.demo/branch/1.4-kss-test/kss/demo/resource.py
Log:
Progress with extending selenium test registry
Modified: kukit/kss.demo/branch/1.4-kss-test/kss/demo/browser/registry.py
==============================================================================
--- kukit/kss.demo/branch/1.4-kss-test/kss/demo/browser/registry.py
(original)
+++ kukit/kss.demo/branch/1.4-kss-test/kss/demo/browser/registry.py Fri Mar
28 19:05:49 2008
@@ -14,6 +14,10 @@
class KSSDemoRegistryView(BrowserView):
+ # --
+ # handling the demos
+ # --
+
def getSortedDemos(self):
"""Get demos"""
registry = getUtility(IKSSDemoRegistry)
@@ -56,9 +60,32 @@
group.append(demo)
return demo_groups
+ # --
+ # handling the selenium tests
+ # --
+
+ def getSeleniumTests(self):
+ """Get selenium tests annotated with title and href."""
+ registry = getUtility(IKSSDemoRegistry)
+ results = []
+ for suite in registry.test_suites:
+ relative_urls = suite.get_relative_urls()
+ for relative_url in relative_urls:
+ results.append(dict(
+ href = relative_url,
+ title = self._url_to_title(relative_url),
+ ))
+ return results
+
@staticmethod
- def _filename_to_title(filename):
+ def _url_to_title(url):
"""Automatic conversion of filename to readable title"""
+ # we use the url's end after the last /, @ or *
+ split_here = max(url.rfind('/'), url.rfind('*'), url.rfind('+'))
+ if split_here != -1:
+ filename = url[split_here:]
+ else:
+ filename = url
if filename.lower().endswith('.html'):
filename = filename[:-5]
elif filename.lower().endswith('.htm'):
@@ -73,40 +100,16 @@
result = ' '.join([word.capitalize() for word in words])
return result
- @staticmethod
- def _filename_to_href(filename):
- """Automatic conversion of filename to publication href"""
- return "@@resource?filename=%s" % (filename, )
-
- def getSeleniumTests(self):
- """Get selenium tests annotated with title and href."""
- return [dict(
- href = self._filename_to_href(filename),
- title=self._filename_to_title(filename),
- )
- for filename in self.selenium_test_filenames]
-
- @property
- def selenium_test_filenames(self):
- """A cached representation of all filenames."""
- try:
- return self._cooked_selenium_test_filenames
- except AttributeError:
- registry = getUtility(IKSSDemoRegistry)
- self._cooked_selenium_test_filenames = filenames = \
- registry.selenium_tests
- return filenames
-
- def getSeleniumTestResource(self, filename):
+ def getSeleniumTestResource(self, path):
"""Return the html resource, whose absolute filename is given,"""
# First of all, let's check if this is one of our file.
# (Refuse otherwise - we don't want access to all files on the server.)
registry = getUtility(IKSSDemoRegistry)
- if filename not in registry.all_registered_filenames:
+ if path not in registry.all_registered_paths:
raise Exception, "Nonexistent resource"
# Return the file's content.
self.request.response.setHeader('Content-type',
'text/html;charset=utf-8')
- return file(filename).read()
+ return file(path).read()
def getZuiteHomePage(self, path):
"""Redirects to the Zuite home page, Zuite object is found from
path."""
Modified: kukit/kss.demo/branch/1.4-kss-test/kss/demo/interfaces.py
==============================================================================
--- kukit/kss.demo/branch/1.4-kss-test/kss/demo/interfaces.py (original)
+++ kukit/kss.demo/branch/1.4-kss-test/kss/demo/interfaces.py Fri Mar 28
19:05:49 2008
@@ -49,17 +49,21 @@
class IKSSSeleniumTestCaseCollection(Interface):
"""Abstract interface representing a set of testcases"""
- def get_filenames(plugin=None, test_root_dir=None):
- """Return the list of absolute filenames in this collection
- Each of this files are a .html format selenium test
-
- Either of plugin and test_root_dir must e specified.
- They are used to acquire the absolute path of the file
- which is acquired from the plugin resource's definition
- place or can be overwritten explicitely by test_root_dir.
+ def get_relative_urls():
+ """Return the list of relative urls in this collection
+ Each of theses urls will serve an .html format selenium
+ test case.
"""
-class IKSSSeleniumTestSuite(Interface):
+ def get_testcase_paths():
+ """Return the list of absolute testcase paths that this collection
+ uses.
+ This will be used in the @@resource?filename=.... view, to protect
+ serving anything else then in this list.
+ But, get_relative_urls will be used to create the test suite.
+ """
+
+class IKSSSeleniumTestSuite(IKSSSeleniumTestCaseCollection):
"""Represents an actual selenium test suite"""
tests = Object(IKSSSeleniumTestCaseCollection,
Modified: kukit/kss.demo/branch/1.4-kss-test/kss/demo/registry.py
==============================================================================
--- kukit/kss.demo/branch/1.4-kss-test/kss/demo/registry.py (original)
+++ kukit/kss.demo/branch/1.4-kss-test/kss/demo/registry.py Fri Mar 28
19:05:49 2008
@@ -46,9 +46,8 @@
site.registerHandler(self.unregisterDemosFromPlugin)
site.registerHandler(self.registerEarlierDemos)
# registry for selenium tests
- self.selenium_tests = []
self.test_suites = []
- self.all_registered_filenames = []
+ self.all_registered_paths = []
site.registerHandler(self.registerSeleniumTestSuitesFromPlugin)
site.registerHandler(self.unregisterSeleniumTestSuitesFromPlugin)
# ... the rest of setup will be done from registerEarlierDemos
@@ -165,17 +164,7 @@
"""Register a selenium suite."""
# Register the suite in different registries.
self.test_suites.append(test_suite)
- # Check if any of the filenames are registered elsewhere.
- # This also assures by the way, that suites cannot be duplicated.
- # The filenames are also used for
- test_filenames = test_suite.tests.get_filenames()
- for test_filename in test_filenames:
- if test_filename in self.selenium_tests:
- raise Exception, 'The selenium test file for %s has already
been registered. Cannot add.' % (test_filename, )
- self.selenium_tests.append(test_filename)
- # All registered filenames are used to protect the resource
- # and prevent a malicious attempt to serve something we should not.
- self.all_registered_filenames.append(test_filename)
+ self.all_registered_paths.extend(test_suite.tests.get_testcase_paths())
# XXX TODO need different other registries for lookup of categories.
def unregisterSeleniumTestSuite(self, test_suite):
Modified: kukit/kss.demo/branch/1.4-kss-test/kss/demo/resource.py
==============================================================================
--- kukit/kss.demo/branch/1.4-kss-test/kss/demo/resource.py (original)
+++ kukit/kss.demo/branch/1.4-kss-test/kss/demo/resource.py Fri Mar 28
19:05:49 2008
@@ -28,30 +28,6 @@
def __getitem__(self, key):
return getattr(self, key)
-class KSSSeleniumTestSuite(object):
- """Represents a single selenium test case,
- specified by its filename.
- """
- implements(IKSSSeleniumTestSuite)
-
- # convenience access for page templates
- __allow_access_to_unprotected_subobjects__ = 1
-
- tests = ()
- component = u''
- application = u''
- layer = None
-
- def __init__(self, tests=None, component=u'', application=u'', layer=None):
- if tests is not None:
- self.tests = tests
- if component:
- self.component = component
- if application:
- self.application = application
- if layer is not None:
- self.layer = layer
-
# --
# IKSSSeleniumTestCaseCollection implementations
# --
@@ -73,10 +49,13 @@
# store it
self.test_root_dir = getRootDirOfModule(locals['__module__'])
- def get_absolute_path(self, filename):
+ def find_absolute_path(self, filename):
"Returns the absolute path of the filename based on the test root
directory."
return os.path.join(self.test_root_dir, filename)
+ def make_relative_urls_from_paths(self, paths):
+ return ('@@resource?path=%s' % (path, ) for path in paths )
+
class KSSSeleniumTestCase(KSSSeleniumTestCaseCollectionBase):
"""Represents a single selenium test case,
specified by its filename.
@@ -87,10 +66,13 @@
self.find_test_root_dir()
self.test_filename = test_filename
- def get_filenames(self):
- test_filename = self.get_absolute_path(self.test_filename)
+ def get_testcase_paths(self):
+ test_filename = self.find_absolute_path(self.test_filename)
return [test_filename]
+ def get_relative_urls(self):
+ return self.make_relative_urls_from_paths(self.get_testcase_paths())
+
class KSSSeleniumTestDirectory(KSSSeleniumTestCaseCollectionBase):
"""Represents a selenium test directory.
It contains a set of tests.
@@ -101,9 +83,9 @@
self.find_test_root_dir()
self.test_directory = test_directory
- def get_filenames(self):
+ def get_testcase_paths(self):
test_filenames = []
- test_root_dir = self.get_absolute_path(self.test_directory)
+ test_root_dir = self.find_absolute_path(self.test_directory)
for test_filename in os.listdir(test_root_dir):
if test_filename.lower().endswith('.html') or \
test_filename.endswith('.htm'):
@@ -114,6 +96,9 @@
test_filenames = (filename[1] for filename in test_filenames)
return test_filenames
+ def get_relative_urls(self):
+ return self.make_relative_urls_from_paths(self.get_testcase_paths())
+
class KSSSeleniumTestCaseList(KSSSeleniumTestCaseCollectionBase):
"""Recursively collects a list of collectiors.
"""
@@ -123,5 +108,66 @@
self.find_test_root_dir()
self.cases = cases
- def get_filenames(self):
- return itertools.chain(*[case.get_filenames() for case in self.cases])
+ def get_testcase_paths(self):
+ return itertools.chain(*[case.get_testcase_paths() for case in
self.cases])
+
+ def get_relative_urls(self):
+ return itertools.chain(*[case.get_relative_urls() for case in
self.cases])
+
+class KSSSeleniumEmptyTestCase(KSSSeleniumTestCaseCollectionBase):
+ """An empty test case."""
+ implements(IKSSSeleniumTestCaseCollection)
+
+ def get_testcase_paths(self):
+ return ()
+
+ def get_relative_urls(self):
+ return ()
+
+# --
+# The Suite itself is a collection, but provides a way to use layers with
setup and
+# tesrdown from the registry.
+# --
+
+class KSSSeleniumTestLayerBase(object):
+ setup = KSSSeleniumEmptyTestCase()
+ teardown = KSSSeleniumEmptyTestCase()
+
+class KSSSeleniumTestSuite(object):
+ """Represents a single selenium test case,
+ specified by its filename.
+ """
+ implements(IKSSSeleniumTestSuite)
+
+ # convenience access for page templates
+ __allow_access_to_unprotected_subobjects__ = 1
+
+ tests = ()
+ component = u''
+ application = u''
+ # default is an empty layer.
+ layer = KSSSeleniumTestLayerBase
+
+ def __init__(self, tests=None, component=u'', application=u'', layer=None):
+ if tests is not None:
+ self.tests = tests
+ if component:
+ self.component = component
+ if application:
+ self.application = application
+ if layer is not None:
+ self.layer = layer
+
+ def get_testcase_paths(self):
+ return itertools.chain(
+ self.layer.setup.get_testcase_paths(),
+ self.tests.get_testcase_paths(),
+ self.layer.teardown.get_testcase_paths()
+ )
+
+ def get_relative_urls(self):
+ return itertools.chain(
+ self.layer.setup.get_relative_urls(),
+ self.tests.get_relative_urls(),
+ self.layer.teardown.get_relative_urls()
+ )
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins