changeset 3262:e30816db5cb5

add EmbedObject tests from Reimar and myself
author Johannes Berg <johannes AT sipsolutions DOT net>
date Sun, 16 Mar 2008 11:04:39 +0100
parents cbaf672bcea3
children d0ffd7c45145
files MoinMoin/macro/_tests/test_EmbedObject.py
diffstat 1 files changed, 85 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/macro/_tests/test_EmbedObject.py	Sun Mar 16 11:04:39 2008 +0100
@@ -0,0 +1,85 @@
+# -*- 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&do=get&target=test.ogg"' in result
+        assert 'height="0px"' in result
+        assert 'width="0px"' in result
+        assert 'align="middle"' in result
+
+    def testEmbedObjectPercentHeight(self):
+        """ tests default values of 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&do=get&target=test.ogg"' in result
+        assert 'height="50.000000%"' in result
+        assert 'width="0px"' in result
+        assert 'align="middle"' in result
+
+coverage_modules = ['MoinMoin.macro.EmbedObject']
+