[Zope3-checkins] CVS: Zope3/src/zope/app/file/browser/tests - __init__.py:1.2 test_imagedata.py:1.2 test_imageupload.py:1.2

Philipp von Weitershausen philikon at philikon.de
Tue Feb 24 11:50:20 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/file/browser/tests
In directory cvs.zope.org:/tmp/cvs-serv26210/src/zope/app/file/browser/tests

Added Files:
	__init__.py test_imagedata.py test_imageupload.py 
Log Message:


Combined the File and Image content types in their own package below
zope.app, including their interfaces and browser views.




=== Zope3/src/zope/app/file/browser/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null	Tue Feb 24 11:50:19 2004
+++ Zope3/src/zope/app/file/browser/tests/__init__.py	Tue Feb 24 11:49:49 2004
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.


=== Zope3/src/zope/app/file/browser/tests/test_imagedata.py 1.1 => 1.2 ===
--- /dev/null	Tue Feb 24 11:50:20 2004
+++ Zope3/src/zope/app/file/browser/tests/test_imagedata.py	Tue Feb 24 11:49:49 2004
@@ -0,0 +1,66 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+
+import unittest
+
+from zope.app.file.image import Image
+from zope.app.file.browser.image import ImageData
+
+class Test(unittest.TestCase):
+
+    def testData(self):
+        """ """
+        image = Image('Data')
+        id = ImageData(image, None)
+        self.assertEqual(id(), 'Data')
+
+    def testTag(self):
+        """ """
+
+        # We need that, sinc eabsolute_url is not implemented yet.
+        def absolute_url():
+            return '/img'
+
+        image = Image()
+        fe = ImageData(image, None)
+        fe.absolute_url = 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" />')
+
+
+def test_suite():
+    loader = unittest.TestLoader()
+    return loader.loadTestsFromTestCase(Test)
+
+if __name__=='__main__':
+    unittest.main()


=== Zope3/src/zope/app/file/browser/tests/test_imageupload.py 1.1 => 1.2 ===
--- /dev/null	Tue Feb 24 11:50:20 2004
+++ Zope3/src/zope/app/file/browser/tests/test_imageupload.py	Tue Feb 24 11:49:49 2004
@@ -0,0 +1,114 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+#
+##############################################################################
+"""XXX short summary goes here.
+
+XXX longer description goes here.
+
+$Id$
+"""
+
+import os
+import unittest
+
+from zope.app.tests import ztapi
+from zope.app.browser.form.editview import EditView
+from zope.app.browser.form.widget import BytesWidget, BytesAreaWidget
+from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.publisher.browser import TestRequest
+from zope.schema.interfaces import IField, IBytesLine, IBytes
+
+import zope.app.file.browser # for __file__
+from zope.app.file.image import Image, IImage
+from zope.app.file.browser.image import ImageUpload
+
+
+class IU(ImageUpload, EditView):
+    schema = IImage
+
+
+class Test(PlacelessSetup, unittest.TestCase):
+
+    def setUp(self):
+        super(Test, self).setUp()
+
+        # Configure the widget views
+        ztapi.setDefaultViewName(IField, 'edit')
+        ztapi.browserView(IBytesLine, 'edit', BytesWidget)
+        ztapi.browserView(IBytes, 'edit', BytesAreaWidget)
+
+        icondir = os.path.split(zope.app.file.browser.__file__)[0]
+        data = open(os.path.join(icondir, 'image_icon.gif'), 'rb').read()
+        image = Image(data)
+        self.__view = IU(image, TestRequest())
+
+    def test_size(self):
+        self.assertEqual(self.__view.size(), "16 x 16 pixels, 1 KB")
+
+    def test_apply_update_no_data(self):
+        view = self.__view
+        ct = view.context.contentType
+        data = view.context.data
+        d = {}
+        self.failUnless(view.apply_update(d))
+        self.assertEqual(view.context.contentType, ct)
+        self.assertEqual(view.context.data, data)
+        d = {'contentType': 'image/gif'}
+        self.failUnless(view.apply_update(d))
+        self.assertEqual(view.context.contentType, ct)
+        self.assertEqual(view.context.data, data)
+
+    def test_apply_update_new_contentType(self):
+        view = self.__view
+        view.context.contentType = 'foo/bar'
+        self.assertEqual(view.context.contentType, 'foo/bar')
+        data = view.context.data
+        d = {'contentType': 'xxx/yyy'}
+        self.failIf(view.apply_update(d))
+        self.assertEqual(view.context.contentType, 'xxx/yyy')
+        self.assertEqual(view.context.data, data)
+
+    def test_apply_update_new_data(self):
+        view = self.__view
+        gifdata = view.context.data
+        view.context.contentType = 'foo/bar'
+        view.context.data = ''
+        ct = view.context.contentType
+        self.assertEqual(ct, 'foo/bar')
+        data = view.context.data
+        self.assertEqual(data, '')
+        d = {'data': gifdata}
+        self.failIf(view.apply_update(d))
+        self.assertEqual(view.context.contentType, 'image/gif')
+        self.assertEqual(view.context.data, gifdata)
+
+    def test_apply_update_new_data_and_new_ct(self):
+        view = self.__view
+        gifdata = view.context.data
+        view.context.contentType = 'foo/bar'
+        view.context.data = ''
+        ct = view.context.contentType
+        self.assertEqual(ct, 'foo/bar')
+        data = view.context.data
+        self.assertEqual(data, '')
+        d = {'contentType': 'xxx/yyy', 'data': gifdata}
+        self.failIf(view.apply_update(d))
+        self.assertEqual(view.context.contentType, 'image/gif')
+        self.assertEqual(view.context.data, gifdata)
+
+
+def test_suite():
+    return unittest.makeSuite(Test)
+
+if __name__=='__main__':
+    unittest.main(defaultTest='test_suite')




More information about the Zope3-Checkins mailing list