Back to index

moin  1.9.0~rc2
test_attachfile.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - tests of AttachFile action
00004 
00005     @copyright: 2007 by Karol Nowak <grywacz@gmail.com>
00006                 2007-2008 MoinMoin:ReimarBauer
00007     @license: GNU GPL, see COPYING for details.
00008 """
00009 import os, StringIO
00010 from MoinMoin.action import AttachFile
00011 from MoinMoin.PageEditor import PageEditor
00012 from MoinMoin._tests import become_trusted, create_page, nuke_page
00013 
00014 class TestAttachFile:
00015     """ testing action AttachFile"""
00016     pagename = u"AutoCreatedSillyPageToTestAttachments"
00017 
00018     def test_add_attachment(self):
00019         """Test if add_attachment() works"""
00020 
00021         become_trusted(self.request)
00022         filename = "AutoCreatedSillyAttachment"
00023 
00024         create_page(self.request, self.pagename, u"Foo!")
00025 
00026         AttachFile.add_attachment(self.request, self.pagename, filename, "Test content", True)
00027         exists = AttachFile.exists(self.request, self.pagename, filename)
00028 
00029         nuke_page(self.request, self.pagename)
00030 
00031         assert exists
00032 
00033     def test_add_attachment_for_file_object(self):
00034         """Test if add_attachment() works with file like object"""
00035 
00036         become_trusted(self.request)
00037 
00038         filename = "AutoCreatedSillyAttachment.png"
00039 
00040         create_page(self.request, self.pagename, u"FooBar!")
00041         data = "Test content"
00042 
00043         filecontent = StringIO.StringIO(data)
00044 
00045         AttachFile.add_attachment(self.request, self.pagename, filename, filecontent, True)
00046         exists = AttachFile.exists(self.request, self.pagename, filename)
00047         path = AttachFile.getAttachDir(self.request, self.pagename)
00048         imagef = os.path.join(path, filename)
00049         file_size = os.path.getsize(imagef)
00050 
00051         nuke_page(self.request, self.pagename)
00052 
00053         assert exists and file_size == len(data)
00054 
00055     def test_get_attachment_path_created_on_getFilename(self):
00056         """
00057         Tests if AttachFile.getFilename creates the attachment dir on self.requesting
00058         """
00059         become_trusted(self.request)
00060 
00061         filename = ""
00062 
00063         file_exists = os.path.exists(AttachFile.getFilename(self.request, self.pagename, filename))
00064 
00065         nuke_page(self.request, self.pagename)
00066 
00067         assert file_exists
00068 
00069 coverage_modules = ['MoinMoin.action.AttachFile']