[Checkins] SVN: gocept.selenium/branches/jw-staticfiles-testlayer2/s clean up static files layer implementation

Jan-Wijbrand Kolman janwijbrand at gmail.com
Mon Jun 14 06:24:22 EDT 2010


Log message for revision 113446:
  clean up static files layer implementation

Changed:
  A   gocept.selenium/branches/jw-staticfiles-testlayer2/src/gocept/selenium/static/
  A   gocept.selenium/branches/jw-staticfiles-testlayer2/src/gocept/selenium/static/__init__.py
  A   gocept.selenium/branches/jw-staticfiles-testlayer2/src/gocept/selenium/static/tests/
  A   gocept.selenium/branches/jw-staticfiles-testlayer2/src/gocept/selenium/static/tests/__init__.py
  A   gocept.selenium/branches/jw-staticfiles-testlayer2/src/gocept/selenium/static/tests/test_static.py
  A   gocept.selenium/branches/jw-staticfiles-testlayer2/static.cfg

-=-
Added: gocept.selenium/branches/jw-staticfiles-testlayer2/src/gocept/selenium/static/__init__.py
===================================================================
--- gocept.selenium/branches/jw-staticfiles-testlayer2/src/gocept/selenium/static/__init__.py	                        (rev 0)
+++ gocept.selenium/branches/jw-staticfiles-testlayer2/src/gocept/selenium/static/__init__.py	2010-06-14 10:24:22 UTC (rev 113446)
@@ -0,0 +1,77 @@
+#############################################################################
+#
+# Copyright (c) 2010 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)
+        super(StaticFilesLayer, self).tearDown()
+
+    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

Added: gocept.selenium/branches/jw-staticfiles-testlayer2/src/gocept/selenium/static/tests/__init__.py
===================================================================
--- gocept.selenium/branches/jw-staticfiles-testlayer2/src/gocept/selenium/static/tests/__init__.py	                        (rev 0)
+++ gocept.selenium/branches/jw-staticfiles-testlayer2/src/gocept/selenium/static/tests/__init__.py	2010-06-14 10:24:22 UTC (rev 113446)
@@ -0,0 +1 @@
+# python package

Added: gocept.selenium/branches/jw-staticfiles-testlayer2/src/gocept/selenium/static/tests/test_static.py
===================================================================
--- gocept.selenium/branches/jw-staticfiles-testlayer2/src/gocept/selenium/static/tests/test_static.py	                        (rev 0)
+++ gocept.selenium/branches/jw-staticfiles-testlayer2/src/gocept/selenium/static/tests/test_static.py	2010-06-14 10:24:22 UTC (rev 113446)
@@ -0,0 +1,52 @@
+#############################################################################
+#
+# Copyright (c) 2010 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)

Copied: gocept.selenium/branches/jw-staticfiles-testlayer2/static.cfg (from rev 113445, gocept.selenium/branches/jw-staticfiles-testlayer2/ztk.cfg)
===================================================================
--- gocept.selenium/branches/jw-staticfiles-testlayer2/static.cfg	                        (rev 0)
+++ gocept.selenium/branches/jw-staticfiles-testlayer2/static.cfg	2010-06-14 10:24:22 UTC (rev 113446)
@@ -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