[Checkins] SVN: gocept.selenium/branches/jw-staticfiles-testlayer/s add test layer and testcase baseclass for testing static files with selenium

Jan-Wijbrand Kolman janwijbrand at gmail.com
Thu Jun 3 08:38:46 EDT 2010


Log message for revision 112999:
  add test layer and testcase baseclass for testing static files with selenium

Changed:
  A   gocept.selenium/branches/jw-staticfiles-testlayer/src/gocept/selenium/static/
  A   gocept.selenium/branches/jw-staticfiles-testlayer/src/gocept/selenium/static/__init__.py
  A   gocept.selenium/branches/jw-staticfiles-testlayer/src/gocept/selenium/static/tests/
  D   gocept.selenium/branches/jw-staticfiles-testlayer/src/gocept/selenium/static/tests/ftesting.zcml
  D   gocept.selenium/branches/jw-staticfiles-testlayer/src/gocept/selenium/static/tests/test_selenese.py
  A   gocept.selenium/branches/jw-staticfiles-testlayer/src/gocept/selenium/static/tests/test_static.py
  D   gocept.selenium/branches/jw-staticfiles-testlayer/src/gocept/selenium/static/tests/test_ztk.py
  A   gocept.selenium/branches/jw-staticfiles-testlayer/static.cfg

-=-
Added: gocept.selenium/branches/jw-staticfiles-testlayer/src/gocept/selenium/static/__init__.py
===================================================================
--- gocept.selenium/branches/jw-staticfiles-testlayer/src/gocept/selenium/static/__init__.py	                        (rev 0)
+++ gocept.selenium/branches/jw-staticfiles-testlayer/src/gocept/selenium/static/__init__.py	2010-06-03 12:38:45 UTC (rev 112999)
@@ -0,0 +1,73 @@
+#############################################################################
+#
+# Copyright (c) 2009 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+import os
+import shutil
+import signal
+import subprocess
+import sys
+import tempfile
+import time
+import unittest
+
+import gocept.selenium.base
+
+class StaticFilesLayer(gocept.selenium.base.Layer):
+
+    host = 'localhost'
+    port = 5698
+
+    def setUp(self):
+        super(StaticFilesLayer, self).setUp()
+        self.server = None
+        self.documentroot = tempfile.mkdtemp(suffix='tha.selenium.staticfiles')
+        self.start_server()
+
+    def start_server(self):
+        cmd = [sys.executable, '-m', 'SimpleHTTPServer', str(self.port)]
+        self.server = subprocess.Popen(cmd, cwd=self.documentroot)
+        # Wait a little as it sometimes takes a while to
+        # get the server started.
+        time.sleep(0.25)
+
+    def stop_server(self):
+        if self.server is None:
+            return
+        try:
+            # Kill the previously started SimpleHTTPServer process.
+            os.kill(self.server.pid, signal.SIGKILL)
+            self.server = None
+        except OSError, e:
+            print 'Could not kill process, do so manually. Reason:\n' + str(e)
+
+    def tearDown(self):
+        # Clean up after our behinds.
+        self.stop_server()
+        shutil.rmtree(self.documentroot)
+
+    def switch_db(self):
+        # Part of the gocept.selenium test layer contract. We use the
+        # hook to clear out all the files from the documentroot.
+        shutil.rmtree(self.documentroot)
+        self.documentroot = tempfile.mkdtemp(suffix='doctree.tinydocbook')
+
+static_files_layer = StaticFilesLayer()
+
+class StaticFilesTestCase(gocept.selenium.base.TestCase, unittest.TestCase):
+
+    layer = static_files_layer
+
+    def setUp(self):
+        super(StaticFilesTestCase, self).setUp()
+        self.documentroot = self.layer.documentroot

Deleted: gocept.selenium/branches/jw-staticfiles-testlayer/src/gocept/selenium/static/tests/ftesting.zcml
===================================================================
--- gocept.selenium/branches/jw-staticfiles-testlayer/src/gocept/selenium/ztk/tests/ftesting.zcml	2010-06-03 12:01:25 UTC (rev 112998)
+++ gocept.selenium/branches/jw-staticfiles-testlayer/src/gocept/selenium/static/tests/ftesting.zcml	2010-06-03 12:38:45 UTC (rev 112999)
@@ -1,35 +0,0 @@
-<configure
-  xmlns="http://namespaces.zope.org/zope"
-  i18n_domain="zope">
-
-  <include package="zope.app.zcmlfiles"/>
-  <include package="gocept.selenium.tests.fixture" file="configure.zcml"/>
-
-  <!-- typical functional testing security setup -->
-  <include package="zope.securitypolicy" file="meta.zcml"/>
-  <include package="zope.app.authentication"/>
-  <securityPolicy
-    component="zope.securitypolicy.zopepolicy.ZopeSecurityPolicy"
-    />
-
-  <unauthenticatedPrincipal
-    id="zope.anybody"
-    title="Unauthenticated User"
-    />
-  <grant
-    permission="zope.View"
-    principal="zope.anybody"
-    />
-
-  <principal
-    id="zope.mgr"
-    title="Manager"
-    login="admin"
-    password="admin"
-    />
-
-  <role id="zope.Manager" title="Site Manager" />
-  <grantAll role="zope.Manager" />
-  <grant role="zope.Manager" principal="zope.mgr" />
-
-</configure>

