[KSS-checkins] r53380 - in kukit/kss.demo/branch/1.4-kss-test/kss/demo: . tests
reebalazs at codespeak.net
reebalazs at codespeak.net
Sat Apr 5 12:02:52 CEST 2008
Author: reebalazs
Date: Sat Apr 5 12:02:49 2008
New Revision: 53380
Added:
kukit/kss.demo/branch/1.4-kss-test/kss/demo/selenium_testcases.txt (contents, props changed)
Modified:
kukit/kss.demo/branch/1.4-kss-test/kss/demo/selenium_suites.txt
kukit/kss.demo/branch/1.4-kss-test/kss/demo/tests/test_doc.py
Log:
And add more tests.
Modified: kukit/kss.demo/branch/1.4-kss-test/kss/demo/selenium_suites.txt
==============================================================================
--- kukit/kss.demo/branch/1.4-kss-test/kss/demo/selenium_suites.txt (original)
+++ kukit/kss.demo/branch/1.4-kss-test/kss/demo/selenium_suites.txt Sat Apr 5 12:02:49 2008
@@ -178,3 +178,42 @@
More testing of the layers can be found in the selenium_layers.txt file.
+Filtering of testcases
+----------------------
+
+Test suites can be given a ``component`` and ``application`` property. They are
+both strings.
+
+``component`` should be the dotted component name of the owner of this test.
+For example, ``plone.app.fancylib`` or ``kss.plugins.superplugin``.
+
+``application`` identified the application that tests for the usage of this
+component. For example, ``Plone``. This is usually a bigger category then the
+component, as an application consists of many components.
+
+If the application property is not specified, this means that the test does not
+belong to a specific application, so it is either a kss core or a
+plugin test.
+
+Filtering at the moment is only implemented by the ``application`` property.
+This means all the tests of an application can be executed together.
+
+ >>> class Plugin6(object):
+ ...
+ ... selenium_tests = (
+ ... KSSSeleniumTestSuite(
+ ... tests = KSSSeleniumTestCase('6a'),
+ ... component = 'kss.plugins.superplugin',
+ ... ),
+ ... KSSSeleniumTestSuite(
+ ... tests = KSSSeleniumTestCase('6b'),
+ ... component = 'plone.app.fancylib',
+ ... application = 'Plone',
+ ... ),
+ ... )
+
+The filtering is done from the resource registry. How the test sequence is
+actually constructed from a selection of suites, is demonstrated in the
+``selenium_layers.txt`` document.
+
+
Added: kukit/kss.demo/branch/1.4-kss-test/kss/demo/selenium_testcases.txt
==============================================================================
--- (empty file)
+++ kukit/kss.demo/branch/1.4-kss-test/kss/demo/selenium_testcases.txt Sat Apr 5 12:02:49 2008
@@ -0,0 +1,238 @@
+
+===================
+Selenium test cases
+===================
+
+Selenium test cases in kss.demo are defined by "test collections".
+A collection selects a number of tests. This is why they are called collections,
+although in reality they are testcases which however can be constructed
+from other collections.
+
+There are two methods that every collection has, and they are executed
+during the creation of the test suite.
+
+Every collection implements an ``get_resolve_urls``. This returns
+an iterator that yields a list of relative test urls. If resolved,
+they should render a selenium test case in html format. The order
+of the resources specifies their execution order. The method
+needs to be called with the rendering view as a parameter.
+
+In addition, they also implement a ``get_testcase_paths`` method.
+This, unlike the previous one, returns an iterator to a list of
+absolute filenames. The order of these is not important. It must
+contain all the filenames that the collection wants to publish
+via the ``@@resource?path=...`` view provided by kss.demo. So,
+each item in this list corresponds to an item in the ``get_resolve_urls``
+results.
+
+New collection types can be implemented by classes, as long as they
+implement the ``ISeleniumTestCollection`` interface, in the way specified
+below. kss.demo supplies the following collection types, that
+allow to specify a set of testcases in a flexible way.
+
+
+Creation of testcase collections
+--------------------------------
+
+The collections use implicit magic (the same one used by the
+Zope CA for the ``implements``) to locate the directory of the
+python file that instantiates the collection. This allows that
+filenames that are used as parameters, will be expanded to their
+absolute class automatically. If we create a collection in itself,
+we will get an error:
+
+ >>> from kss.demo import KSSSeleniumTestCase
+
+ >>> tests = KSSSeleniumTestCase('my_testcase.html')
+ Traceback (most recent call last):
+ ...
+ TypeError: The <class 'kss.demo.resource.KSSSeleniumTestCase'> suite class can be used only from inside a class definition.
+
+ The correct way is to use it from inside a class definition. This way
+ the html file will be located relative to this directory:
+
+ >>> from kss.demo import KSSSeleniumTestSuite
+
+ >>> class Plugin(object):
+ ...
+ ... selenium_tests = (
+ ... KSSSeleniumTestSuite(
+ ... tests = KSSSeleniumTestCase('my_testcase.html'),
+ ... ),
+ ... )
+
+
+Test cases by filename
+----------------------
+
+This collection will contain a single test that we specify by filepath.
+The path will be applied relatively to the directory where the file
+containing the instantiation resides.
+
+ >>> class Suite:
+ ... tests = KSSSeleniumTestCase('my_testcase.html')
+ >>> case1 = Suite.tests
+
+The ``get_relative_url`` will only return a single resource url:
+
+ >>> tuple(case1.get_relative_urls(None))
+ ('@@resource?path=...my_testcase.html',)
+
+Note that we gave ``None`` as a parameter. This should be normally
+the view that does the rendering, needed to be passed to each collection.
+We will see a case later when this will be important.
+
+The ``get_testcase_paths`` method also just returns a single absolute
+filepath. (In the case of the test they will really not be absolute,
+because the locator magic does not work well with doctests.)
+
+ >>> tuple(case1.get_testcase_paths())
+ ('...my_testcase.html',)
+
+
+Test cases by directory
+-----------------------
+
+This is the usual way of working with tests. We specify a directory,
+and every ``*.html`` file in that directory is picked into the testcase
+collection.
+
+ >>> from kss.demo import KSSSeleniumTestDirectory
+
+ >>> class Suite2:
+ ... tests = KSSSeleniumTestDirectory('selenium_tests')
+ >>> case2 = Suite2.tests
+
+ We don't have this directory here. So in both cases we get an error.
+
+ >>> tuple(case2.get_relative_urls(None))
+ Traceback (most recent call last):
+ ...
+ OSError: [Errno 2] No such file or directory: 'selenium_tests'
+
+ >>> tuple(case2.get_testcase_paths())
+ Traceback (most recent call last):
+ ...
+ OSError: [Errno 2] No such file or directory: 'selenium_tests'
+
+ For the sake of the test, we will find a testcase directory
+ from kss.core. Note this would not be needed from real code,
+ you'd just need to use the directory name.
+
+ >>> import sys, os.path, kss.core.plugins.core.demo
+ >>> rootdir = os.path.dirname(sys.modules['kss.core.plugins.core.demo'].__file__)
+ >>> dirpath = os.path.join(rootdir, 'selenium_tests')
+
+ >>> class Suite2:
+ ... tests = KSSSeleniumTestDirectory(dirpath)
+ >>> case2 = Suite2.tests
+
+ There are many tests in this list. (These are the tests for the kss core plugin.)
+
+ >>> tuple(case2.get_relative_urls(None))
+ ('@@resource?path=...0_ecmaunit_tests.html', ...)
+
+ >>> tuple(case2.get_testcase_paths())
+ ('...0_ecmaunit_tests.html', ...)
+
+
+Empty test cases
+----------------
+
+These are used for default values.
+
+ >>> from kss.demo import KSSSeleniumEmptyTestCase
+
+ >>> class Suite3:
+ ... tests = KSSSeleniumEmptyTestCase()
+ >>> case3 = Suite3.tests
+
+ >>> tuple(case3.get_relative_urls(None))
+ ()
+
+ >>> tuple(case3.get_testcase_paths())
+ ()
+
+
+Test case lists
+---------------
+
+These can be used to compose collections from other collections.
+
+ >>> from kss.demo import KSSSeleniumTestCaseList
+
+ >>> class Suite4:
+ ... tests = KSSSeleniumTestCaseList(
+ ... KSSSeleniumTestCase('testcase1.html'),
+ ... KSSSeleniumTestCase('testcase2.html'),
+ ... )
+ >>> case4 = Suite4.tests
+
+ >>> tuple(case4.get_relative_urls(None))
+ ('@@resource?path=...testcase1.html', '@@resource?path=...testcase2.html')
+
+ >>> tuple(case4.get_testcase_paths())
+ ('...testcase1.html', '...testcase2.html')
+
+Of course, they can also resurse.
+
+ >>> class Suite5:
+ ... tests = KSSSeleniumTestCaseList(
+ ... KSSSeleniumTestCase('testcase1.html'),
+ ... KSSSeleniumTestCaseList(
+ ... KSSSeleniumTestCase('testcase2.html'),
+ ... KSSSeleniumTestCase('testcase3.html'),
+ ... ),
+ ... )
+ >>> case5 = Suite5.tests
+
+ >>> tuple(case5.get_relative_urls(None))
+ ('@@resource?path=...testcase1.html', '@@resource?path=...testcase2.html', '@@resource?path=...testcase3.html')
+
+ >>> tuple(case5.get_testcase_paths())
+ ('...testcase1.html', '...testcase2.html', '...testcase3.html')
+
+
+Support for sandbox creation
+----------------------------
+
+A more special testcase is used to create a sandbox (a site with some content, or
+some initial data that each tests need). This test suite
+will be rendered by the browser view and take parameters. These are used as
+credentials for the content creation (as normal login to Zope could not be used
+from the setup), and to specify the url of the view that will carry out the
+creation.
+
+For this test, we will need a real (although fake) view.
+
+ >>> class FakeRequest(object):
+ ... admin_username = 'admin'
+ ... admin_password = 'admin'
+ ... def get(self, key, default=None):
+ ... return getattr(self, key, default)
+ >>> class FakeView(object):
+ ... content = None
+ ... request = FakeRequest()
+ >>> fake_view = FakeView()
+
+ >>> from kss.demo import KSSSeleniumSandboxCreationTestCase
+
+ >>> class Suite6:
+ ... tests = KSSSeleniumSandboxCreationTestCase('@@kss_create_my_sandbox')
+ >>> case6 = Suite6.tests
+
+ >>> tuple(case6.get_relative_urls(fake_view))
+ ('@@kss-selenium-create-sandbox-test.html?method_name=@@kss_create_my_sandbox&admin_username=admin&admin_password=admin',)
+
+This view will generate a testcase which is an informational form with a button. If
+this button is pressed, the view specified with ``method_name`` will be executed.
+This will receive the credentials, and it will check them against the Zope
+authentication information, before acting as Administrator.
+
+The collection does not return paths, since it does not use the ```@@resource?path=...```
+view.
+
+ >>> tuple(case6.get_testcase_paths())
+ ()
+
+
Modified: kukit/kss.demo/branch/1.4-kss-test/kss/demo/tests/test_doc.py
==============================================================================
--- kukit/kss.demo/branch/1.4-kss-test/kss/demo/tests/test_doc.py (original)
+++ kukit/kss.demo/branch/1.4-kss-test/kss/demo/tests/test_doc.py Sat Apr 5 12:02:49 2008
@@ -21,6 +21,10 @@
def test_suite():
return unittest.TestSuite((
+ DocFileSuite('selenium_testcases.txt',
+ package = 'kss.demo',
+ optionflags = doctest.ELLIPSIS,
+ ),
DocFileSuite('selenium_layers.txt',
package = 'kss.demo',
optionflags = doctest.ELLIPSIS,
More information about the Kukit-checkins
mailing list