view MoinMoin/action/_tests/ @ 2886:dbd445620f9d

test_Attachfile: getFilename checked for creating attachments dir
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Wed, 03 Oct 2007 10:47:31 +0200
parents 8ae20e588337
children 7f07db1306d1
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
    MoinMoin - tests of AttachFile action

    @copyright: 2007 by Karol Nowak <>
    @license: GNU GPL, see COPYING for details.
import os
from MoinMoin.action import AttachFile
from MoinMoin.PageEditor import PageEditor
from MoinMoin._tests.common import gain_superuser_rights

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

    pagename = "AutoCreatedSillyPageToTestAttachments"
    filename = "AutoCreatedSillyAttachment"

    editor = PageEditor(request, pagename)
    editor.saveText("Test text!", 0)

    print "First of all, no exceptions should be raised!"
    AttachFile.add_attachment(request, pagename, filename, "Test content", True)

    print "The save attachment should actually exist!"
    assert AttachFile.exists(request, pagename, filename)

def test_get_attachment_path_created_on_getFilename(request):
    Tests if AttachFile.getFilename creates the attachment dir on requesting
    pagename = "ThisPageDoesOnlyExistForThisTest"
    filename = ""
    result = os.path.exists(AttachFile.getFilename(request, pagename, filename))
    expect = True

    # real delete pagename from filesystem
    import shutil
    page = PageEditor(request, pagename, do_editor_backup=0)
    fpath = page.getPagePath(check_create=0)
    shutil.rmtree(fpath, True)

    assert expect == result