Deleted: gocept.selenium/branches/jw-staticfiles-testlayer/src/gocept/selenium/static/tests/test_selenese.py
===================================================================
--- gocept.selenium/branches/jw-staticfiles-testlayer/src/gocept/selenium/ztk/tests/test_selenese.py	2010-06-03 12:01:25 UTC (rev 112998)
+++ gocept.selenium/branches/jw-staticfiles-testlayer/src/gocept/selenium/static/tests/test_selenese.py	2010-06-03 12:38:45 UTC (rev 112999)
@@ -1,234 +0,0 @@
-#############################################################################
-#
-# Copyright (c) 2009 Zope Foundation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-
-from gocept.selenium.selenese import selenese_pattern_equals as match
-from gocept.selenium.selenese import camelcase_to_underscore
-import gocept.selenium.selenese
-import gocept.selenium.ztk.testing
-import unittest
-import time
-
-
-class PatternTest(unittest.TestCase):
-
-    def test_no_prefix(self):
-        self.assert_(match('foo', 'foo'))
-        self.assert_(not match('foo', 'bar'))
-        self.assert_(match('foo:bar', 'foo:bar'))
-
-    def test_exact(self):
-        self.assert_(match('foo', 'exact:foo'))
-        self.assert_(not match('foo', 'exact:bar'))
-
-    def test_glob(self):
-        self.assert_(match('foo', 'glob:f*'))
-        self.assert_(match('foo', 'glob:fo?'))
-        self.assert_(not match('foo', 'glob:'))
-
-        self.assert_(not match('foo', 'glob:b*'))
-        self.assert_(not match('foo', 'glob:?ar'))
-
-    def test_glob_with_regex_chars_should_work(self):
-        self.assert_(match('(foo)', 'glob:(foo)'))
-        self.assert_(match('[foo]', 'glob:[foo]'))
-
-    def test_regex(self):
-        self.assert_(match('foo', 'regex:^fo+$'))
-        self.assert_(not match('foo', 'regex:^f+$'))
-
-
-class UtilsTest(unittest.TestCase):
-
-    def test_camelcaseconvert(self):
-        self.assertEquals('asdf', camelcase_to_underscore('asdf'))
-        self.assertEquals('foo_bar', camelcase_to_underscore('fooBar'))
-
-
-class NonexistentNameTest(unittest.TestCase):
-
-    def setUp(self):
-        class TestCase(object):
-            failureException = None
-
-        class Selenese(gocept.selenium.selenese.Selenese):
-            def get_without_assert_type(self):
-                pass
-            @gocept.selenium.selenese.assert_type('wrong_type')
-            def get_with_wrong_assert_type(self):
-                pass
-
-        self.selenese = Selenese(None, TestCase())
-
-    def assertError(self, error, name, expected_msg):
-        try:
-            getattr(self.selenese, name)
-        except error, e:
-            msg = e.args[0]
-        self.assertEquals(expected_msg, msg)
-
-    def assertAttributeError(self, name):
-        self.assertError(AttributeError, name, name)
-
-    def test_nonexistent_name(self):
-        self.assertAttributeError('a_nonexistent_name')
-        self.assertAttributeError('assert_a_nonexistent_name')
-
-    def test_waitfor_verify(self):
-        self.assertAttributeError('waitFor_a_nonexistent_name')
-        self.assertAttributeError('verify_a_nonexistent_name')
-
-    def test_not(self):
-        self.assertAttributeError('a_Notexistent_name')
-        self.assertAttributeError('assert_a_Notexistent_name')
-        self.assertAttributeError('waitFor_a_Notexistent_name')
-        self.assertAttributeError('verify_a_Notexistent_name')
-
-    def test_broken_assert_type(self):
-        self.assertError(AttributeError,
-                         'assert_without_assert_type',
-                         "'function' object has no attribute 'assert_type'")
-        self.assertError(ValueError,
-                         'assert_with_wrong_assert_type',
-                         "Unknown assert type 'wrong_type' for "
-                         "selenese method 'assert_with_wrong_assert_type'.")
-
-
-class AssertionTest(gocept.selenium.ztk.testing.TestCase):
-
-    def test_wait_for(self):
-        self.selenium.open('/display-delay.html')
-        self.selenium.assertElementNotPresent('css=div')
-        self.selenium.waitForElementPresent('css=div')
-
-    def test_wait_for_timeout(self):
-        self.selenium.open('/display-delay.html')
-        self.selenium.assertElementNotPresent('css=div')
-        try:
-            self.selenium.setTimeout(10)
-            self.selenium.waitForElementPresent('css=div')
-        except AssertionError:
-            pass
-        else:
-            self.fail('Timeout did not raise')
-
-    def test_assert_element_present_failure(self):
-        self.selenium.open('/display-delay.html')
-        try:
-            self.selenium.assertElementNotPresent('css=body')
-        except AssertionError:
-            pass
-        else:
-            self.fail('assertion should have failed')
-
-    def test_pause(self):
-        start = time.time()
-        self.selenium.pause(5000)
-        if time.time() - start < 4:
-            self.fail('Pause did not pause long enough')
-
-    def test_deleteCookie_smoke(self):
-        # Smoke test: just check that we don't break
-        self.selenium.deleteCookie('foo', '/')
-
-    def test_selectFrame_frame_doesnt_exist(self):
-        self.assertRaises(Exception, self.selenium.selectFrame, 'foo')
-
-    def test_waitForCondition_timeout(self):
-        self.selenium.setTimeout(100)
-        self.assertRaises(
-            AssertionError, self.selenium.waitForCondition, 'false')
-
-    def test_fireEvent_smoke(self):
-        self.selenium.fireEvent('css=body', 'click')
-
-    def test_location(self):
-        self.selenium.open('/')
-        self.assertEquals(
-            'http://localhost:8087/',
-            self.selenium.getLocation())
-
-    def test_alert_not_present(self):
-        self.selenium.open('/')
-        self.selenium.verifyAlertNotPresent()
-
-    def test_alert_present(self):
-        self.selenium.open('/alert.html')
-        time.sleep(0.6)
-        self.selenium.verifyAlertPresent()
-        self.selenium.getAlert()
-
-    def test_wait_for_alert(self):
-        self.selenium.open('/alert.html')
-        self.selenium.verifyAlertNotPresent()
-        self.selenium.waitForAlertPresent()
-        self.selenium.getAlert()
-
-
-class PopUpTest(gocept.selenium.ztk.testing.TestCase):
-
-    def setUp(self):
-        super(PopUpTest, self).setUp()
-        self.selenium.open('/launch-popup.html')
-
-    def tearDown(self):
-        try:
-            self.selenium.selectPopUp(wait=False)
-        except Exception:
-            pass
-        if self.selenium.getLocation().endswith('/popup.html'):
-            self.selenium.close()
-            self.selenium.deselectPopUp()
-        self.selenium.setTimeout(30)
-        super(PopUpTest, self).tearDown()
-
-    def test_wait_for_and_select_popup(self):
-        # smoke tests for calls not otherwise used in this test class
-        self.selenium.waitForPopUp('gocept.selenium-popup')
-        self.selenium.waitForPopUp()
-        self.selenium.selectPopUp()
-
-    def test_wait_for_popup_times_out(self):
-        self.selenium.selectPopUp('gocept.selenium-popup')
-        self.selenium.close()
-        self.selenium.deselectPopUp()
-        self.selenium.setTimeout(0)
-        self.assertRaises(Exception, self.selenium.waitForPopUp,
-                          'gocept.selenium-popup')
-        self.assertRaises(Exception, self.selenium.waitForPopUp)
-        self.selenium.setTimeout(1)
-        self.assertRaises(Exception, self.selenium.waitForPopUp,
-                          'gocept.selenium-popup')
-        self.assertRaises(Exception, self.selenium.waitForPopUp)
-
-    def test_select_popup(self):
-        self.assertRaises(Exception,
-                          self.selenium.selectPopUp,
-                          'gocept.selenium-popup', wait=False)
-        self.selenium.selectPopUp('gocept.selenium-popup')
-        self.selenium.verifyElementPresent('css=div#popup')
-
-    def test_deselect_popup(self):
-        self.selenium.selectPopUp('gocept.selenium-popup')
-        self.selenium.deselectPopUp()
-        self.selenium.verifyElementNotPresent('css=div#popup')
-        self.selenium.verifyElementPresent('css=div#parent')
-
-    def test_close(self):
-        self.selenium.selectPopUp('gocept.selenium-popup')
-        self.selenium.verifyElementPresent('css=div#popup')
-        self.selenium.close()
-        self.assertRaises(Exception,
-                          self.selenium.verifyElementPresent, 'css=div#popup')
-        self.selenium.deselectPopUp()
-        self.selenium.verifyElementPresent('css=div#parent')

