Back to index

moin  1.9.0~rc2
test_EmbedObject.py
Go to the documentation of this file.
00001 # -*- coding: utf-8 -*-
00002 """
00003     MoinMoin - MoinMoin.macro.EmbedObject Tests
00004 
00005     @copyright: 2008 MoinMoin:ReimarBauer,
00006                 2008 MoinMoin:JohannesBerg
00007     @license: GNU GPL, see COPYING for details.
00008 """
00009 import py
00010 
00011 from MoinMoin import macro
00012 from MoinMoin.action import AttachFile
00013 
00014 from MoinMoin._tests import become_trusted, create_page, make_macro, nuke_page
00015 
00016 class TestEmbedObject:
00017     """ testing macro Action calling action raw """
00018     pagename = u'AutoCreatedMoinMoinTemporaryTestPageForEmbedObject'
00019 
00020     def setup_class(self):
00021         request = self.request
00022         pagename = self.pagename
00023         become_trusted(request)
00024         self.page = create_page(request, pagename, u"Foo")
00025         AttachFile.getAttachDir(request, pagename)
00026         test_files = [
00027             ('test.ogg', 'vorbis'),
00028             ('test.svg', 'SVG'),
00029             ('test.mpg', 'MPG'),
00030             ('test.pdf', 'PDF'),
00031             ('test.mp3', 'MP3'),
00032         ]
00033         for filename, filecontent in test_files:
00034             AttachFile.add_attachment(request, pagename, filename, filecontent, overwrite=0)
00035 
00036     def teardown_class(self):
00037         nuke_page(self.request, self.pagename)
00038 
00039     def testEmbedObjectMimetype(self):
00040         """ tests defined mimetyes """
00041         tests = [
00042             (u'test.pdf', 'application/pdf'),
00043             (u'test.svg', 'image/svg+xml'),
00044             (u'test.mpg', 'video/mpeg'),
00045             (u'test.mp3', 'audio/mpeg'),
00046         ]
00047         for filename, mimetype in tests:
00048             m = make_macro(self.request, self.page)
00049             result = m.execute('EmbedObject', filename)
00050             assert mimetype in result
00051 
00052     def testEmbedObjectDefaultValues(self):
00053         """ tests default values of macro EmbedObject """
00054         m = make_macro(self.request, self.page)
00055         filename = 'test.mpg'
00056         result = m.execute('EmbedObject', u'%s' % filename)
00057         assert '<object data="/AutoCreatedMoinMoinTemporaryTestPageForEmbedObject?action=AttachFile&amp;do=get&amp;target=test.mpg"' in result
00058         assert 'align="middle"' in result
00059         assert 'value="transparent"' in result
00060 
00061     def testEmbedObjectPercentHeight(self):
00062         """ tests a unit value for macro EmbedObject """
00063         m = make_macro(self.request, self.page)
00064         filename = 'test.mpg'
00065         height = '50 %' # also tests that space is allowed in there
00066         result = m.execute('EmbedObject', u'target=%s, height=%s' % (filename, height))
00067         assert '<object data="/AutoCreatedMoinMoinTemporaryTestPageForEmbedObject?action=AttachFile&amp;do=get&amp;target=test.mpg"' in result
00068         assert 'height="50%"' in result
00069         assert 'align="middle"' in result
00070 
00071     def testEmbedObjectFromUrl(self):
00072         """ tests using a URL for macro EmbedObject """
00073         m = make_macro(self.request, self.page)
00074         target = 'http://localhost/%s?action=AttachFile&do=view&target=test.mpg' % self.pagename
00075         result = m.execute('EmbedObject', u'target=%s, url_mimetype=video/mpeg' % target)
00076         assert '<object data="http://localhost/AutoCreatedMoinMoinTemporaryTestPageForEmbedObject?action=AttachFile&amp;do=view&amp;target=test.mpg" type="video/mpeg"' in result
00077 
00078 coverage_modules = ['MoinMoin.macro.EmbedObject']