changeset 3696:207ae45bab18

test_attachfile: added a test for add_attachment using a file object / removed the duplicated str using test
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Tue, 10 Jun 2008 08:44:35 +0200
parents e3b4ae470e86
children 57d85b82bc3e
files MoinMoin/action/_tests/test_attachfile.py
diffstat 1 files changed, 8 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/_tests/test_attachfile.py	Mon Jun 09 20:14:14 2008 +0200
+++ b/MoinMoin/action/_tests/test_attachfile.py	Tue Jun 10 08:44:35 2008 +0200
@@ -3,14 +3,15 @@
     MoinMoin - tests of AttachFile action
 
     @copyright: 2007 by Karol Nowak <grywacz@gmail.com>
-                     MoinMoin:ReimarBauer
+                2007-2008 MoinMoin:ReimarBauer
     @license: GNU GPL, see COPYING for details.
 """
-import os
+import os, StringIO
 from MoinMoin.action import AttachFile
 from MoinMoin.PageEditor import PageEditor
 from MoinMoin._tests import become_trusted, create_page, nuke_page
 
+
 def test_add_attachment(request):
     """Test if add_attachment() works"""
 
@@ -27,18 +28,17 @@
 
     assert exists
 
-def test_add_attachment_mimetype(request):
-    """Test if add_attachment() with small mimetype file works"""
+def test_add_attachment_for_file_object(request):
+    """Test if add_attachment() works with file like object"""
 
     become_trusted(request)
     pagename = "AutoCreatedSillyPageToTestAttachments"
     filename = "AutoCreatedSillyAttachment.png"
 
     create_page(request, pagename, u"FooBar!")
+    data = "Test content"
 
-    import base64
-    imageEncodeText = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAMCAIAAADkharWAAAAD0lEQVQokWNgGAWjgDoAAAJMAAFOlIxNAAAAAElFTkSuQmCC"
-    filecontent = base64.decodestring(imageEncodeText)
+    filecontent = StringIO.StringIO(data)
 
     AttachFile.add_attachment(request, pagename, filename, filecontent, True)
     exists = AttachFile.exists(request, pagename, filename)
@@ -48,7 +48,7 @@
 
     nuke_page(request, pagename)
 
-    assert exists and file_size == 72
+    assert exists and file_size == len(data)
 
 def test_get_attachment_path_created_on_getFilename(request):
     """