summaryrefslogtreecommitdiff
path: root/repoze/bfg/tests/test_push.py
blob: e8d257c034971d49185e59915139665c5760b172 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import unittest

from zope.component.testing import PlacelessSetup

class Test_pushpage(unittest.TestCase, PlacelessSetup):
    def setUp(self):
        PlacelessSetup.setUp(self)

    def tearDown(self):
        PlacelessSetup.tearDown(self)

    def _zcmlConfigure(self):
        import repoze.bfg
        import zope.configuration.xmlconfig
        zope.configuration.xmlconfig.file('configure.zcml', package=repoze.bfg)

    def _getTargetClass(self):
        from repoze.bfg.push import pushpage
        return pushpage

    def _makeOne(self, template):
        return self._getTargetClass()(template)

    def test_decorated_has_same_name_as_wrapped(self):
        pp = self._makeOne('pp.pt')
        wrapped = pp(to_wrap)
        self.assertEqual(wrapped.__name__, 'to_wrap')
        self.assertEqual(wrapped.__grok_module__, to_wrap.__module__)

    def test___call___passes_names_from_wrapped(self):
        self._zcmlConfigure()
        pp = self._makeOne('pp.pt')
        wrapped = pp(to_wrap)
        response = wrapped(object(), object())
        self.assertEqual(response.body, '<p>WRAPPED</p>\n')

def to_wrap(context, request):
    return {'wrapped': 'WRAPPED'}