Skip to content
Browse files

added tests for #1

  • Loading branch information...
1 parent ccc5fda commit 6c56e8a1fd884bad63da1d48994d0913fe30d0e5 @garbas garbas committed Nov 25, 2012
Showing with 19 additions and 3 deletions.
  1. +3 −2 src/plone/app/blob/adapters/xmlrpc.py
  2. +16 −1 src/plone/app/blob/tests/test_adapters.py
View
5 src/plone/app/blob/adapters/xmlrpc.py
@@ -4,6 +4,7 @@
from xmlrpclib import Binary
from plone.app.blob.interfaces import IBlobbable
+from plone.app.blob.utils import guessMimetype
class BlobbableBinary(object):
@@ -22,8 +23,8 @@ def feed(self, blob):
def filename(self):
""" see interface ... """
- return None
+ return getattr(self.context, 'filename', None)
def mimetype(self):
""" see interface ... """
- return 'application/octet-stream'
+ return guessMimetype(self.context.data, self.filename())
View
17 src/plone/app/blob/tests/test_adapters.py
@@ -1,3 +1,4 @@
+import os
from unittest import defaultTestLoader
from ZODB.blob import Blob
from OFS.Image import File, Image
@@ -57,7 +58,21 @@ def testBlobbableEmptyATFile(self):
blobbable.feed(target)
def testBlobbableBinaryFile(self):
- self.assertEquals(True, False)
+ _file = os.path.join(os.path.dirname(__file__), 'data', 'image.gif')
+ f = open(_file, 'rb')
+ try:
+ obj = Binary(f)
+ obj.filename = 'image.gif'
+ blobbable = IBlobbable(obj)
+ target = Blob()
+ blobbable.feed(target)
+ self.assertEqual(target.open('r').read(),
+ getFile('image.gif').read())
+ self.assertEquals(blobbable.filename(), 'image.gif')
+ self.assertEquals(blobbable.mimetype(), 'image/gif')
+ finally:
+ f.close()
+
def test_suite():
return defaultTestLoader.loadTestsFromName(__name__)

0 comments on commit 6c56e8a

Please sign in to comment.
Something went wrong with that request. Please try again.