Ejemplo n.º 1
0
    def setUp(self):
        super(CookieFunctionalTest, self).setUp()
        self.assertEqual(
                len(self.cookies.keys()), 0,
                'cookies store should be empty'
                )

        root = self.getRootFolder()

        from zope.app.zptpage.zptpage import ZPTPage

        page = ZPTPage()

        page.source = u'''<tal:tag tal:define="
        cookies python:['%s=%s'%(k,v) for k,v in request.getCookies().items()]"
        ><tal:tag tal:define="
        ignored python:cookies.sort()"
        /><span tal:replace="python:';'.join(cookies)" /></tal:tag>'''

        root['getcookies'] = page

        page = ZPTPage()

        page.source = u'''<tal:tag tal:define="
            ignored python:request.response.setCookie('bid','bval')" >
            <h1 tal:condition="ignored" />
            </tal:tag>'''

        root['setcookie'] = page
        transaction.commit()
Ejemplo n.º 2
0
 def test_ReadFile(self):
     page = ZPTPage()
     content = u"<p></p>"
     page.setSource(content)
     f = ZPTReadFile(page)
     self.assertEqual(f.read(), content)
     self.assertEqual(f.size(), len(content))
Ejemplo n.º 3
0
    def testZPTRendering(self):
        page = ZPTPage()
        page.setSource(
            u''
            '<html>'
            '<head><title tal:content="options/title">blah</title></head>'
            '<body>'
            '<a href="foo" tal:attributes="href request/URL/1">'
            '<span tal:replace="container/name">splat</span>'
            '</a></body></html>'
            )

        page = contained(page, Data(name='zope'))

        request = Data(URL={'1': 'http://foo.com/'},
                       debug=Data(showTAL=False, sourceAnnotations=False))
        out = page.render(request, title="Zope rules")
        out = ' '.join(out.split())

        self.assertEqual(
            out,
            '<html><head><title>Zope rules</title></head><body>'
            '<a href="http://foo.com/">'
            'zope'
            '</a></body></html>'
            )
Ejemplo n.º 4
0
 def test_ReadFile(self):
     page = ZPTPage()
     content = u"<p></p>"
     page.setSource(content)
     f = ZPTReadFile(page)
     self.assertEqual(f.read(), content)
     self.assertEqual(f.size(), len(content))
Ejemplo n.º 5
0
 def setUp(self):
     BrowserTestCase.setUp(self)
     page = ZPTPage()
     page.source = self.content
     page.evaluateInlineCode = True
     root = self.getRootFolder()
     root['page'] = page
     self.commit()
Ejemplo n.º 6
0
    def test_request_protected(self):
        page = ZPTPage()
        page.setSource(u'<p tal:content="python: request.__dict__" />')

        page = contained(page, Data(name='zope'))

        request = Data(debug=Data(showTAL=False, sourceAnnotations=False))
        self.assertRaises(Forbidden, page.render, request)
Ejemplo n.º 7
0
    def test_request_protected(self):
        page = ZPTPage()
        page.setSource(
            u'<p tal:content="python: request.__dict__" />'
            )

        page = contained(page, Data(name='zope'))

        request = Data(debug=Data(showTAL=False, sourceAnnotations=False))
        self.assertRaises(Forbidden, page.render, request)
Ejemplo n.º 8
0
    def testSourceView(self):
        page = ZPTPage()

        utext = u'another test\n' # The source will grow a newline if ommited
        html = u"<html><body>%s</body></html>\n" % (utext, )
        page.setSource(html, content_type='text/plain')
        request = TestRequest()

        view = zapi.getMultiAdapter((page, request), name='source.html')

        self.assertEqual(str(view), html)
        self.assertEqual(view(), html)
Ejemplo n.º 9
0
    def testSourceView(self):
        page = ZPTPage()

        utext = u'another test\n'  # The source will grow a newline if ommited
        html = u"<html><body>%s</body></html>\n" % (utext, )
        page.setSource(html, content_type='text/plain')
        request = TestRequest()

        view = getMultiAdapter((page, request), name='source.html')

        self.assertEqual(str(view), html)
        self.assertEqual(view(), html)
Ejemplo n.º 10
0
    def setUp(self):
        super(VirtualHostSessionTest, self).setUp()
        page = ZPTPage()
        page.source = u'<div>Foo</div>'
        page.evaluateInlineCode = True
        root = self.getRootFolder()
        root['folder'] = Folder()
        root['folder']['page'] = page
        self.commit()

        zope.component.provideHandler(self.accessSessionOnRootTraverse,
                       (IBeforeTraverseEvent,))
Ejemplo n.º 11
0
    def test_template_context_wrapping(self):
        class AU(BrowserView):
            def __str__(self):
                name = self.context.__name__
                if name is None:
                    return 'None'
                return name

        defineChecker(AU, NamesChecker(['__str__']))

        from zope.traversing.namespace import view
        ztapi.provideNamespaceHandler('view', view)
        ztapi.browserView(IZPTPage, 'name', AU)

        page = ZPTPage()
        page.setSource(u'<p tal:replace="template/@@name" />')
        page = contained(page, None, name='zpt')
        request = TestRequest()
        self.assertEquals(page.render(request), u'zpt')