Added: gocept.selenium/branches/jw-staticfiles-testlayer/src/gocept/selenium/static/tests/test_static.py
===================================================================
--- gocept.selenium/branches/jw-staticfiles-testlayer/src/gocept/selenium/static/tests/test_static.py	                        (rev 0)
+++ gocept.selenium/branches/jw-staticfiles-testlayer/src/gocept/selenium/static/tests/test_static.py	2010-06-03 12:38:45 UTC (rev 112999)
@@ -0,0 +1,51 @@
+#############################################################################
+#
+# Copyright (c) 2009 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+import unittest
+import gocept.selenium.static
+
+class TestStaticFilesTestCase(unittest.TestCase):
+
+    def setUp(self):
+        self.testlayer = gocept.selenium.static.StaticFilesLayer()
+        self.testlayer.setUp()
+
+    def tearDown(self):
+        self.testlayer.tearDown()
+
+    def test_documentroot(self):
+        self.assert_(self.testlayer.documentroot.startswith('/tmp'))
+
+    def test_documentroot_initially_empty(self):
+        import os
+        documentroot = self.testlayer.documentroot
+        self.assert_(not os.listdir(self.testlayer.documentroot))
+        open(os.path.join(documentroot, 'foo.txt'), 'w').write('Hello World!')
+        self.assertEquals(
+            ['foo.txt'], os.listdir(self.testlayer.documentroot))
+
+    def test_documentroot_empty_after_switchdb(self):
+        import os
+        documentroot = self.testlayer.documentroot
+        self.assert_(not os.listdir(self.testlayer.documentroot))
+        open(os.path.join(documentroot, 'bar.txt'), 'w').write('Hello World!')
+        self.assertEquals(
+            ['bar.txt'], os.listdir(self.testlayer.documentroot))
+        self.testlayer.switch_db()
+        self.assert_(not os.listdir(self.testlayer.documentroot))
+
+    def test_server_startup_shutdown(self):
+        self.assert_(self.testlayer.server.pid)
+        self.testlayer.stop_server()
+        self.assert_(not self.testlayer.server)

