[Checkins] SVN: five.hashedresource/trunk/ added tests and Zope2 setup

Thomas Lotze tl at gocept.com
Tue Jul 14 10:15:47 EDT 2009


Log message for revision 101902:
  added tests and Zope2 setup

Changed:
  _U  five.hashedresource/trunk/
  U   five.hashedresource/trunk/buildout.cfg
  U   five.hashedresource/trunk/setup.py
  A   five.hashedresource/trunk/src/five/hashedresource/ftesting-devmode.zcml
  A   five.hashedresource/trunk/src/five/hashedresource/ftesting.zcml
  A   five.hashedresource/trunk/src/five/hashedresource/testing.py
  A   five.hashedresource/trunk/src/five/hashedresource/tests/
  A   five.hashedresource/trunk/src/five/hashedresource/tests/__init__.py
  A   five.hashedresource/trunk/src/five/hashedresource/tests/fixture/
  A   five.hashedresource/trunk/src/five/hashedresource/tests/fixture/test.pt
  A   five.hashedresource/trunk/src/five/hashedresource/tests/fixture/test.txt
  A   five.hashedresource/trunk/src/five/hashedresource/tests/test_browser.py
  A   five.hashedresource/trunk/src/five/hashedresource/tests/test_hash.py
  A   five.hashedresource/trunk/src/five/hashedresource/tests/test_url.py

-=-

Property changes on: five.hashedresource/trunk
___________________________________________________________________
Added: svn:ignore
   + develop-eggs
bin
build
var
parts
.installed.cfg


Modified: five.hashedresource/trunk/buildout.cfg
===================================================================
--- five.hashedresource/trunk/buildout.cfg	2009-07-14 13:59:05 UTC (rev 101901)
+++ five.hashedresource/trunk/buildout.cfg	2009-07-14 14:15:47 UTC (rev 101902)
@@ -1,7 +1,55 @@
 [buildout]
 develop = .
 parts = test
+        zopepy
 
+find-links =
+    http://download.zope.org/ppix/
+    http://download.zope.org/distribution/
+    http://effbot.org/downloads
+    http://download.gocept.com/packages
+
+# Add additional eggs here
+eggs =
+    five.hashedresource [test]
+
+versions = versions
+
+[versions]
+zc.recipe.cmmi = 1.2.0
+
+[zope2]
+recipe = plone.recipe.zope2install
+url = http://www.zope.org/Products/Zope/2.11.3/Zope-2.11.3-final.tgz
+fake-zope-eggs = true
+fake-eggs-folder = ${buildout:parts-directory}/fake-eggs
+# [dovecot] needs these and can't get them from the [zope2]-location
+skip-fake-eggs =
+    zdaemon
+    ZConfig
+
+[instance]
+recipe = plone.recipe.zope2instance
+zope2-location = ${zope2:location}
+blob-storage = ${buildout:directory}/var/blobstorage
+user = admin:admin
+http-address = 8080
+debug-mode = on
+verbose-security = on
+eggs = ${buildout:eggs}
+zcml =
+    gocept.restmail
+    gocept.webmail
+
+[zopepy]
+recipe = zc.recipe.egg
+eggs = ${instance:eggs}
+interpreter = zopepy
+extra-paths = ${zope2:location}/lib/python
+scripts = zopepy
+
 [test]
-recipe = zc.recipe.testrunner
-eggs = five.hashedresource[test]
+recipe = collective.recipe.z2testrunner
+packages = five.hashedresource
+extra-paths = .
+zope2part = instance

