source: publico/PortalInterlegis/produtos/il.portalinterlegis/trunk/src/il/portalinterlegis/tests/testunitboxes.py @ 6540

Última Alteração nesse arquivo desde 6540 foi 6540, incluída por mazza, 9 anos atrás

inicio da edicao do carrossel (falta concluir a interface)

File size: 2.5 KB
Linha 
1# -*- coding: utf-8 -*-
2from mock import patch
3
4from il.portalinterlegis.browser.boxes.manager import Box, DtRow
5from mock import MagicMock as Mock
6
7from differenttestcase import DifferentTestCase
8
9class TestUnitBoxes(DifferentTestCase):
10    """ Unit tests for the boxes functionality
11    """
12
13    def test_box_render_basic(self):
14
15        with patch('il.portalinterlegis.browser.boxes.manager.get_template', get_template_stub):
16
17            box = Box(IStubBox, 1)
18            box.get_data = Mock(return_value={'var': 'XXXX'})
19            context = object()
20            self.assertMultiLineEqual('''
21<div id="IStubBox_1">
22  XXXX
23</div>
24'''.strip('\n'), box(context))
25            box.get_data.assert_called_with(context)
26
27    def test_box_render_editable(self):
28        with patch('il.portalinterlegis.browser.boxes.manager.get_template', get_template_stub):
29            with patch('il.portalinterlegis.browser.boxes.manager.getSecurityManager') as security_mock:
30                security_mock.checkPermission.return_value = True
31
32                box = Box(IStubBox, 1)
33                box.get_data = Mock(return_value={'var': 'XXXX'})
34                context = object()
35                self.assertMultiLineEqual('''
36<div id="IStubBox_1" class ="editable-box" >
37  XXXX
38  <a class="editable-box-link-overlay" href="box_IStubBox_1">
39    <img src="pencil_icon.png" width="16" height="16" alt="Edite esta caixa"/>
40  </a>
41</div>
42'''.strip('\n'), box(context))
43                box.get_data.assert_called_with(context)
44
45    def test_row_structure(self):
46        context = object()
47
48        self.assertMultiLineEqual('''
49  <div class="dt-row">
50    <div class="dt-cell dt-position-0 dt-width-1">
51      AAA
52    </div>
53    <div class="dt-cell dt-position-1 dt-width-2">
54      BBB
55    </div>
56    <div class="dt-cell dt-position-3 dt-width-3">
57      CCC
58    </div>
59    <div class="dt-cell dt-position-6 dt-width-1">
60      DDD
61    </div>
62  </div>
63'''.strip('\n'), DtRow((1, Mock(return_value="AAA")),
64           (2, Mock(return_value="BBB")),
65           (3, Mock(return_value="CCC")),
66           (1, Mock(return_value="DDD"))).render(context))
67
68
69class IStubBox(object):
70    pass
71
72from jinja2 import Template
73def get_template_stub(name):
74    if name == "istubbox.html":
75        return Template("{{var}}")
76    elif name == "basebox.html":
77        from il.portalinterlegis.browser.boxes.manager import _template_factory
78        return _template_factory.get_template(name)
79    else:
80        raise AssertionError("Unexpected name: [%s]" % name)
Note: Veja TracBrowser para ajuda no uso do navegador do trac.
 

The contents and data of this website are published under license:
Creative Commons 4.0 Brasil - Atribuir Fonte - Compartilhar Igual.