~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/macro/_tests/test_EmbedObject.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
"""
 
3
    MoinMoin - MoinMoin.macro.EmbedObject Tests
 
4
 
 
5
    @copyright: 2008 MoinMoin:ReimarBauer,
 
6
                2008 MoinMoin:JohannesBerg
 
7
 
 
8
    @license: GNU GPL, see COPYING for details.
 
9
"""
 
10
 
 
11
import py
 
12
 
 
13
from MoinMoin import macro
 
14
from MoinMoin.action import AttachFile
 
15
 
 
16
from MoinMoin._tests import become_trusted, create_page, nuke_page
 
17
 
 
18
class TestEmbedObject:
 
19
    """ testing macro Action calling action raw """
 
20
    pagename = u'AutoCreatedMoinMoinTemporaryTestPageForEmbedObject'
 
21
 
 
22
    def setup_class(self):
 
23
        request = self.request
 
24
        pagename = self.pagename
 
25
 
 
26
        become_trusted(request)
 
27
        self.page = create_page(request, pagename, u"Foo")
 
28
 
 
29
        AttachFile.getAttachDir(request, pagename)
 
30
        test_files = [
 
31
            ('test.ogg', 'vorbis'),
 
32
            ('test.svg', 'SVG'),
 
33
            ('test.mpg', 'MPG'),
 
34
            ('test.pdf', 'PDF'),
 
35
            ('test.mp3', 'MP3'),
 
36
        ]
 
37
        for filename, filecontent in test_files:
 
38
            AttachFile.add_attachment(request, pagename, filename, filecontent, overwrite=0)
 
39
 
 
40
    def teardown_class(self):
 
41
        nuke_page(self.request, self.pagename)
 
42
 
 
43
    def _make_macro(self):
 
44
        """ Test helper """
 
45
        from MoinMoin.parser.text import Parser
 
46
        from MoinMoin.formatter.text_html import Formatter
 
47
        p = Parser("##\n", self.request)
 
48
        p.formatter = Formatter(self.request)
 
49
        p.formatter.page = self.page
 
50
        self.request.formatter = p.formatter
 
51
        p.form = self.request.form
 
52
        m = macro.Macro(p)
 
53
        return m
 
54
 
 
55
    def testEmbedObjectMimetype(self):
 
56
        """ tests defined mimetyes """
 
57
        tests = [
 
58
            (u'test.ogg', 'application/ogg'),
 
59
            (u'test.svg', 'image/svg+xml'),
 
60
            (u'test.mpg', 'video/mpeg'),
 
61
            (u'test.mp3', 'audio/mpeg'),
 
62
        ]
 
63
        for filename, mimetype in tests:
 
64
            m = self._make_macro()
 
65
            result = m.execute('EmbedObject', filename)
 
66
            assert mimetype in result
 
67
 
 
68
    def testEmbedObjectDefaultValues(self):
 
69
        """ tests default values of macro EmbedObject """
 
70
        m = self._make_macro()
 
71
        filename = 'test.ogg'
 
72
        result = m.execute('EmbedObject', u'%s' % filename)
 
73
        assert '<object data="./AutoCreatedMoinMoinTemporaryTestPageForEmbedObject?action=AttachFile&amp;do=get&amp;target=test.ogg"' in result
 
74
        assert 'align="middle"' in result
 
75
        assert 'value="transparent"' in result
 
76
 
 
77
    def testEmbedObjectPercentHeight(self):
 
78
        """ tests a unit value for macro EmbedObject """
 
79
        m = self._make_macro()
 
80
        filename = 'test.ogg'
 
81
        height = '50 %' # also tests that space is allowed in there
 
82
        result = m.execute('EmbedObject', u'target=%s, height=%s' % (filename, height))
 
83
        assert '<object data="./AutoCreatedMoinMoinTemporaryTestPageForEmbedObject?action=AttachFile&amp;do=get&amp;target=test.ogg"' in result
 
84
        assert 'height="50%"' in result
 
85
        assert 'align="middle"' in result
 
86
 
 
87
    def testEmbedObjectFromUrl(self):
 
88
        """ tests using a URL for macro EmbedObject """
 
89
        m = self._make_macro()
 
90
        target = 'http://localhost/%s?action=AttachFile&do=view&target=test.ogg' % self.pagename
 
91
        result = m.execute('EmbedObject', u'target=%s, url_mimetype=application/ogg' % target)
 
92
        assert '<object data="http://localhost/AutoCreatedMoinMoinTemporaryTestPageForEmbedObject?action=AttachFile&amp;do=view&amp;target=test.ogg" type="application/ogg"' in result
 
93
 
 
94
coverage_modules = ['MoinMoin.macro.EmbedObject']