Modified: five.hashedresource/trunk/setup.py
===================================================================
--- five.hashedresource/trunk/setup.py	2009-07-14 13:59:05 UTC (rev 101901)
+++ five.hashedresource/trunk/setup.py	2009-07-14 14:15:47 UTC (rev 101902)
@@ -5,7 +5,7 @@
 setup(
     name='five.hashedresource',
     version = '0.1dev',
-    author='Sebastian Wehrmann',
+    author='gocept gmbh & co. kg',
     author_email='sw at gocept.com',
     description='Provides URLs for resources that change whenever their content changes.',
     url='http://pypi.python.org/pypi/five.hashedresource',

Added: five.hashedresource/trunk/src/five/hashedresource/ftesting-devmode.zcml
===================================================================
--- five.hashedresource/trunk/src/five/hashedresource/ftesting-devmode.zcml	                        (rev 0)
+++ five.hashedresource/trunk/src/five/hashedresource/ftesting-devmode.zcml	2009-07-14 14:15:47 UTC (rev 101902)
@@ -0,0 +1,8 @@
+<configure
+   xmlns="http://namespaces.zope.org/zope"
+   xmlns:meta="http://namespaces.zope.org/meta"
+   >
+
+  <meta:provides feature="devmode"/>
+  <include file="ftesting.zcml"/>
+</configure>
\ No newline at end of file


Property changes on: five.hashedresource/trunk/src/five/hashedresource/ftesting-devmode.zcml
___________________________________________________________________
Added: svn:keywords
   + Id Rev Date
Added: svn:eol-style
   + native

Added: five.hashedresource/trunk/src/five/hashedresource/ftesting.zcml
===================================================================
--- five.hashedresource/trunk/src/five/hashedresource/ftesting.zcml	                        (rev 0)
+++ five.hashedresource/trunk/src/five/hashedresource/ftesting.zcml	2009-07-14 14:15:47 UTC (rev 101902)
@@ -0,0 +1,16 @@
+<configure
+   xmlns="http://namespaces.zope.org/zope"
+   xmlns:browser="http://namespaces.zope.org/browser"
+   xmlns:five="http://namespaces.zope.org/five"
+   >
+
+  <include package="five.hashedresource" />
+
+  <browser:defaultSkin name="z3c.hashedresource" />
+
+  <!-- example resource for testing -->
+  <browser:resourceDirectory
+    directory="tests/fixture"
+    name="myresource"
+    />
+</configure>


Property changes on: five.hashedresource/trunk/src/five/hashedresource/ftesting.zcml
___________________________________________________________________
Added: svn:keywords
   + Id Rev Date
Added: svn:eol-style
   + native

Added: five.hashedresource/trunk/src/five/hashedresource/testing.py
===================================================================
--- five.hashedresource/trunk/src/five/hashedresource/testing.py	                        (rev 0)
+++ five.hashedresource/trunk/src/five/hashedresource/testing.py	2009-07-14 14:15:47 UTC (rev 101902)
@@ -0,0 +1,78 @@
+#############################################################################
+#
+# Copyright (c) 2009 Zope Corporation 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.
+#
+##############################################################################
+"""tests
+
+$Id$
+"""
+import Products.Five
+import Products.Five.browser.resource
+import Products.Five.zcml
+import Testing.ZopeTestCase
+import Testing.ZopeTestCase.layer
+import Testing.ZopeTestCase.utils
+import five.hashedresource
+import five.hashedresource.tests
+import os.path
+import re
+import shutil
+import tempfile
+import z3c.hashedresource
+import zope.app.testing.functional
+import zope.interface
+
+
+fixture = os.path.join(
+    os.path.dirname(five.hashedresource.tests.__file__), 'fixture')
+
+
+class HashedResourcesLayer(Testing.ZopeTestCase.layer.ZopeLiteLayer):
+
+    @classmethod
+    def setUp(cls):
+        Products.Five.zcml.load_config(
+            'configure.zcml', Products.Five)
+        Products.Five.zcml.load_config(
+            'ftesting-devmode.zcml', five.hashedresource)
+
+
+class FunctionalTestCase(Testing.ZopeTestCase.FunctionalTestCase):
+
+    layer = HashedResourcesLayer
+
+    def assertMatches(self, regex, text):
+        self.assert_(re.match(regex, text), "/%s/ did not match '%s'" % (
+            regex, text))
+
+    def setUp(self):
+        super(FunctionalTestCase, self).setUp()
+
+        self.tmpdir = tempfile.mkdtemp()
+        open(os.path.join(self.tmpdir, 'example.txt'), 'w').write('')
+        self.dirname = os.path.basename(self.tmpdir)
+
+        self.request = Testing.ZopeTestCase.utils.makerequest(
+            self._app()).REQUEST
+        zope.interface.directlyProvides(
+            self.request, z3c.hashedresource.interfaces.IHashedResourceSkin)
+        self.request.getVirtualHostRoot = lambda: None
+        self.directory = Products.Five.browser.resource.DirectoryResourceFactory(
+            self.dirname, self.tmpdir)(self.request)
+        self.directory.__name__ = self.dirname
+        self.directory.absolute_url = lambda: 'http://127.0.0.1'
+
+    def tearDown(self):
+        shutil.rmtree(self.tmpdir)
+
+    def _hash(self, text):
+        return re.match('http://127.0.0.1/\+\+noop\+\+([^/]*)/.*', text).group(1)


Property changes on: five.hashedresource/trunk/src/five/hashedresource/testing.py
___________________________________________________________________
Added: svn:keywords
   + Id Rev Date
Added: svn:eol-style
   + native

Added: five.hashedresource/trunk/src/five/hashedresource/tests/__init__.py
===================================================================
--- five.hashedresource/trunk/src/five/hashedresource/tests/__init__.py	                        (rev 0)
+++ five.hashedresource/trunk/src/five/hashedresource/tests/__init__.py	2009-07-14 14:15:47 UTC (rev 101902)
@@ -0,0 +1 @@
+# python package


Property changes on: five.hashedresource/trunk/src/five/hashedresource/tests/__init__.py
___________________________________________________________________
Added: svn:keywords
   + Id Rev Date
Added: svn:eol-style
   + native

Added: five.hashedresource/trunk/src/five/hashedresource/tests/fixture/test.pt
===================================================================
--- five.hashedresource/trunk/src/five/hashedresource/tests/fixture/test.pt	                        (rev 0)
+++ five.hashedresource/trunk/src/five/hashedresource/tests/fixture/test.pt	2009-07-14 14:15:47 UTC (rev 101902)
@@ -0,0 +1 @@
+<html><body><p>test</p></body></html>


Property changes on: five.hashedresource/trunk/src/five/hashedresource/tests/fixture/test.pt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Date
Added: svn:eol-style
   + native

Added: five.hashedresource/trunk/src/five/hashedresource/tests/fixture/test.txt
===================================================================
--- five.hashedresource/trunk/src/five/hashedresource/tests/fixture/test.txt	                        (rev 0)
+++ five.hashedresource/trunk/src/five/hashedresource/tests/fixture/test.txt	2009-07-14 14:15:47 UTC (rev 101902)
@@ -0,0 +1,2 @@
+test
+data


Property changes on: five.hashedresource/trunk/src/five/hashedresource/tests/fixture/test.txt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Date
Added: svn:eol-style
   + native

Added: five.hashedresource/trunk/src/five/hashedresource/tests/test_browser.py
===================================================================
--- five.hashedresource/trunk/src/five/hashedresource/tests/test_browser.py	                        (rev 0)
+++ five.hashedresource/trunk/src/five/hashedresource/tests/test_browser.py	2009-07-14 14:15:47 UTC (rev 101902)
@@ -0,0 +1,53 @@
+#############################################################################
+#
+# Copyright (c) 2006-2007 Zope Corporation 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.
+#
+##############################################################################
+"""tests
+
+$Id$
+"""
+from five.hashedresource import testing
+from z3c.hashedresource import interfaces
+import Testing.ZopeTestCase
+import unittest
+import Products.Five.testbrowser
+import zope.component
+import zope.publisher.browser
+
+
+class BrowserTest(Testing.ZopeTestCase.FunctionalTestCase):
+
+    layer = testing.HashedResourcesLayer
+
+    def setUp(self):
+        super(BrowserTest, self).setUp()
+        self.browser = Products.Five.testbrowser.Browser()
+        self.browser.handleErrors = False
+        self.directory = zope.component.getAdapter(
+            zope.publisher.browser.TestRequest(), name='myresource')
+
+    def test_traverse_resource_by_name(self):
+        self.browser.open('http://localhost/++resource++myresource/test.txt')
+        self.assertEqual('test\ndata\n', self.browser.contents)
+
+    def test_traverse_resource_by_hash(self):
+        hash = str(
+            interfaces.IResourceContentsHash(self.directory))
+        self.browser.open(
+            'http://localhost/++noop++%s/++resource++myresource/test.txt' % hash)
+        self.assertEqual('test\ndata\n', self.browser.contents)
+
+
+def test_suite():
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(BrowserTest))
+    return suite


