[Zope3-checkins] CVS: Zope3/src/zope/app/content/tests - test_file.py:1.3 test_image.py:1.5 test_zptpage.py:1.7
Jim Fulton
jim@zope.com
Mon, 3 Feb 2003 10:09:38 -0500
Update of /cvs-repository/Zope3/src/zope/app/content/tests
In directory cvs.zope.org:/tmp/cvs-serv15846/src/zope/app/content/tests
Modified Files:
test_file.py test_image.py test_zptpage.py
Log Message:
Refactored the ftp framework to make it much simpler, less general,
and easier to maintain. This included ripping out the vfs framework.
=== Zope3/src/zope/app/content/tests/test_file.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/content/tests/test_file.py:1.2 Wed Dec 25 09:12:48 2002
+++ Zope3/src/zope/app/content/tests/test_file.py Mon Feb 3 10:08:34 2003
@@ -19,10 +19,25 @@
import unittest
from zope.interface.verify import verifyClass
-from zope.app.content.file import FileChunk
+from zope.app.content.file import FileChunk, FileReadFile, FileWriteFile
+class TestFileAdapters:
+
-class Test(unittest.TestCase):
+ def test_ReadFile(self):
+ file = self._makeFile()
+ content = "This is some file\ncontent."
+ file.edit(content, 'text/plain')
+ self.assertEqual(FileReadFile(file).read(), content)
+ self.assertEqual(FileReadFile(file).size(), len(content))
+
+ def test_WriteFile(self):
+ file = self._makeFile()
+ content = "This is some file\ncontent."
+ FileWriteFile(file).write(content)
+ self.assertEqual(file.getData(), content)
+
+class Test(unittest.TestCase, TestFileAdapters):
def _makeFile(self, *args, **kw):
""" """
=== Zope3/src/zope/app/content/tests/test_image.py 1.4 => 1.5 ===
--- Zope3/src/zope/app/content/tests/test_image.py:1.4 Mon Dec 30 09:02:59 2002
+++ Zope3/src/zope/app/content/tests/test_image.py Mon Feb 3 10:08:34 2003
@@ -18,11 +18,33 @@
import unittest
from zope.interface.verify import verifyClass
+import test_file
+from zope.app.content.image import Image, FileFactory
+from zope.app.content.file import File
+
+zptlogo = (
+ 'GIF89a\x10\x00\x10\x00\xd5\x00\x00\xff\xff\xff\xff\xff\xfe\xfc\xfd\xfd'
+ '\xfa\xfb\xfc\xf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xb8h\xbeb'
+ '\x00A\x00;'
+ )
class TestImage(unittest.TestCase):
def _makeImage(self, *args, **kw):
- from zope.app.content.image import Image
return Image(*args, **kw)
@@ -59,6 +81,11 @@
self.failUnless(IImage.isImplementedByInstancesOf(Image))
self.failUnless(verifyClass(IImage, Image))
+class TestFileAdapters(test_file.TestFileAdapters, unittest.TestCase):
+
+ def _makeFile(self, *args, **kw):
+ return Image(*args, **kw)
+
class DummyImage:
@@ -74,6 +101,30 @@
return self.width, self.height
+class TestFileFactory(unittest.TestCase):
+
+ def test_image(self):
+ factory = FileFactory(None)
+ f = factory("spam.txt", "image/foo", "hello world")
+ self.assert_(isinstance(f, Image), f)
+ f = factory("spam.txt", "", zptlogo)
+ self.assert_(isinstance(f, Image), f)
+
+ def test_text(self):
+ factory = FileFactory(None)
+ f = factory("spam.txt", "", "hello world")
+ self.assert_(isinstance(f, File), f)
+ self.assert_(not isinstance(f, Image), f)
+ f = factory("spam.txt", "", "\0\1\2\3\4")
+ self.assert_(isinstance(f, File), f)
+ self.assert_(not isinstance(f, Image), f)
+ f = factory("spam.txt", "text/splat", zptlogo)
+ self.assert_(isinstance(f, File), f)
+ self.assert_(not isinstance(f, Image), f)
+ f = factory("spam.txt", "application/splat", zptlogo)
+ self.assert_(isinstance(f, File), f)
+ self.assert_(not isinstance(f, Image), f)
+
class TestSized(unittest.TestCase):
def testInterface(self):
@@ -102,9 +153,12 @@
self.assertEqual(s.sizeForDisplay(), u'1 KB ?x?')
def test_suite():
- return unittest.TestSuite((unittest.makeSuite(TestImage),
- unittest.makeSuite(TestSized)
- ))
+ return unittest.TestSuite((
+ unittest.makeSuite(TestImage),
+ unittest.makeSuite(TestFileAdapters),
+ unittest.makeSuite(TestFileFactory),
+ unittest.makeSuite(TestSized)
+ ))
if __name__=='__main__':
unittest.TextTestRunner().run(test_suite())
=== Zope3/src/zope/app/content/tests/test_zptpage.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/content/tests/test_zptpage.py:1.6 Sat Jan 25 09:48:52 2003
+++ Zope3/src/zope/app/content/tests/test_zptpage.py Mon Feb 3 10:08:34 2003
@@ -22,6 +22,7 @@
from zope.interface.verify import verifyClass
from zope.exceptions import Forbidden
+import zope.app.content.zpt
from zope.app.content.zpt import ZPTPage, SearchableText
from zope.app.interfaces.content.zpt import IZPTPage
from zope.app.interfaces.index.text import ISearchableText
@@ -137,11 +138,35 @@
self.assertEqual(s.sizeForSorting(), ('line', 5))
self.assertEqual(s.sizeForDisplay(), u'5 lines')
+class TestFileEmulation(unittest.TestCase):
+
+ def test_ReadFile(self):
+ page = zope.app.content.zpt.ZPTPage()
+ content = u"<p></p>"
+ page.setSource(content)
+ f = zope.app.content.zpt.ZPTReadFile(page)
+ self.assertEqual(f.read(), content)
+ self.assertEqual(f.size(), len(content))
+
+ def test_WriteFile(self):
+ page = zope.app.content.zpt.ZPTPage()
+ f = zope.app.content.zpt.ZPTWriteFile(page)
+ content = "<p></p>"
+ f.write(content)
+ self.assertEqual(page.getSource(), content)
+
+ def test_factory(self):
+ content = "<p></p>"
+ page = zope.app.content.zpt.ZPTFactory(None)('foo', '', content)
+ self.assertEqual(page.getSource(), content)
+
def test_suite():
- return unittest.TestSuite((unittest.makeSuite(ZPTPageTests),
- unittest.makeSuite(SizedTests)
- ))
+ return unittest.TestSuite((
+ unittest.makeSuite(ZPTPageTests),
+ unittest.makeSuite(SizedTests),
+ unittest.makeSuite(TestFileEmulation),
+ ))
if __name__=='__main__':
unittest.TextTestRunner().run(test_suite())