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

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

refatoracao: eliminado BoxManager?, metodos integrados a Box

File size: 3.1 KB
Linha 
1# -*- coding: utf-8 -*-
2import unittest2 as unittest
3from mock import patch
4
5from il.portalinterlegis.browser.boxes.manager import Box, DtRow
6from itertools import count
7from mock import MagicMock as Mock
8
9diff_count = count(1)
10
11class TestUnitBoxes(unittest.TestCase):
12    """ Unit tests for the boxes functionality
13    """
14
15    def setUp(self):
16        pass
17
18    def assertMultiLineEqual(self, first, second, *args):
19        "ignores differences in leading and trailing whitespace in strings"
20        self.assert_(isinstance(first, basestring), (
21                'First argument is not a string'))
22        self.assert_(isinstance(second, basestring), (
23                'Second argument is not a string'))
24
25        first = first.strip()
26        second = second.strip()
27        if first != second:
28            c = diff_count.next()
29            for i, s in enumerate([first, second]):
30                with open("out_%s.%s" % (c, i), "w+") as f:
31                    f.write(s)
32        super(TestUnitBoxes, self).assertMultiLineEqual(first, second, *args)
33
34    def test_box_render_basic(self):
35
36        with patch('il.portalinterlegis.browser.boxes.manager.template_factory',
37                   template_factory_stub('        XXXX')):
38
39            box = Box(IStubBox, 1)
40            box.content = Mock(
41                return_value = {'var': 'XXXX'})
42            context = object()
43            self.assertMultiLineEqual('''
44      <div id="IStubBox_1">
45        XXXX
46      </div>''', box(context))
47            box.content.assert_called_with(context)
48
49    def test_box_render_editable(self):
50        with patch('il.portalinterlegis.browser.boxes.manager.template_factory',
51                   template_factory_stub('        XXXX')):
52            with patch('il.portalinterlegis.browser.boxes.manager.getSecurityManager') as security_mock:
53                security_mock.checkPermission.return_value = True
54
55                box = Box(IStubBox, 1)
56                box.content = Mock(
57                    return_value = {'var': 'XXXX'})
58                context = object()
59                self.assertMultiLineEqual('''
60      <div id="IStubBox_1" class ="editable-box">
61        XXXX
62      </div>''', box(context))
63                box.content.assert_called_with(context)
64
65    def test_row_structure(self):
66        context = object()
67
68        self.assertMultiLineEqual('''
69  <div class="dt-row">
70    <div class="dt-cell dt-position-0 dt-width-1">
71      AAA
72    </div>
73    <div class="dt-cell dt-position-1 dt-width-2">
74      BBB
75    </div>
76    <div class="dt-cell dt-position-3 dt-width-3">
77      CCC
78    </div>
79    <div class="dt-cell dt-position-6 dt-width-1">
80      DDD
81    </div>
82  </div>
83''', DtRow((1, Mock(return_value="\n      AAA")),
84           (2, Mock(return_value="\n      BBB")),
85           (3, Mock(return_value="\n      CCC")),
86           (1, Mock(return_value="\n      DDD"))).render(context))
87
88
89class IStubBox(object):
90    pass
91
92class TemplateStub(object):
93    def render(self, context):
94        return "        %(var)s" % context
95
96def template_factory_stub(value):
97    template_factory_stub = Mock()
98    template_factory_stub.get_template.return_value = TemplateStub()
99    return template_factory_stub
100
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.