Property changes on: five.hashedresource/trunk/src/five/hashedresource/tests/test_browser.py
___________________________________________________________________
Added: svn:keywords
   + Id Rev Date
Added: svn:eol-style
   + native

Added: five.hashedresource/trunk/src/five/hashedresource/tests/test_hash.py
===================================================================
--- five.hashedresource/trunk/src/five/hashedresource/tests/test_hash.py	                        (rev 0)
+++ five.hashedresource/trunk/src/five/hashedresource/tests/test_hash.py	2009-07-14 14:15:47 UTC (rev 101902)
@@ -0,0 +1,59 @@
+#############################################################################
+#
+# Copyright (c) 2006-2007 Zope Corporation 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.
+#
+##############################################################################
+"""tests
+
+$Id$
+"""
+from five.hashedresource import testing
+from z3c.hashedresource import hash
+import Products.Five.browser.resource
+import Products.Five.zcml
+import Testing.ZopeTestCase.layer
+import five.hashedresource
+import os
+import unittest
+import zope.component
+
+
+class ProductionModeLayer(Testing.ZopeTestCase.layer.ZopeLiteLayer):
+
+    @classmethod
+    def setUp(cls):
+        Products.Five.zcml.load_config(
+            'ftesting.zcml', five.hashedresource)
+
+
+class CachingContentsHashTest(testing.FunctionalTestCase):
+
+    layer = ProductionModeLayer
+
+    def test_production_mode_hash_should_not_change(self):
+        zope.component.provideAdapter(
+            hash.CachingContentsHash,
+            (Products.Five.browser.resource.DirectoryResource,))
+
+        before = str(zope.component.getMultiAdapter(
+                (self.directory, self.request),
+                zope.traversing.browser.interfaces.IAbsoluteURL))
+        open(os.path.join(self.tmpdir, 'example.txt'), 'w').write('foo')
+        after = str(zope.component.getMultiAdapter(
+                (self.directory, self.request),
+                zope.traversing.browser.interfaces.IAbsoluteURL))
+        self.assertEqual(self._hash(before), self._hash(after))
+
+
+def test_suite():
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(CachingContentsHashTest))
+    return suite


