[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/file/browser/ fixed the way absolute_url is retrieved in ImageData.tag()

Tarek Ziadé tziade at nuxeo.com
Sun Apr 9 21:09:36 EDT 2006


Log message for revision 66755:
  fixed the way absolute_url is retrieved in ImageData.tag()

Changed:
  U   Zope3/trunk/src/zope/app/file/browser/image.py
  U   Zope3/trunk/src/zope/app/file/browser/tests/test_imagedata.py

-=-
Modified: Zope3/trunk/src/zope/app/file/browser/image.py
===================================================================
--- Zope3/trunk/src/zope/app/file/browser/image.py	2006-04-09 21:31:11 UTC (rev 66754)
+++ Zope3/trunk/src/zope/app/file/browser/image.py	2006-04-10 01:09:35 UTC (rev 66755)
@@ -18,6 +18,7 @@
 __docformat__ = 'restructuredtext'
 
 from zope.app.size.interfaces import ISized
+from zope.app import zapi
 
 class ImageData(object):
 
@@ -58,8 +59,12 @@
         if ydelta and height:
             height = str(int(round(int(height) * ydelta)))
 
-        result = '<img src="%s"' % (self.absolute_url())
-
+        if self.request is not None:
+            result = '<img src="%s"' % zapi.absoluteURL(self.context,
+                                                        self.request)
+        else:
+            result = '<img '       
+ 
         if alt is None:
             alt = getattr(self, 'title', '')
         result = '%s alt="%s"' % (result, alt)

Modified: Zope3/trunk/src/zope/app/file/browser/tests/test_imagedata.py
===================================================================
--- Zope3/trunk/src/zope/app/file/browser/tests/test_imagedata.py	2006-04-09 21:31:11 UTC (rev 66754)
+++ Zope3/trunk/src/zope/app/file/browser/tests/test_imagedata.py	2006-04-10 01:09:35 UTC (rev 66755)
@@ -20,6 +20,9 @@
 from zope.app.file.image import Image
 from zope.app.file.browser.image import ImageData
 
+class FakeRequest(object):
+    pass
+
 class Test(unittest.TestCase):
 
     def testData(self):
@@ -33,34 +36,39 @@
     def testTag(self):
         """ """
 
-        # We need that, sinc eabsolute_url is not implemented yet.
-        def absolute_url():
+        # faking absolute_url getter .
+        def absolute_url(context, request):
             return '/img'
 
         image = Image()
         fe = ImageData()
         fe.context = image
-        fe.request = None
-        fe.absolute_url = absolute_url
+        fe.request = FakeRequest()
 
-        self.assertEqual(fe.tag(),
-            '<img src="/img" alt="" height="-1" width="-1" border="0" />')
-        self.assertEqual(fe.tag(alt="Test Image"),
-            '<img src="/img" alt="Test Image" '
-            'height="-1" width="-1" border="0" />')
-        self.assertEqual(fe.tag(height=100, width=100),
-            '<img src="/img" alt="" height="100" width="100" border="0" />')
-        self.assertEqual(fe.tag(border=1),
-            '<img src="/img" alt="" height="-1" width="-1" border="1" />')
-        self.assertEqual(fe.tag(css_class="Image"),
-            '<img src="/img" alt="" '
-            'height="-1" width="-1" border="0" class="Image" />')
-        self.assertEqual(fe.tag(height=100, width="100",
-                         border=1, css_class="Image"),
-            '<img src="/img" alt="" '
-            'height="100" width="100" class="Image" border="1" />')
+        from zope.app import zapi
+        old_absoluteURL = zapi.absoluteURL
+        try:
+            zapi.absoluteURL = absolute_url
+            self.assertEqual(fe.tag(),
+                '<img src="/img" alt="" height="-1" width="-1" border="0" />')
+            self.assertEqual(fe.tag(alt="Test Image"),
+                '<img src="/img" alt="Test Image" '
+                'height="-1" width="-1" border="0" />')
+            self.assertEqual(fe.tag(height=100, width=100),
+                ('<img src="/img" alt="" height="100" '
+                 'width="100" border="0" />'))
+            self.assertEqual(fe.tag(border=1),
+                '<img src="/img" alt="" height="-1" width="-1" border="1" />')
+            self.assertEqual(fe.tag(css_class="Image"),
+                '<img src="/img" alt="" '
+                'height="-1" width="-1" border="0" class="Image" />')
+            self.assertEqual(fe.tag(height=100, width="100",
+                            border=1, css_class="Image"),
+                '<img src="/img" alt="" '
+                'height="100" width="100" class="Image" border="1" />')
+        finally:
+            zapi.absoluteURL = old_absoluteURL
 
-
 def test_suite():
     loader = unittest.TestLoader()
     return loader.loadTestsFromTestCase(Test)



More information about the Zope3-Checkins mailing list