view MoinMoin/action/_tests/ @ 5098:ff588e9e24d6

simplify getAttachUrl: remove upload parameter upload=x didn't influence drawing url generation at all, for file url generation one can just give do='upload_form' if one wants the upload url. URL args for do='upload_form' were streamlined to use target=x instead of rename=x so it is more similar to the other code. Removed test for "tainted" file names in URLs. We must not "taint" file names for URLs. Filenames in URLs need to be url-quoted. If a URL is used in html, it needs to be escaped.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 13 Sep 2009 00:06:04 +0200
parents e6190a499a7e
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
    MoinMoin - tests of AttachFile action

    @copyright: 2007 by Karol Nowak <>
                2007-2008 MoinMoin:ReimarBauer
    @license: GNU GPL, see COPYING for details.
import os, StringIO
from MoinMoin.action import AttachFile
from MoinMoin.PageEditor import PageEditor
from MoinMoin._tests import become_trusted, create_page, nuke_page

class TestAttachFile:
    """ testing action AttachFile"""
    pagename = u"AutoCreatedSillyPageToTestAttachments"

    def test_add_attachment(self):
        """Test if add_attachment() works"""

        filename = "AutoCreatedSillyAttachment"

        create_page(self.request, self.pagename, u"Foo!")

        AttachFile.add_attachment(self.request, self.pagename, filename, "Test content", True)
        exists = AttachFile.exists(self.request, self.pagename, filename)

        nuke_page(self.request, self.pagename)

        assert exists

    def test_add_attachment_for_file_object(self):
        """Test if add_attachment() works with file like object"""


        filename = "AutoCreatedSillyAttachment.png"

        create_page(self.request, self.pagename, u"FooBar!")
        data = "Test content"

        filecontent = StringIO.StringIO(data)

        AttachFile.add_attachment(self.request, self.pagename, filename, filecontent, True)
        exists = AttachFile.exists(self.request, self.pagename, filename)
        path = AttachFile.getAttachDir(self.request, self.pagename)
        imagef = os.path.join(path, filename)
        file_size = os.path.getsize(imagef)

        nuke_page(self.request, self.pagename)

        assert exists and file_size == len(data)

    def test_get_attachment_path_created_on_getFilename(self):
        Tests if AttachFile.getFilename creates the attachment dir on self.requesting

        filename = ""

        file_exists = os.path.exists(AttachFile.getFilename(self.request, self.pagename, filename))

        nuke_page(self.request, self.pagename)

        assert file_exists

coverage_modules = ['MoinMoin.action.AttachFile']