Property changes on: five.hashedresource/trunk/src/five/hashedresource/tests/test_hash.py
___________________________________________________________________
Added: svn:keywords
   + Id Rev Date
Added: svn:eol-style
   + native

Added: five.hashedresource/trunk/src/five/hashedresource/tests/test_url.py
===================================================================
--- five.hashedresource/trunk/src/five/hashedresource/tests/test_url.py	                        (rev 0)
+++ five.hashedresource/trunk/src/five/hashedresource/tests/test_url.py	2009-07-14 14:15:47 UTC (rev 101902)
@@ -0,0 +1,79 @@
+##############################################################################
+#
+# Copyright (c) 2009 Zope Corporation 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.
+#
+##############################################################################
+"""tests
+
+$Id$
+"""
+from five.hashedresource import testing
+import Products.Five.browser.resource
+import os.path
+import unittest
+import zope.component
+import zope.traversing.browser.interfaces
+
+
+class HashingURLTest(testing.FunctionalTestCase):
+
+    def test_directory_url_should_contain_hash(self):
+        directory_url = str(zope.component.getMultiAdapter(
+                (self.directory, self.request),
+                zope.traversing.browser.interfaces.IAbsoluteURL))
+        self.assertMatches(
+            r'http://127.0.0.1/\+\+noop\+\+[^/]*/\+\+resource\+\+%s' %
+            self.dirname, directory_url)
+
+    def test_file_url_should_contain_hash(self):
+        file = Products.Five.browser.resource.FileResourceFactory(
+            'test.txt', os.path.join(testing.fixture, 'test.txt'))(
+            self.request)
+        file.__name__ = 'test.txt'
+        file.absolute_url = lambda: 'http://127.0.0.1'
+        file_url = str(zope.component.getMultiAdapter((file, self.request),
+                zope.traversing.browser.interfaces.IAbsoluteURL))
+        self.assertMatches(
+            'http://127.0.0.1/\+\+noop\+\+[^/]*/\+\+resource\+\+test.txt',
+            file_url)
+
+    def test_different_files_hashes_should_differ(self):
+        file1 = Products.Five.browser.resource.FileResourceFactory(
+            'test.txt', os.path.join(testing.fixture, 'test.txt'))(
+            self.request)
+        file1.__name__ = 'test.txt'
+        file1.absolute_url = lambda: 'http://127.0.0.1'
+        file1_url = str(zope.component.getMultiAdapter((file1, self.request),
+                zope.traversing.browser.interfaces.IAbsoluteURL))
+        file2 = Products.Five.browser.resource.FileResourceFactory(
+            'test.txt', os.path.join(testing.fixture, 'test.pt'))(
+            self.request)
+        file2.__name__ = 'test.txt'
+        file2.absolute_url = lambda: 'http://127.0.0.1'
+        file2_url = str(zope.component.getMultiAdapter((file2, self.request),
+                zope.traversing.browser.interfaces.IAbsoluteURL))
+        self.assertNotEqual(self._hash(file1_url), self._hash(file2_url))
+
+    def test_directory_contents_changed_hash_should_change(self):
+        before = str(zope.component.getMultiAdapter(
+                (self.directory, self.request),
+                zope.traversing.browser.interfaces.IAbsoluteURL))
+        open(os.path.join(self.tmpdir, 'example.txt'), 'w').write('foo')
+        after = str(zope.component.getMultiAdapter(
+                (self.directory, self.request),
+                zope.traversing.browser.interfaces.IAbsoluteURL))
+        self.assertNotEqual(self._hash(before), self._hash(after))
+
+
+def test_suite():
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(HashingURLTest))
+    return suite


Property changes on: five.hashedresource/trunk/src/five/hashedresource/tests/test_url.py
___________________________________________________________________
Added: svn:keywords
   + Id Rev Date
Added: svn:eol-style
   + native



More information about the Checkins mailing list