view MoinMoin/macro/_tests/test_EmbedObject.py @ 3268:753f234085c2

macro.EmbedObject: fixed double escaping for urls and added a unit test for urls
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 16 Mar 2008 19:24:02 +0100
parents f62792cb2d24
children 779f2ab6cb91
line wrap: on
line source
# -*- coding: utf-8 -*-
"""
    MoinMoin - MoinMoin.macro.EmbedObject Tests

    @copyright: 2008 MoinMoin:ReimarBauer,
                2008 MoinMoin:JohannesBerg

    @license: GNU GPL, see COPYING for details.
"""
import os
from MoinMoin import macro
from MoinMoin.action import AttachFile
from MoinMoin.macro import EmbedObject
from MoinMoin.Page import Page
from MoinMoin.PageEditor import PageEditor


class TestEmbedObject:
    """ testing macro Action calling action raw """

    def setup_class(self):
        self.pagename = u'AutoCreatedMoinMoinTemporaryTestPageForEmbedObject'
        self.page = PageEditor(self.request, self.pagename)
        AttachFile.getAttachDir(self.request, self.pagename)
        filename = 'test.ogg'
        filecontent = u'vorbis'
        AttachFile.add_attachment(self.request, self.pagename, filename, filecontent, overwrite=0)
        self.shouldDeleteTestPage = True

    def teardown_class(self):
        if self.shouldDeleteTestPage:
            import shutil
            page = Page(self.request, self.pagename)
            fpath = page.getPagePath(use_underlay=0, check_create=0)
            shutil.rmtree(fpath, True)

            fpath = self.request.rootpage.getPagePath('event-log', isfile=1)
            if os.path.exists(fpath):
                os.remove(fpath)

    def _make_macro(self):
        """ Test helper """
        from MoinMoin.parser.text import Parser
        from MoinMoin.formatter.text_html import Formatter
        p = Parser("##\n", self.request)
        p.formatter = Formatter(self.request)
        p.formatter.page = self.page
        self.request.formatter = p.formatter
        p.form = self.request.form
        m = macro.Macro(p)
        return m

    def _createTestPage(self, body):
        """ Create temporary page """
        assert body is not None
        self.request.reset()
        self.page.saveText(body, 0)

    def testEmbedObjectDefaultValues(self):
        """ tests default values of macro EmbedObject """
        text = '= Example ='
        self._createTestPage(text)
        m = self._make_macro()
        filename = 'test.ogg'
        result = m.execute('EmbedObject', u'%s' % filename)
        assert '<object data="./AutoCreatedMoinMoinTemporaryTestPageForEmbedObject?action=AttachFile&amp;do=get&amp;target=test.ogg"' in result
        assert 'align="middle"' in result
        assert 'value="transparent"' in result

    def testEmbedObjectPercentHeight(self):
        """ tests a unit value for macro EmbedObject """
        text = '= Example2 ='
        self._createTestPage(text)
        m = self._make_macro()
        filename = 'test.ogg'
        height = '50 %' # also tests that space is allowed in there
        result = m.execute('EmbedObject', u'target=%s, height=%s' % (filename, height))
        assert '<object data="./AutoCreatedMoinMoinTemporaryTestPageForEmbedObject?action=AttachFile&amp;do=get&amp;target=test.ogg"' in result
        assert 'height="50%"' in result
        assert 'align="middle"' in result

    def testEmbedObjectFromUrl(self):
        """ tests using a URL for macro EmbedObject """
        text = '= Example3 ='
        self._createTestPage(text)
        m = self._make_macro()
        target = 'http://localhost/%s?action=AttachFile&do=view&target=test.ogg' % self.pagename
        result = m.execute('EmbedObject', u'target=%s, url_mimetype=application/ogg' % target)
        assert '<object data="http://localhost/AutoCreatedMoinMoinTemporaryTestPageForEmbedObject?action=AttachFile&amp;do=view&amp;target=test.ogg" type="application/ogg"' in result

coverage_modules = ['MoinMoin.macro.EmbedObject']