Ejemplo n.º 12
0
    def test_template_context_wrapping(self):

        class AU(BrowserView):
            def __str__(self):
                name = self.context.__name__
                if name is None:
                    return 'None'
                return name

        defineChecker(AU, NamesChecker(['__str__']))

        from zope.app.traversing.namespace import view
        ztapi.provideNamespaceHandler('view', view)
        ztapi.browserView(IZPTPage, 'name', AU)

        page = ZPTPage()
        page.setSource(
            u'<p tal:replace="template/@@name" />'
            )
        page = contained(page, None, name='zpt')
        request = TestRequest()
        self.assertEquals(page.render(request), 'zpt\n')
Ejemplo n.º 13
0
    def testSearchableText(self):
        page = ZPTPage()
        searchableText = ISearchableText(page)

        utext = u'another test\n'  # The source will grow a newline if ommited
        html = u"<html><body>%s</body></html>\n" % (utext, )

        page.setSource(utext)
        self.failUnlessEqual(searchableText.getSearchableText(), [utext])

        page.setSource(html, content_type='text/html')
        self.assertEqual(searchableText.getSearchableText(), [utext + '\n'])

        page.setSource(html, content_type='text/plain')
        self.assertEqual(searchableText.getSearchableText(), [html])
Ejemplo n.º 14
0
    def testZPTRendering(self):
        page = ZPTPage()
        page.setSource(
            u''
            '<html>'
            '<head><title tal:content="options/title">blah</title></head>'
            '<body>'
            '<a href="foo" tal:attributes="href request/URL/1">'
            '<span tal:replace="container/name">splat</span>'
            '</a></body></html>')

        page = contained(page, Data(name='zope'))

        request = Data(URL={'1': 'http://foo.com/'},
                       debug=Data(showTAL=False, sourceAnnotations=False))
        out = page.render(request, title="Zope rules")
        out = ' '.join(out.split())

        self.assertEqual(
            out, '<html><head><title>Zope rules</title></head><body>'
            '<a href="http://foo.com/">'
            'zope'
            '</a></body></html>')
Ejemplo n.º 15
0
    def test_debug_flags(self):
        page = ZPTPage()
        page = self.pageInContext(page)
        page.setSource(u'<tal:x>Foo</tal:x>')

        request = TestRequest()
        self.assertEquals(page.render(request), u'Foo')

        request.debug.showTAL = True
        self.assertEquals(page.render(request), u'<tal:x>Foo</tal:x>')

        request.debug.showTAL = False
        request.debug.sourceAnnotations = True
        self.assertEquals(page.pt_source_file(), '/folder/zpt')
        self.assertEquals(
            page.render(request), '<!--\n' + '=' * 78 + '\n' +
            '/folder/zpt (line 1)\n' + '=' * 78 + '\n' + '-->Foo')
Ejemplo n.º 16
0
    def testSearchableText(self):
        page = ZPTPage()
        searchableText = ISearchableText(page)

        utext = u'another test\n' # The source will grow a newline if ommited
        html = u"<html><body>%s</body></html>\n" % (utext, )

        page.setSource(utext)
        self.failUnlessEqual(searchableText.getSearchableText(), [utext])

        page.setSource(html, content_type='text/html')
        self.assertEqual(searchableText.getSearchableText(), [utext+'\n'])

        page.setSource(html, content_type='text/plain')
        self.assertEqual(searchableText.getSearchableText(), [html])
Ejemplo n.º 17
0
    def test_debug_flags(self):
        page = ZPTPage()
        page = self.pageInContext(page)
        page.setSource(u'<tal:x>Foo</tal:x>')

        request = TestRequest()
        self.assertEquals(page.render(request), 'Foo\n')

        request.debug.showTAL = True
        self.assertEquals(page.render(request), '<tal:x>Foo</tal:x>\n')

        request.debug.showTAL = False
        request.debug.sourceAnnotations = True
        self.assertEquals(page.pt_source_file(), '/folder/zpt')
        self.assertEquals(page.render(request),
            '<!--\n' +
            '=' * 78 + '\n' +
            '/folder/zpt (line 1)\n' +
            '=' * 78 + '\n' +
            '-->Foo\n')
Ejemplo n.º 18
0
 def test_WriteFile(self):
     page = ZPTPage()
     f = ZPTWriteFile(page)
     content = "<p></p>"
     f.write(content)
     self.assertEqual(page.getSource(), content)
Ejemplo n.º 19
0
 def addZPTPage(self):
     zptpage = ZPTPage()
     zptpage.source = self.content
     root = self.getRootFolder()
     root['zptpage'] = zptpage
     self.commit()
Ejemplo n.º 20
0
 def test_WriteFile(self):
     page = ZPTPage()
     f = ZPTWriteFile(page)
     content = "<p></p>"
     f.write(content)
     self.assertEqual(page.getSource(), content)
Ejemplo n.º 21
0
 def addZPTPage(self):
     zptpage = ZPTPage()
     zptpage.source = self.content
     root = self.getRootFolder()
     root['zptpage'] = zptpage
     self.commit()
Ejemplo n.º 22
0
    def test_source_file(self):
        page = ZPTPage()
        self.assert_(page.pt_source_file() is None)

        page = self.pageInContext(page)
        self.assertEquals(page.pt_source_file(), '/folder/zpt')
Ejemplo n.º 23
0
 def addPage(self, path, content):
     page = ZPTPage()
     page.source = content
     self.createObject(path, page)
Ejemplo n.º 24
0
    def test_source_file(self):
        page = ZPTPage()
        self.assert_(page.pt_source_file() is None)

        page = self.pageInContext(page)
        self.assertEquals(page.pt_source_file(), '/folder/zpt')