[Checkins] SVN: five.hashedresource/trunk/ checkpoint: trying to clean up test, just makes them break so far

Thomas Lotze tl at gocept.com
Tue Jul 14 11:00:40 EDT 2009


Log message for revision 101907:
  checkpoint: trying to clean up test, just makes them break so far

Changed:
  U   five.hashedresource/trunk/buildout.cfg
  U   five.hashedresource/trunk/src/five/hashedresource/ftesting.zcml
  U   five.hashedresource/trunk/src/five/hashedresource/testing.py
  U   five.hashedresource/trunk/src/five/hashedresource/tests/test_url.py
  U   five.hashedresource/trunk/src/five/hashedresource/url.py

-=-
Modified: five.hashedresource/trunk/buildout.cfg
===================================================================
--- five.hashedresource/trunk/buildout.cfg	2009-07-14 14:44:43 UTC (rev 101906)
+++ five.hashedresource/trunk/buildout.cfg	2009-07-14 15:00:40 UTC (rev 101907)
@@ -1,5 +1,6 @@
 [buildout]
 develop = .
+          ../z3c.hashedresource
 parts = test
         zopepy
 

Modified: five.hashedresource/trunk/src/five/hashedresource/ftesting.zcml
===================================================================
--- five.hashedresource/trunk/src/five/hashedresource/ftesting.zcml	2009-07-14 14:44:43 UTC (rev 101906)
+++ five.hashedresource/trunk/src/five/hashedresource/ftesting.zcml	2009-07-14 15:00:40 UTC (rev 101907)
@@ -13,4 +13,12 @@
     directory="tests/fixture"
     name="myresource"
     />
+  <browser:resource
+    file="tests/fixture/example.txt"
+    name="example.txt"
+    />
+  <browser:resource
+    file="tests/fixture/test.txt"
+    name="test.txt"
+    />
 </configure>

Modified: five.hashedresource/trunk/src/five/hashedresource/testing.py
===================================================================
--- five.hashedresource/trunk/src/five/hashedresource/testing.py	2009-07-14 14:44:43 UTC (rev 101906)
+++ five.hashedresource/trunk/src/five/hashedresource/testing.py	2009-07-14 15:00:40 UTC (rev 101907)
@@ -23,6 +23,7 @@
 import Testing.ZopeTestCase.utils
 import five.hashedresource
 import five.hashedresource.tests
+import os
 import os.path
 import re
 import shutil
@@ -40,12 +41,17 @@
 
     @classmethod
     def setUp(cls):
+        open(os.path.join(fixture, 'example.txt'), 'w').write('')
         Products.Five.zcml.load_config(
             'configure.zcml', Products.Five)
         Products.Five.zcml.load_config(
             'ftesting-devmode.zcml', five.hashedresource)
 
+    @classmethod
+    def tearDown(cls):
+        os.unlink(os.path.join(fixture, 'example.txt'))
 
+
 class FunctionalTestCase(Testing.ZopeTestCase.FunctionalTestCase):
 
     layer = HashedResourcesLayer
@@ -66,13 +72,11 @@
         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'
+        self.directory = zope.component.getAdapter(
+            self.request, name='myresource')
 
     def tearDown(self):
         shutil.rmtree(self.tmpdir)
 
     def _hash(self, text):
-        return re.match('http://127.0.0.1/\+\+noop\+\+([^/]*)/.*', text).group(1)
+        return re.match('http://nohost/\+\+noop\+\+([^/]*)/.*', text).group(1)

Modified: five.hashedresource/trunk/src/five/hashedresource/tests/test_url.py
===================================================================
--- five.hashedresource/trunk/src/five/hashedresource/tests/test_url.py	2009-07-14 14:44:43 UTC (rev 101906)
+++ five.hashedresource/trunk/src/five/hashedresource/tests/test_url.py	2009-07-14 15:00:40 UTC (rev 101907)
@@ -16,7 +16,6 @@
 $Id$
 """
 from five.hashedresource import testing
-import Products.Five.browser.resource
 import os.path
 import unittest
 import zope.component
@@ -30,34 +29,24 @@
                 (self.directory, self.request),
                 zope.traversing.browser.interfaces.IAbsoluteURL))
         self.assertMatches(
-            r'http://127.0.0.1/\+\+noop\+\+[^/]*/\+\+resource\+\+%s' %
+            r'http://nohost/\+\+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 = zope.component.getAdapter(self.request, name='test.txt')
         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',
+            'http://nohost/\+\+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'
+        open(os.path.join(testing.fixture, 'example.txt'), 'w').write('foo')
+        file1 = zope.component.getAdapter(self.request, name='example.txt')
         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'
+        open(os.path.join(testing.fixture, 'example.txt'), 'w').write('bar')
+        file2 = zope.component.getAdapter(self.request, name='example.txt')
         file2_url = str(zope.component.getMultiAdapter((file2, self.request),
                 zope.traversing.browser.interfaces.IAbsoluteURL))
         self.assertNotEqual(self._hash(file1_url), self._hash(file2_url))

Modified: five.hashedresource/trunk/src/five/hashedresource/url.py
===================================================================
--- five.hashedresource/trunk/src/five/hashedresource/url.py	2009-07-14 14:44:43 UTC (rev 101906)
+++ five.hashedresource/trunk/src/five/hashedresource/url.py	2009-07-14 15:00:40 UTC (rev 101907)
@@ -33,8 +33,7 @@
         self.context = context
         self.request = request
 
-        # XXX duplicated from zope.app.publisher.browser.resource.AbsoluteURL
-        self.name = self.context.__name__
+        self.name = self.context.__parent__.__name__
         if self.name.startswith('++resource++'):
             self.name = self.name[12:]
 



More information about the Checkins mailing list