Deleted: gocept.selenium/branches/jw-staticfiles-testlayer/src/gocept/selenium/static/tests/test_ztk.py
===================================================================
--- gocept.selenium/branches/jw-staticfiles-testlayer/src/gocept/selenium/ztk/tests/test_ztk.py	2010-06-03 12:01:25 UTC (rev 112998)
+++ gocept.selenium/branches/jw-staticfiles-testlayer/src/gocept/selenium/static/tests/test_ztk.py	2010-06-03 12:38:45 UTC (rev 112999)
@@ -1,22 +0,0 @@
-#############################################################################
-#
-# Copyright (c) 2009 Zope Foundation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-
-import gocept.selenium.ztk.testing
-import gocept.selenium.tests.isolation
-
-class ZTKTests(gocept.selenium.tests.isolation.IsolationTests,
-               gocept.selenium.ztk.testing.TestCase):
-
-    def test_selenium_http_500_handling(self):
-        self.selenium.open('http://%s/error.html' % self.selenium.server)

Copied: gocept.selenium/branches/jw-staticfiles-testlayer/static.cfg (from rev 112998, gocept.selenium/branches/jw-staticfiles-testlayer/ztk.cfg)
===================================================================
--- gocept.selenium/branches/jw-staticfiles-testlayer/static.cfg	                        (rev 0)
+++ gocept.selenium/branches/jw-staticfiles-testlayer/static.cfg	2010-06-03 12:38:45 UTC (rev 112999)
@@ -0,0 +1,14 @@
+[buildout]
+develop = .
+parts = test seleniumrc
+package = gocept.selenium
+
+[seleniumrc]
+recipe = collective.recipe.seleniumrc
+url = http://release.seleniumhq.org/selenium-remote-control/1.0.1/selenium-remote-control-1.0.1-dist.zip
+md5sum = 068b1adb26a7450717e6d6d67e261b58
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = ${buildout:package}
+defaults = ['--ignore_dir', 'zope2', '--ignore_dir', 'plone', '--ignore_dir', 'ztk', '-v', '-c']



More information about the checkins mailing list