Exemplo n.º 1
0
    def testMenuItemNeedsFor(self):
	# <browser:menuItem> directive fails if no 'for' argument was provided
	from zope.configuration.exceptions import ConfigurationError
        self.assertRaises(ConfigurationError, xmlconfig, StringIO(template %
            '''
            <browser:menu
                id="test_menu" title="Test menu" />
	    <browser:menuItem
	        title="Test Entry"
	        menu="test_menu"
		action="@@test"
		/>
            '''
            ))

	# it works, when the argument is there and a valid interface
	xmlconfig(StringIO(template %
            '''
	    <browser:menuItem
                for="zope.app.component.tests.views.IC"
	        title="Test Entry"
	        menu="test_menu"
		action="@@test"
		/>
            '''
	    ))
Exemplo n.º 2
0
    def testTraversalOfPageForViewWithPublishTraverse(self):
        """Tests proper traversal of a page defined for a view.

        This test is different from testTraversalOfPageForView in that it
        tests the behavior on a view that has a publishTraverse method --
        the implementation of the lookup is slightly different in such a
        case.
        """
        xmlconfig(
            StringIO(template % u'''
            <browser:view
                name="test"
                class="zope.browserpage.tests.test_page.VT"
                for="zope.browserpage.tests.test_page.IC"
                permission="zope.Public" />

            <browser:page name="index.html"
                for="zope.browserpage.tests.test_page.IV"
                class="zope.browserpage.tests.test_page.CV"
                permission="zope.Public" />
            '''))

        view = component.getMultiAdapter((ob, self.request), name='test')
        view = removeSecurityProxy(view)
        view.publishTraverse(self.request, 'index.html')
Exemplo n.º 3
0
    def test_page_menu_within_different_layers(self):
        path = os.path.join(tests_path, 'testfiles', 'test.pt')
        self.assertEqual(
            component.queryMultiAdapter((ob, self.request), name='index.html'),
            None)

        xmlconfig(
            StringIO(template % u'''
            <browser:menu
                id="test_menu"
                title="Test menu"
                interface="zope.browserpage.tests.test_page.ITestMenu"/>

            <browser:page
                name="index.html"
                permission="zope.Public"
                for="zope.browserpage.tests.test_page.IC"
                template="%s"
                menu="test_menu" title="Index"/>

            <browser:page
                name="index.html"
                permission="zope.Public"
                for="zope.browserpage.tests.test_page.IC"
                menu="test_menu" title="Index"
                template="%s"
                layer="zope.browserpage.tests.test_page.ITestLayer"/>
            ''' % (path, path)))

        v = component.getMultiAdapter((ob, self.request), name='index.html')
        self.assertEqual(v().strip(), '<html><body><p>test</p></body></html>')
    def testPluggableFactory(self):
        class ImageResource(object):
            def __init__(self, image, request):
                pass

        class ImageResourceFactory(object):
            def __init__(self, path, checker, name):
                pass

            def __call__(self, request):
                return ImageResource(None, request)

        from zope.browserresource.interfaces import IResourceFactoryFactory
        component.provideUtility(ImageResourceFactory,
                                 IResourceFactoryFactory,
                                 name='gif')

        xmlconfig(
            StringIO(template % '''
            <browser:resource
                name="test.gif"
                file="%s"
                />
            ''' % os.path.join(tests_path, 'testfiles', 'test.gif')))

        r = component.getAdapter(request, name='test.gif')
        self.assertTrue(isinstance(r, ImageResource))
Exemplo n.º 5
0
    def testPageInPagesWithClassWithMenu(self):
        self.assertEqual(
            component.queryMultiAdapter((ob, self.request), name='test'), None)
        testtemplate = os.path.join(tests_path, 'testfiles', 'test.pt')

        xmlconfig(
            StringIO(template % ('''
            <browser:menu
                id="test_menu" title="Test menu" />
            <browser:pages
                for="zope.browserpage.tests.test_page.IC"
                class="zope.browserpage.tests.test_page.V1"
                permission="zope.Public">
              <browser:page
                  name="test"
                  template="%s"
                  menu="test_menu"
                  title="Test View"
                  />
            </browser:pages>
            ''' % testtemplate)))

        menuItem = getFirstMenuItem('test_menu', ob, TestRequest())
        self.assertEqual(menuItem["title"], "Test View")
        self.assertEqual(menuItem["action"], "@@test")
        v = component.queryMultiAdapter((ob, self.request), name='test')
        self.assertEqual(v().replace('\r\n', '\n'),
                         "<html><body><p>test</p></body></html>\n")
Exemplo n.º 6
0
    def testNamedViewPageViewsCustomTraversr(self):
        self.assertEqual(zapi.queryMultiAdapter((ob, request), name='test'),
                         None)

        xmlconfig(StringIO(template %
            '''
            <browser:view
                name="test"
                class="zope.app.publisher.browser.tests.test_directives.V1"
                for="zope.app.component.tests.views.IC"
                permission="zope.Public"
                >

              <browser:page name="index.html" attribute="index" />
              <browser:page name="action.html" attribute="action" />
            </browser:view>
            '''
            ))

        view = zapi.getMultiAdapter((ob, request), name='test')
        view = removeSecurityProxy(view)
        self.assertEqual(view.browserDefault(request)[1], (u'index.html', ))


        v = view.publishTraverse(request, 'index.html')
        v = removeSecurityProxy(v)
        self.assertEqual(v(), 'V1 here')
        v = view.publishTraverse(request, 'action.html')
        v = removeSecurityProxy(v)
        self.assertEqual(v(), 'done')
Exemplo n.º 7
0
    def testProtectedNamedViewPageViews(self):
        self.assertEqual(zapi.queryMultiAdapter((ob, request), name='test'),
                         None)

        xmlconfig(StringIO(template %
            '''
            <include package="zope.app.security" file="meta.zcml" />

            <permission id="zope.TestPermission" title="Test permission" />

            <browser:view
                name="test"
                class="zope.app.component.tests.views.V1"
                for="zope.app.component.tests.views.IC"
                permission="zope.Public"
                >
             
              <browser:page name="index.html" attribute="index" />
              <browser:page name="action.html" attribute="action" />
            </browser:view>
            '''
            ))

        view = zapi.getMultiAdapter((ob, request), name='test')
        self.assertEqual(view.browserDefault(request)[1], (u'index.html', ))

        v = view.publishTraverse(request, 'index.html')
        self.assertEqual(v(), 'V1 here')
Exemplo n.º 8
0
    def testAddForm(self):
        self.assertEqual(
            component.queryMultiAdapter((ob, request), name='add.html'), None)
        xmlconfig(
            StringIO(template % ("""
          <view
              type="zope.publisher.interfaces.browser.IBrowserRequest"
              for="zope.schema.interfaces.ITextLine"
              provides="zope.formlib.interfaces.IInputWidget"
              factory="zope.app.form.browser.TextWidget"
              permission="zope.Public"
              />

          <browser:addform
              for="zope.app.form.browser.tests.test_directives.IC"
              schema="zope.app.form.browser.tests.test_directives.Schema"
              name="add.html"
              label="Add a ZPT page"
              fields="text"
              permission="zope.Public" />
            """)))

        v = component.getMultiAdapter((ob, request), name='add.html')
        # expect to fail as standard macros are not configured
        self.assertRaises(TraversalError, v)
Exemplo n.º 9
0
    def testSchemaDisplay(self):
        self.assertEqual(
            zapi.queryMultiAdapter((ob, request), name='view.html'),
            None)
        xmlconfig(StringIO(template % ('''
          <view
              type="zope.publisher.interfaces.browser.IBrowserRequest"
              for="zope.schema.interfaces.IField"
              provides="zope.app.form.interfaces.IDisplayWidget"
              factory="zope.app.form.browser.DisplayWidget"
              permission="zope.Public"
              />

          <browser:schemadisplay
              for="zope.app.form.browser.tests.test_directives.IC"
              schema="zope.app.form.browser.tests.test_directives.Schema"
              name="view.html"
              label="View a ZPT page"
              fields="text"
              permission="zope.Public" />
            ''')))

        v = zapi.queryMultiAdapter((ob, request), name='view.html')
        # expect to fail as standard macros are not configured
        self.assertRaises(TraversalError, v)
Exemplo n.º 10
0
    def testSchemaDisplay(self):
        self.assertEqual(
            component.queryMultiAdapter((ob, request), name='view.html'), None)
        xmlconfig(
            StringIO(template % ('''
          <view
              type="zope.publisher.interfaces.browser.IBrowserRequest"
              for="zope.schema.interfaces.IField"
              provides="zope.formlib.interfaces.IDisplayWidget"
              factory="zope.app.form.browser.DisplayWidget"
              permission="zope.Public"
              />

          <browser:schemadisplay
              for="zope.app.form.browser.tests.test_directives.IC"
              schema="zope.app.form.browser.tests.test_directives.Schema"
              name="view.html"
              label="View a ZPT page"
              fields="text"
              permission="zope.Public" />
            ''')))

        v = component.queryMultiAdapter((ob, request), name='view.html')
        # expect to fail as standard macros are not configured
        self.assertRaises(TraversalError, v)
Exemplo n.º 11
0
    def testSchemaDisplayWithWidget(self):
        self.assertEqual(
            component.queryMultiAdapter((ob, request), name='view.html'), None)
        xmlconfig(
            StringIO(template % ('''
          <view
              type="zope.publisher.interfaces.browser.IBrowserRequest"
              for="zope.schema.interfaces.IField"
              provides="zope.formlib.interfaces.IDisplayWidget"
              factory="zope.app.form.browser.DisplayWidget"
              permission="zope.Public"
              />

          <browser:schemadisplay
              for="zope.app.form.browser.tests.test_directives.IC"
              schema="zope.app.form.browser.tests.test_directives.Schema"
              name="view.html"
              label="View a ZPT page"
              fields="text"
              permission="zope.Public">

            <browser:widget
                field="text"
                class="zope.app.form.browser.tests.test_directives.SomeWidget"
                displayWidth="30"
                extra="foo"
                />
          </browser:schemadisplay>
            ''')))

        view = component.queryMultiAdapter((ob, request), name='view.html')
        self.assert_(hasattr(view, 'text_widget'))
        self.assert_(isinstance(view.text_widget, SomeWidget))
        self.assertEqual(view.text_widget.extra, u'foo')
        self.assertEqual(view.text_widget.displayWidth, 30)
Exemplo n.º 12
0
    def testEditFormWithMenu(self):
        self.assertEqual(
            component.queryMultiAdapter((ob, request), name='edit.html'), None)
        xmlconfig(
            StringIO(template % ('''
          <browser:menu id="test_menu" title="Test menu"/>
          <view
              type="zope.publisher.interfaces.browser.IBrowserRequest"
              for="zope.schema.interfaces.ITextLine"
              provides="zope.formlib.interfaces.IInputWidget"
              factory="zope.app.form.browser.TextWidget"
              permission="zope.Public"
              />
          <browser:editform
              for="zope.app.form.browser.tests.test_directives.IC"
              schema="zope.app.form.browser.tests.test_directives.Schema"
              name="edit.html"
              label="Edit a ZPT page"
              fields="text"
              permission="zope.Public"
              menu="test_menu"
              title="Test View"
              />
            ''')))

        v = component.queryMultiAdapter((ob, request), name='edit.html')
        # expect to fail as standard macros are not configured
        self.assertRaises(TraversalError, v)
Exemplo n.º 13
0
    def testMenuItemNeedsFor(self):
        # <browser:menuItem> directive fails if no 'for' argument was provided
        from zope.configuration.exceptions import ConfigurationError
        self.assertRaises(
            ConfigurationError, xmlconfig,
            StringIO(template % '''
            <browser:menu
                id="test_menu" title="Test menu" />
            <browser:menuItem
                title="Test Entry"
                menu="test_menu"
                action="@@test"
            />
            '''))

        # it works, when the argument is there and a valid interface
        xmlconfig(
            StringIO(template % '''
            <browser:menuItem
                for="zope.component.testfiles.views.IC"
                title="Test Entry"
                menu="test_menu"
                action="@@test"
            />
            '''))
Exemplo n.º 14
0
    def testMenuOverride(self):
        self.assertEqual(
            component.queryMultiAdapter((ob, request), name='test'), None)

        xmlconfig(
            StringIO(template % ('''
            <browser:menu
                id="test_menu" title="Test menu" />
            <browser:menuItem
                action="@@test"
                for="zope.component.testfiles.views.IC"
                permission="zope.Public"
                menu="test_menu"
                title="Test View"
                />
            ''')))
        menu1 = component.getUtility(IBrowserMenu, 'test_menu')
        menuItem1 = getFirstMenuItem('test_menu', ob, TestRequest())
        xmlconfig(
            StringIO(template % ('''
            <browser:menu
                id="test_menu" title="Test menu"
                class="zope.browsermenu.tests.test_directives.M1" />
            ''')))
        menu2 = component.getUtility(IBrowserMenu, 'test_menu')
        menuItem2 = getFirstMenuItem('test_menu', ob, TestRequest())
        self.assertNotEqual(menu1, menu2)
        self.assertEqual(menuItem1, menuItem2)
Exemplo n.º 15
0
    def testDefaultViewWithLayer(self):
        class FakeRequest(TestRequest):
            implements(ITestLayer)
        request2 = FakeRequest()

        self.assertEqual(
            zapi.queryMultiAdapter((ob, request2), IDefaultViewName),
            None)

        xmlconfig(StringIO(template % (
            '''
            <browser:defaultView
                name="test"
                for="zope.app.component.tests.views.IC" />

            <browser:defaultView
                name="test2"
                for="zope.app.component.tests.views.IC"
                layer="
                  zope.app.publisher.browser.tests.test_directives.ITestLayer"
                />
            '''
            )))

        self.assertEqual(zapi.getDefaultViewName(ob, request2), 'test2')
        self.assertEqual(zapi.getDefaultViewName(ob, request), 'test')
Exemplo n.º 16
0
    def testSchemaDisplayWithWidget(self):
        self.assertEqual(
            zapi.queryMultiAdapter((ob, request), name='view.html'),
            None)
        xmlconfig(StringIO(template % ('''
          <view
              type="zope.publisher.interfaces.browser.IBrowserRequest"
              for="zope.schema.interfaces.IField"
              provides="zope.app.form.interfaces.IDisplayWidget"
              factory="zope.app.form.browser.DisplayWidget"
              permission="zope.Public"
              />

          <browser:schemadisplay
              for="zope.app.form.browser.tests.test_directives.IC"
              schema="zope.app.form.browser.tests.test_directives.Schema"
              name="view.html"
              label="View a ZPT page"
              fields="text"
              permission="zope.Public">

            <browser:widget
                field="text"
                class="zope.app.form.browser.tests.test_directives.SomeWidget"
                displayWidth="30"
                extra="foo"
                />
          </browser:schemadisplay>
            ''')))

        view = zapi.queryMultiAdapter((ob, request), name='view.html')
        self.assert_(hasattr(view, 'text_widget'))
        self.assert_(isinstance(view.text_widget, SomeWidget))
        self.assertEqual(view.text_widget.extra, u'foo')
        self.assertEqual(view.text_widget.displayWidth, 30)
Exemplo n.º 17
0
    def testSkinPage(self):
        self.assertEqual(zapi.queryMultiAdapter((ob, request), name='test'),
                         None)

        xmlconfig(StringIO(template % (
            '''
            <browser:layer name="zmi" />
            <browser:skin name="zmi" layers="zmi" />
            <browser:page name="test"
                class="zope.app.component.tests.views.VZMI"
                layer="zmi"
                for="zope.app.component.tests.views.IC"
                permission="zope.Public"
                attribute="index"
                />
            <browser:page name="test"
                class="zope.app.component.tests.views.V1"
                for="zope.app.component.tests.views.IC"
                permission="zope.Public"
                attribute="index"
                />
            '''
            )))

        v = zapi.queryMultiAdapter((ob, request), name='test')
        self.assert_(issubclass(v.__class__, V1))
        zmi = zapi.getUtility(ISkin, 'zmi')
        v = zapi.queryMultiAdapter((ob, TestRequest(skin=zmi)), name='test')
        self.assert_(issubclass(v.__class__, VZMI))
Exemplo n.º 18
0
    def testAddForm(self):
        self.assertEqual(
            zapi.queryMultiAdapter((ob, request), name='add.html'),
            None)
        xmlconfig(StringIO(template % ("""
          <view
              type="zope.publisher.interfaces.browser.IBrowserRequest"
              for="zope.schema.interfaces.ITextLine"
              provides="zope.app.form.interfaces.IInputWidget"
              factory="zope.app.form.browser.TextWidget"
              permission="zope.Public"
              />

          <browser:addform
              for="zope.app.form.browser.tests.test_directives.IC"
              schema="zope.app.form.browser.tests.test_directives.Schema"
              name="add.html"
              label="Add a ZPT page"
              fields="text"
              permission="zope.Public" />
            """)))

        v = zapi.getMultiAdapter((ob, request), name='add.html')
        # expect to fail as standard macros are not configured
        self.assertRaises(TraversalError, v)
Exemplo n.º 19
0
    def testTraversalOfPageForViewWithPublishTraverse(self):
        """Tests proper traversal of a page defined for a view.
        
        This test is different from testTraversalOfPageForView in that it
        tests the behavior on a view that has a publishTraverse method --
        the implementation of the lookup is slightly different in such a
        case.
        """
        xmlconfig(StringIO(template %
            '''
            <browser:view
                name="test"
                class="zope.app.publisher.browser.tests.test_directives.VT"
                for="zope.app.component.tests.views.IC"
                permission="zope.Public" />

            <browser:page name="index.html"
                for="zope.app.component.tests.views.IV" 
                class="zope.app.publisher.browser.tests.test_directives.CV"
                permission="zope.Public" />
            '''
            ))

        view = zapi.getMultiAdapter((ob, request), name='test')
        view = removeSecurityProxy(view)
        view.publishTraverse(request, 'index.html')
Exemplo n.º 20
0
    def testFile(self):
        from zope.security.interfaces import ForbiddenAttribute
        path = os.path.join(tests_path, 'testfiles', 'test.pt')

        self.assertEqual(component.queryAdapter(request, name='test'), None)

        xmlconfig(
            StringIO(template % '''
            <browser:resource
                name="index.html"
                file="%s"
                />
            ''' % path))

        unwrapped_r = component.getAdapter(request, name='index.html')
        self.assertTrue(isinstance(unwrapped_r, FileResource))
        r = ProxyFactory(unwrapped_r)
        self.assertEqual(r.__name__, "index.html")

        # Make sure we can access available attrs and not others
        for n in ('GET', 'HEAD', 'publishTraverse', 'request', '__call__'):
            getattr(r, n)

        self.assertRaises(ForbiddenAttribute, getattr, r, '_testData')

        with open(path, 'rb') as f:
            self.assertEqual(unwrapped_r._testData(), f.read())
Exemplo n.º 21
0
    def testFile(self):
        path = os.path.join(tests_path, 'testfiles', 'test.pt')

        self.assertEqual(zapi.queryAdapter(request, name='test'), None)

        xmlconfig(StringIO(template %
            '''
            <browser:resource
                name="index.html"
                file="%s"
                />
            ''' % path
            ))

        r = zapi.getAdapter(request, name='index.html')
        self.assertEquals(r.__class__, FileResource)
        r = ProxyFactory(r)
        self.assertEqual(r.__name__, "index.html")

        # Make sure we can access available attrs and not others
        for n in ('GET', 'HEAD', 'publishTraverse', 'request', '__call__'):
            getattr(r, n)
        self.assertEqual(r.__name__, "index.html")

        self.assertRaises(Exception, getattr, r, '_testData')

        r = removeSecurityProxy(r)
        self.assert_(r.__class__ is FileResource)
        self.assertEqual(r._testData(), open(path, 'rb').read())
Exemplo n.º 22
0
    def testResource(self):
        self.assertEqual(
            component.queryMultiAdapter((ob, request), name='zmi_icon'), None)

        import zope.app.publisher.browser.tests as p
        path = os.path.dirname(p.__file__)
        path = os.path.join(path, 'testfiles', 'test.gif')

        xmlconfig(
            StringIO(template % ('''
            <browser:resource name="zmi_icon_res"
                      image="%s" />
            <browser:icon name="zmi_icon"
                      for="zope.app.component.tests.views.IC"
                      resource="zmi_icon_res" />
            ''' % path)))

        view = component.getMultiAdapter((ob, request), name='zmi_icon')
        rname = "zmi_icon_res"
        self.assertEqual(
            view(), '<img src="http://127.0.0.1/@@/%s" alt="IC" width="16" '
            'height="16" border="0" />' % rname)

        resource = ProxyFactory(component.getAdapter(request, name=rname))

        self.assertRaises(Forbidden, getattr, resource, '_testData')
        resource = removeSecurityProxy(resource)
        self.assertEqual(resource._testData(), open(path, 'rb').read())
Exemplo n.º 23
0
    def testI18nResource(self):
        self.assertEqual(component.queryAdapter(request, name='test'), None)

        path1 = os.path.join(tests_path, 'testfiles', 'test.pt')
        path2 = os.path.join(tests_path, 'testfiles', 'test2.pt')

        xmlconfig(
            StringIO(template % ('''
            <browser:i18n-resource name="test" defaultLanguage="fr">
              <browser:translation language="en" file="%s" />
              <browser:translation language="fr" file="%s" />
            </browser:i18n-resource>
            ''' % (path1, path2))))

        v = component.getAdapter(request, name='test')
        self.assertEqual(
            component.queryAdapter(request, name='test').__class__,
            I18nFileResource)
        self.assertEqual(v._testData('en'), open(path1, 'rb').read())
        self.assertEqual(v._testData('fr'), open(path2, 'rb').read())

        # translation must be provided for the default language
        config = StringIO(template % ('''
            <browser:i18n-resource name="test" defaultLanguage="fr">
              <browser:translation language="en" file="%s" />
              <browser:translation language="lt" file="%s" />
            </browser:i18n-resource>
            ''' % (path1, path2)))
        self.assertRaises(ConfigurationError, xmlconfig, config)
Exemplo n.º 24
0
    def testPluggableFactory(self):

        class ImageResource(object):
            def __init__(self, image, request):
                pass

        class ImageResourceFactory(object):
            def __init__(self, path, checker, name):
                pass
            def __call__(self, request):
                return ImageResource(None, request)

        from zope.browserresource.interfaces import IResourceFactoryFactory
        component.provideUtility(ImageResourceFactory, IResourceFactoryFactory,
                                 name='gif')

        xmlconfig(StringIO(template %
            '''
            <browser:resource
                name="test.gif"
                file="%s"
                />
            ''' % os.path.join(tests_path, 'testfiles', 'test.gif')
            ))

        r = component.getAdapter(request, name='test.gif')
        self.assertTrue(isinstance(r, ImageResource))
Exemplo n.º 25
0
    def testPageViews(self):
        self.assertEqual(
            component.queryMultiAdapter((ob, self.request), name='test'), None)
        test3 = os.path.join(tests_path, 'testfiles', 'test3.pt')

        xmlconfig(
            StringIO(template % u'''
            <browser:pages
                class="zope.browserpage.tests.test_page.V1"
                for="zope.browserpage.tests.test_page.IC"
                permission="zope.Public"
                >

              <browser:page name="index.html" attribute="index" />
              <browser:page name="action.html" attribute="action" />
              <browser:page name="test.html" template="%s" />
            </browser:pages>
            ''' % test3))

        v = component.getMultiAdapter((ob, self.request), name='index.html')
        self.assertEqual(v(), 'V1 here')
        v = component.getMultiAdapter((ob, self.request), name='action.html')
        self.assertEqual(v(), 'done')
        v = component.getMultiAdapter((ob, self.request), name='test.html')
        self.assertEqual(
            str(v()).replace('\r\n', '\n'),
            "<html><body><p>done</p></body></html>\n")
Exemplo n.º 26
0
    def testDirectory(self):
        path = os.path.join(tests_path, 'testfiles', 'subdir')

        self.assertEqual(component.queryAdapter(request, name='dir'), None)

        xmlconfig(StringIO(template %
            '''
            <browser:resourceDirectory
                name="dir"
                directory="%s"
                />
            ''' % path
            ))

        r = component.getAdapter(request, name='dir')
        self.assertTrue(isinstance(r, DirectoryResource))
        r = ProxyFactory(r)
        self.assertEqual(r.__name__, "dir")

        # Make sure we can access available attrs and not others
        for n in ('publishTraverse', 'browserDefault', 'request', '__call__',
                  'get', '__getitem__'):
            getattr(r, n)

        self.assertRaises(Exception, getattr, r, 'directory_factory')

        inexistent_dir = StringIO(template %
            '''
            <browser:resourceDirectory
                name="dir"
                directory="does-not-exist"
                />
            ''')

        self.assertRaises(ConfigurationError, xmlconfig, inexistent_dir)
Exemplo n.º 27
0
    def testProtectedNamedViewPageViews(self):
        self.assertEqual(
            component.queryMultiAdapter((ob, self.request), name='test'), None)

        xmlconfig(
            StringIO(template % u'''
            <include package="zope.security" file="meta.zcml" />

            <permission id="zope.TestPermission" title="Test permission" />

            <browser:view
                name="test"
                class="zope.browserpage.tests.test_page.V1"
                for="zope.browserpage.tests.test_page.IC"
                permission="zope.Public"
                >

              <browser:page name="index.html" attribute="index" />
              <browser:page name="action.html" attribute="action" />
            </browser:view>
            '''))

        view = component.getMultiAdapter((ob, self.request), name='test')
        self.assertEqual(
            view.browserDefault(self.request)[1], (u'index.html', ))

        v = view.publishTraverse(self.request, 'index.html')
        self.assertEqual(v(), 'V1 here')
Exemplo n.º 28
0
    def testI18nResource(self):
        self.assertEqual(component.queryAdapter(request, name='test'), None)

        path1 = os.path.join(tests_path, 'testfiles', 'test.pt')
        path2 = os.path.join(tests_path, 'testfiles', 'test2.pt')

        xmlconfig(StringIO(template % (
            '''
            <browser:i18n-resource name="test" defaultLanguage="fr">
              <browser:translation language="en" file="%s" />
              <browser:translation language="fr" file="%s" />
            </browser:i18n-resource>
            ''' % (path1, path2)
            )))

        v = component.getAdapter(request, name='test')
        self.assertEqual(
            component.queryAdapter(request, name='test').__class__,
            I18nFileResource)
        self.assertEqual(v._testData('en'), open(path1, 'rb').read())
        self.assertEqual(v._testData('fr'), open(path2, 'rb').read())

        # translation must be provided for the default language
        config = StringIO(template % (
            '''
            <browser:i18n-resource name="test" defaultLanguage="fr">
              <browser:translation language="en" file="%s" />
              <browser:translation language="lt" file="%s" />
            </browser:i18n-resource>
            ''' % (path1, path2)
            ))
        self.assertRaises(ConfigurationError, xmlconfig, config)
Exemplo n.º 29
0
    def testSkinPage(self):
        self.assertEqual(
            component.queryMultiAdapter((ob, request), name='test'), None)

        xmlconfig(
            StringIO(template % ('''
            <browser:page name="test"
                class="zope.app.component.tests.views.VZMI"
                layer="
                  zope.app.publisher.browser.tests.test_directives.ITestLayer"
                for="zope.app.component.tests.views.IC"
                permission="zope.Public"
                attribute="index"
                />
            <browser:page name="test"
                class="zope.app.component.tests.views.V1"
                for="zope.app.component.tests.views.IC"
                permission="zope.Public"
                attribute="index"
                />
            ''')))

        v = component.queryMultiAdapter((ob, request), name='test')
        self.assert_(issubclass(v.__class__, V1))
        v = component.queryMultiAdapter((ob, TestRequest(skin=ITestSkin)),
                                        name='test')
        self.assert_(issubclass(v.__class__, VZMI))
Exemplo n.º 30
0
    def register_RelationsType(self):
        xmlconfig.xmlconfig(StringIO(
            '''
            <configure
                 package="plone.behavior"
                 xmlns="http://namespaces.zope.org/zope"
                 xmlns:plone="http://namespaces.plone.org/plone"
                 i18n_domain="plone.behavior.tests">

                 <include package="plone.behavior" file="meta.zcml" />

                <plone:behavior
                    title="Relations behavior"
                    description="A behavior"
                    provides="plone.app.versioningbehavior.tests.test_modifiers.IRelationsBehavior"
                    />
            </configure>
            '''
        ))
        rel_fti = DexterityFTI(
            'RelationsType',
            behaviors=[IRelationsBehavior.__identifier__]
        )
        self.portal.portal_types._setObject('RelationsType', rel_fti)

        # Setup IIntIds utility which is required for relations to work
        site.add_intids(self.portal)
Exemplo n.º 31
0
    def testPageInPagesWithClassWithMenu(self):
        self.assertEqual(zapi.queryMultiAdapter((ob, request), name='test'),
                         None)
        testtemplate = os.path.join(tests_path, 'testfiles', 'test.pt')
                         

        xmlconfig(StringIO(template % (
            '''
            <browser:menu
                id="test_menu" title="Test menu" />
            <browser:pages
                for="zope.app.component.tests.views.IC"
                class="zope.app.component.tests.views.V1"
                permission="zope.Public">
              <browser:page
                  name="test"
                  template="%s" 
                  menu="test_menu"
                  title="Test View"
                  />
            </browser:pages>                  
            ''' % testtemplate
            )))

        menuItem = getFirstMenuItem('test_menu', ob, TestRequest())
        self.assertEqual(menuItem["title"], "Test View")
        self.assertEqual(menuItem["action"], "@@test")
        v = zapi.queryMultiAdapter((ob, request), name='test')
        self.assertEqual(v(), "<html><body><p>test</p></body></html>\n")
    def testAllow(self):
        f = configfile("""
<content class="zope.app.component.tests.exampleclass.ExampleClass">
    <allow attributes="anAttribute anotherAttribute" />
</content>
                       """)
        xmlconfig(f)
Exemplo n.º 33
0
    def testDefaultSkin(self):
        request = TestRequest()

        self.assertEqual(zapi.queryMultiAdapter((ob, request), name='test'),
                         None)
        xmlconfig(StringIO(template % (
            '''
            <browser:layer name="zmi" />
            <browser:skin name="zmi" layers="zmi" />
            <browser:defaultSkin name="zmi" />
            <browser:page name="test"
                class="zope.app.component.tests.views.VZMI"
                layer="zmi"
                for="zope.app.component.tests.views.IC"
                permission="zope.Public"
                attribute="index"
                />
            <browser:page name="test"
                class="zope.app.component.tests.views.V1"
                for="zope.app.component.tests.views.IC"
                permission="zope.Public"
                attribute="index"
                />
            '''
            )))

        # Simulate Zope Publication behavior in beforeTraversal()
        adapters = zapi.getSiteManager().adapters
        skin = adapters.lookup((providedBy(request),), IDefaultSkin, '')
        directlyProvides(request, skin)

        v = zapi.queryMultiAdapter((ob, request), name='test')
        self.assert_(issubclass(v.__class__, VZMI))
    def testMimic(self):
        f = configfile("""
<content class="zope.app.component.tests.exampleclass.ExampleClass">
    <require like_class="zope.app.component.tests.exampleclass.ExampleClass" />
</content>
                       """)
        xmlconfig(f)
Exemplo n.º 35
0
    def testPageViews(self):
        self.assertEqual(zapi.queryMultiAdapter((ob, request), name='test'),
                         None)
        test3 = os.path.join(tests_path, 'testfiles', 'test3.pt')

        xmlconfig(StringIO(template %
            '''
            <browser:pages
                class="zope.app.component.tests.views.V1"
                for="zope.app.component.tests.views.IC"
                permission="zope.Public"
                >

              <browser:page name="index.html" attribute="index" />
              <browser:page name="action.html" attribute="action" />
              <browser:page name="test.html" template="%s" />
            </browser:pages>
            ''' % test3
            ))

        v = zapi.getMultiAdapter((ob, request), name='index.html')
        self.assertEqual(v(), 'V1 here')
        v = zapi.getMultiAdapter((ob, request), name='action.html')
        self.assertEqual(v(), 'done')
        v = zapi.getMultiAdapter((ob, request), name='test.html')
        self.assertEqual(str(v()), '<html><body><p>done</p></body></html>\n')
Exemplo n.º 36
0
    def testNamedViewPageViewsWithDefault(self):
        self.assertEqual(
            component.queryMultiAdapter((ob, request), name='test'), None)
        test3 = os.path.join(tests_path, 'testfiles', 'test3.pt')

        xmlconfig(
            StringIO(template % '''
            <browser:view
                name="test"
                class="zope.component.testfiles.views.V1"
                for="zope.component.testfiles.views.IC"
                permission="zope.Public"
                >

              <browser:defaultPage name="test.html" />
              <browser:page name="index.html" attribute="index" />
              <browser:page name="action.html" attribute="action" />
              <browser:page name="test.html" template="%s" />
            </browser:view>
            ''' % test3))

        view = component.getMultiAdapter((ob, request), name='test')
        view = removeSecurityProxy(view)
        self.assertEqual(view.browserDefault(request)[1], (u'test.html', ))

        v = view.publishTraverse(request, 'index.html')
        v = removeSecurityProxy(v)
        self.assertEqual(v(), 'V1 here')
        v = view.publishTraverse(request, 'action.html')
        v = removeSecurityProxy(v)
        self.assertEqual(v(), 'done')
        v = view.publishTraverse(request, 'test.html')
        v = removeSecurityProxy(v)
        self.assertEqual(str(v()), '<html><body><p>done</p></body></html>\n')
Exemplo n.º 37
0
    def testNamedViewPageViewsNoDefault(self):
        self.assertEqual(zapi.queryMultiAdapter((ob, request), name='test'),
                         None)
        test3 = os.path.join(tests_path, 'testfiles', 'test3.pt')

        xmlconfig(StringIO(template %
            '''
            <browser:view
                name="test"
                class="zope.app.component.tests.views.V1"
                for="zope.app.component.tests.views.IC"
                permission="zope.Public"
                >

              <browser:page name="index.html" attribute="index" />
              <browser:page name="action.html" attribute="action" />
              <browser:page name="test.html" template="%s" />
            </browser:view>
            ''' % test3
            ))

        view = zapi.getMultiAdapter((ob, request), name='test')
        view = removeSecurityProxy(view)
        self.assertEqual(view.browserDefault(request)[1], (u'index.html', ))


        v = view.publishTraverse(request, 'index.html')
        v = removeSecurityProxy(v)
        self.assertEqual(v(), 'V1 here')
        v = view.publishTraverse(request, 'action.html')
        v = removeSecurityProxy(v)
        self.assertEqual(v(), 'done')
        v = view.publishTraverse(request, 'test.html')
        v = removeSecurityProxy(v)
        self.assertEqual(str(v()), '<html><body><p>done</p></body></html>\n')
Exemplo n.º 38
0
    def testViewThatProvidesAnInterface(self):
        request = TestRequest()
        self.assertEqual(
            component.queryMultiAdapter((ob, request), IV, name='test'), None)

        xmlconfig(
            StringIO(template % '''
            <browser:view
                name="test"
                class="zope.component.testfiles.views.V1"
                for="zope.component.testfiles.views.IC"
                permission="zope.Public"
                />
            '''))

        v = component.queryMultiAdapter((ob, request), IV, name='test')
        self.assertEqual(v, None)

        xmlconfig(
            StringIO(template % '''
            <browser:view
                name="test"
                class="zope.component.testfiles.views.V1"
                for="zope.component.testfiles.views.IC"
                provides="zope.component.testfiles.views.IV"
                permission="zope.Public"
                />
            '''))

        v = component.queryMultiAdapter((ob, request), IV, name='test')
        self.assert_(isinstance(v, V1))
Exemplo n.º 39
0
    def testProtectedPageViews(self):
        ztapi.provideUtility(IPermission, Permission('p', 'P'), 'p')

        request = TestRequest()
        self.assertEqual(zapi.queryMultiAdapter((ob, request), name='test'),
                         None)

        xmlconfig(StringIO(template %
            '''
            <include package="zope.app.security" file="meta.zcml" />
            
            <permission id="zope.TestPermission" title="Test permission" />

            <browser:pages
                class="zope.app.component.tests.views.V1"
                for="zope.app.component.tests.views.IC"
                permission="zope.TestPermission"
                >
             
              <browser:page name="index.html" attribute="index" />
              <browser:page name="action.html" attribute="action" />
            </browser:pages>
            '''
            ))

        v = zapi.getMultiAdapter((ob, request), name='index.html')
        v = ProxyFactory(v)
        zope.security.management.getInteraction().add(request)
        self.assertRaises(Exception, v)
        v = zapi.getMultiAdapter((ob, request), name='action.html')
        v = ProxyFactory(v)
        self.assertRaises(Exception, v)
Exemplo n.º 40
0
    def setUp(self):
        self.root = DummyContext()
        zope.component.testing.setUp()
        xmlconfig.XMLConfig('meta.zcml', zope.component)()
        xmlconfig.XMLConfig('configure.zcml', zope.traversing)()
        xmlconfig.XMLConfig('configure.zcml', zope.publisher)()
        try:
            xmlconfig.XMLConfig('configure.zcml', zope.i18n)()
        except IOError:
            # Zope 2.10
            xmlconfig.xmlconfig(
                StringIO('''
            <configure xmlns="http://namespaces.zope.org/zope">
               <utility
                  provides="zope.i18n.interfaces.INegotiator"
                  component="zope.i18n.negotiator.negotiator" />

               <include package="zope.i18n.locales" />
            </configure>
             '''))
        xmlconfig.XMLConfig('meta.zcml', zope.i18n)()
        xmlconfig.XMLConfig('meta.zcml', zope.browserresource)()
        xmlconfig.XMLConfig('meta.zcml', z3c.form)()
        xmlconfig.XMLConfig('configure.zcml',
                            collective.z3cform.datetimewidget)()
Exemplo n.º 41
0
    def testSkinnedPageView(self):
        self.assertEqual(zapi.queryMultiAdapter((ob, request), name='test'),
                         None)

        xmlconfig(StringIO(template %
            '''
            <browser:layer name="layer" />
            <browser:skin name="skinny" layers="layer" />
            <browser:pages
                for="*"
                class="zope.app.component.tests.views.V1"
                permission="zope.Public"
                >
             
              <browser:page name="index.html" attribute="index" />
            </browser:pages>
            <browser:pages
                for="*"
                class="zope.app.component.tests.views.V1"
                layer="layer"
                permission="zope.Public"
                >
            
              <browser:page name="index.html" attribute="action" />
            </browser:pages>
            '''
            ))

        v = zapi.getMultiAdapter((ob, request), name='index.html')
        self.assertEqual(v(), 'V1 here')
        skinny = zapi.getUtility(ISkin, 'skinny')
        v = zapi.getMultiAdapter((ob, TestRequest(skin=skinny)),
                                 name='index.html')
        self.assertEqual(v(), 'done')
Exemplo n.º 42
0
def demo_multiadapters(load_zcml):
    print "=====[ Demo multi adapters ]======="

    if load_zcml:
        from zope.configuration.xmlconfig import xmlconfig
        fname = __file__[:-3] + '.zcml'
        xmlconfig(open(fname))
    else:
        register()

    img = me.Image()
    page = me.Page()
    multi_page = me.MultiPageDocument()

    left_column = PortletManagerLeftColumn('left')

    print list(left_column.get_portlets(img))
    #[(u'generic portlet', <GenericPortlet on left for <__main__.Image object at 0x177fdd0>>),
    # (u'image portlet', <ImagePortlet on left for <__main__.Image object at 0x177fdd0>>)]

    gsm = getGlobalSiteManager()
    gsm.registerAdapter(me.PagePortlet,
                       (me.IPortletManager, me.Page),
                        name="page portlet")

    print list(left_column.get_portlets(page))
    # [(u'generic portlet', <GenericPortlet on left for <__main__.Page object at 0x2652e10>>),
    #  (u'page portlet', <PagePortlet on left for <__main__.Page object at 0x2652e10>>)]

    print list(left_column.get_portlets(multi_page))
    # [(u'generic portlet', <GenericPortlet on left for <__main__.MultiPageDocument object at 0x2652e50>>),
    #  (u'page portlet', <PagePortlet on left for <__main__.MultiPageDocument object at 0x2652e50>>)]

    print list(left_column.get_portlets(img))
Exemplo n.º 43
0
    def testFile(self):
        path = os.path.join(tests_path, 'testfiles', 'test.pt')

        self.assertEqual(component.queryAdapter(request, name='test'), None)

        xmlconfig(
            StringIO(template % '''
            <browser:resource
                name="index.html"
                file="%s"
                />
            ''' % path))

        r = component.getAdapter(request, name='index.html')
        self.assertTrue(isinstance(r, FileResource))
        r = ProxyFactory(r)
        self.assertEqual(r.__name__, "index.html")

        # Make sure we can access available attrs and not others
        for n in ('GET', 'HEAD', 'publishTraverse', 'request', '__call__'):
            getattr(r, n)

        self.assertRaises(Exception, getattr, r, '_testData')

        r = removeSecurityProxy(r)
        self.assertEqual(r._testData(), open(path, 'rb').read())
Exemplo n.º 44
0
    def testAllow(self):
        f = configfile("""
<class class="zope.security.tests.exampleclass.ExampleClass">
    <allow attributes="anAttribute anotherAttribute" />
</class>
                       """)
        xmlconfig(f)
Exemplo n.º 45
0
    def testDirectory(self):
        path = os.path.join(tests_path, 'testfiles', 'subdir')

        self.assertEqual(component.queryAdapter(request, name='dir'), None)

        xmlconfig(
            StringIO(template % '''
            <browser:resourceDirectory
                name="dir"
                directory="%s"
                />
            ''' % path))

        r = component.getAdapter(request, name='dir')
        self.assertTrue(isinstance(r, DirectoryResource))
        r = ProxyFactory(r)
        self.assertEqual(r.__name__, "dir")

        # Make sure we can access available attrs and not others
        for n in ('publishTraverse', 'browserDefault', 'request', '__call__',
                  'get', '__getitem__'):
            getattr(r, n)

        self.assertRaises(Exception, getattr, r, 'directory_factory')

        inexistent_dir = StringIO(template % '''
            <browser:resourceDirectory
                name="dir"
                directory="does-not-exist"
                />
            ''')

        self.assertRaises(ConfigurationError, xmlconfig, inexistent_dir)
Exemplo n.º 46
0
    def testMimic(self):
        f = configfile("""
<class class="zope.security.tests.exampleclass.ExampleClass">
    <require like_class="zope.security.tests.exampleclass.ExampleClass" />
</class>
                       """)
        xmlconfig(f)
Exemplo n.º 47
0
    def testMulImplements(self):
        from zope.component.interface import queryInterface
        from zope.configuration.xmlconfig import xmlconfig
        from zope.security.tests.exampleclass import ExampleClass
        from zope.security.tests.exampleclass import IExample
        from zope.security.tests.exampleclass import IExample2
        self._meta()
        self.assertEqual(
            queryInterface("zope.security.tests.exampleclass.IExample"), None)
        self.assertEqual(
            queryInterface("zope.security.tests.exampleclass.IExample2"), None)

        f = configfile("""
<class class="zope.security.tests.exampleclass.ExampleClass">
  <implements interface="
           zope.security.tests.exampleclass.IExample
           zope.security.tests.exampleclass.IExample2
                       " />
</class>
                       """)
        xmlconfig(f)
        self.assertTrue(IExample.implementedBy(ExampleClass))
        self.assertTrue(IExample2.implementedBy(ExampleClass))

        self.assertEqual(
            queryInterface("zope.security.tests.exampleclass.IExample"),
            IExample)
        self.assertEqual(
            queryInterface("zope.security.tests.exampleclass.IExample2"),
            IExample2)
Exemplo n.º 48
0
def demo_events(load_zcml):
    gsm = getGlobalSiteManager()

    if load_zcml:
        from zope.configuration.xmlconfig import xmlconfig
        fname = __file__[:-3] + '.zcml'
        xmlconfig(open(fname))
    else:
        gsm.registerHandler(me.handle_some_event)
        gsm.registerHandler(me.handle_object_modified_event,
                            [me.IData, me.IObjectModifiedEvent])

    obj = me.Data()
    evt = me.SomeEvent()
    evt.object = obj

    if load_zcml:
        notify(evt)
    else:
        handle(evt)

    assert obj.data == 'changed'

    obj.data = 'unchanged'

    if load_zcml:
        notify(me.ObjectModifiedEvent(obj))
    else:
        objectEventNotify(me.ObjectModifiedEvent(obj))

    assert obj.data == 'changed'

    print "Done"
Exemplo n.º 49
0
    def testSkinPage(self):
        self.assertEqual(
            component.queryMultiAdapter((ob, self.request), name='test'), None)

        xmlconfig(
            StringIO(template % u'''
            <browser:page name="test"
                class="zope.browserpage.tests.test_page.VZMI"
                for="zope.browserpage.tests.test_page.IC"
                layer="zope.browserpage.tests.test_page.ITestLayer"
                permission="zope.Public"
                attribute="index"
                />
            <browser:page name="test"
                class="zope.browserpage.tests.test_page.V1"
                for="zope.browserpage.tests.test_page.IC"
                permission="zope.Public"
                attribute="index"
                />
            '''))

        v = component.queryMultiAdapter((ob, self.request), name='test')
        self.assertTrue(issubclass(v.__class__, V1))
        v = component.queryMultiAdapter((ob, TestRequest(skin=ITestSkin)),
                                        name='test')
        self.assertTrue(issubclass(v.__class__, VZMI))
Exemplo n.º 50
0
    def testMenuOverride(self):
        self.assertEqual(
            component.queryMultiAdapter((ob, request), name='test'),
            None)

        xmlconfig(StringIO(template % (
            '''
            <browser:menu
                id="test_menu" title="Test menu" />
            <browser:menuItem
                action="@@test"
                for="zope.component.testfiles.views.IC"
                permission="zope.Public"
                menu="test_menu"
                title="Test View"
                />
            '''
            )))
        menu1 = component.getUtility(IBrowserMenu, 'test_menu')
        menuItem1 = getFirstMenuItem('test_menu', ob, TestRequest())
        xmlconfig(StringIO(template % (
            '''
            <browser:menu
                id="test_menu" title="Test menu"
                class="zope.browsermenu.tests.test_directives.M1" />
            '''
            )))
        menu2 = component.getUtility(IBrowserMenu, 'test_menu')
        menuItem2 = getFirstMenuItem('test_menu', ob, TestRequest())
        self.assertNotEqual(menu1, menu2)
        self.assertEqual(menuItem1, menuItem2)
Exemplo n.º 51
0
    def testNamedViewPageViewsCustomTraversr(self):
        self.assertEqual(
            component.queryMultiAdapter((ob, self.request), name='test'), None)

        xmlconfig(
            StringIO(template % u'''
            <browser:view
                name="test"
                class="zope.browserpage.tests.test_page.V1"
                for="zope.browserpage.tests.test_page.IC"
                permission="zope.Public"
                >

              <browser:page name="index.html" attribute="index" />
              <browser:page name="action.html" attribute="action" />
            </browser:view>
            '''))

        view = component.getMultiAdapter((ob, self.request), name='test')
        view = removeSecurityProxy(view)
        self.assertEqual(
            view.browserDefault(self.request)[1], (u'index.html', ))

        v = view.publishTraverse(self.request, 'index.html')
        v = removeSecurityProxy(v)
        self.assertEqual(v(), 'V1 here')
        v = view.publishTraverse(self.request, 'action.html')
        v = removeSecurityProxy(v)
        self.assertEqual(v(), 'done')
Exemplo n.º 52
0
    def testDefaultViewWithLayer(self):
        class FakeRequest(TestRequest):
            implements(ITestLayer)
        request2 = FakeRequest()

        self.assertEqual(
            component.queryMultiAdapter((ob, request2), IDefaultViewName),
            None)

        xmlconfig(StringIO(template % (
            '''
            <browser:defaultView
                for="zope.publisher.tests.test_zcml.IOb"
                name="test"
                />
            <browser:defaultView
                for="zope.publisher.tests.test_zcml.IOb"
                layer="zope.publisher.tests.test_zcml.ITestLayer"
                name="test2"
                />
            '''
            )))

        self.assertEqual(
            zope.publisher.defaultview.getDefaultViewName(ob, request2),
            'test2')
        self.assertEqual(
            zope.publisher.defaultview.getDefaultViewName(ob, request),
            'test')
Exemplo n.º 53
0
    def testProtectedPageViews(self):
        component.provideUtility(Permission('p', 'P'), IPermission, 'p')

        request = TestRequest()
        self.assertEqual(
            component.queryMultiAdapter((ob, request), name='test'), None)

        xmlconfig(
            StringIO(template % u'''
            <include package="zope.security" file="meta.zcml" />

            <permission id="zope.TestPermission" title="Test permission" />

            <browser:pages
                class="zope.browserpage.tests.test_page.V1"
                for="zope.browserpage.tests.test_page.IC"
                permission="zope.TestPermission"
                >

              <browser:page name="index.html" attribute="index" />
              <browser:page name="action.html" attribute="action" />
            </browser:pages>
            '''))

        v = component.getMultiAdapter((ob, request), name='index.html')
        v = ProxyFactory(v)
        zope.security.management.getInteraction().add(request)
        self.assertRaises(Exception, v)
        v = component.getMultiAdapter((ob, request), name='action.html')
        v = ProxyFactory(v)
        self.assertRaises(Exception, v)
Exemplo n.º 54
0
    def testResource(self):
        self.assertEqual(
            zapi.queryMultiAdapter((ob, request), name='zmi_icon'), None)

        import zope.app.publisher.browser.tests as p
        path = os.path.dirname(p.__file__)
        path = os.path.join(path, 'testfiles', 'test.gif')

        xmlconfig(StringIO(template % (
            '''
            <browser:resource name="zmi_icon_res"
                      image="%s" />
            <browser:icon name="zmi_icon"
                      for="zope.app.component.tests.views.IC"
                      resource="zmi_icon_res" />
            ''' % path
            )))

        view = zapi.getMultiAdapter((ob, request), name='zmi_icon')
        rname = "zmi_icon_res"
        self.assertEqual(
            view(),
            '<img src="http://127.0.0.1/@@/%s" alt="IC" width="16" '
            'height="16" border="0" />'
            % rname)

        resource = ProxyFactory(zapi.getAdapter(request, name=rname))

        self.assertRaises(Forbidden, getattr, resource, '_testData')
        resource = removeSecurityProxy(resource)
        self.assertEqual(resource._testData(), open(path, 'rb').read())
Exemplo n.º 55
0
    def testSkinnedPageView(self):
        self.assertEqual(
            component.queryMultiAdapter((ob, self.request), name='test'), None)

        xmlconfig(
            StringIO(template % u'''
            <browser:pages
                class="zope.browserpage.tests.test_page.V1"
                for="*"
                permission="zope.Public"
                >
              <browser:page name="index.html" attribute="index" />
            </browser:pages>

            <browser:pages
                class="zope.browserpage.tests.test_page.V1"
                for="*"
                layer="zope.browserpage.tests.test_page.ITestLayer"
                permission="zope.Public"
                >
              <browser:page name="index.html" attribute="action" />
            </browser:pages>
            '''))

        v = component.getMultiAdapter((ob, self.request), name='index.html')
        self.assertEqual(v(), 'V1 here')
        v = component.getMultiAdapter((ob, TestRequest(skin=ITestSkin)),
                                      name='index.html')
        self.assertEqual(v(), 'done')
Exemplo n.º 56
0
    def testUnnamedViewThatProvidesAnInterface(self):
        request = TestRequest()
        self.assertEqual(zapi.queryMultiAdapter((ob, request), IV),
                         None)

        xmlconfig(StringIO(template %
            '''
            <browser:view
                class="zope.app.component.tests.views.V1"
                for="zope.app.component.tests.views.IC"
                permission="zope.Public"
                />
            '''
            ))

        v = zapi.queryMultiAdapter((ob, request), IV)
        self.assertEqual(v, None)

        xmlconfig(StringIO(template %
            '''
            <browser:view
                class="zope.app.component.tests.views.V1"
                for="zope.app.component.tests.views.IC"
                provides="zope.app.component.tests.views.IV"
                permission="zope.Public"
                />
            '''
            ))

        v = zapi.queryMultiAdapter((ob, request), IV)

        self.assert_(isinstance(v, V1))
Exemplo n.º 57
0
    def testUnnamedViewThatProvidesAnInterface(self):
        request = TestRequest()
        self.assertEqual(component.queryMultiAdapter((ob, request), IV), None)

        xmlconfig(
            StringIO(template % u'''
            <browser:view
                class="zope.browserpage.tests.test_page.V1"
                for="zope.browserpage.tests.test_page.IC"
                permission="zope.Public"
                />
            '''))

        v = component.queryMultiAdapter((ob, request), IV)
        self.assertEqual(v, None)

        xmlconfig(
            StringIO(template % u'''
            <browser:view
                class="zope.browserpage.tests.test_page.V1"
                for="zope.browserpage.tests.test_page.IC"
                provides="zope.browserpage.tests.test_page.IV"
                permission="zope.Public"
                />
            '''))

        v = component.queryMultiAdapter((ob, request), IV)

        self.assertTrue(isinstance(v, V1))
Exemplo n.º 58
0
    def testDefaultViewWithLayer(self):
        class FakeRequest(TestRequest):
            implements(ITestLayer)

        request2 = FakeRequest()

        self.assertEqual(
            component.queryMultiAdapter((ob, request2), IDefaultViewName),
            None)

        xmlconfig(
            StringIO(template % ('''
            <browser:defaultView
                name="test"
                for="zope.app.component.tests.views.IC" />

            <browser:defaultView
                name="test2"
                for="zope.app.component.tests.views.IC"
                layer="
                  zope.app.publisher.browser.tests.test_directives.ITestLayer"
                />
            ''')))

        self.assertEqual(
            zope.app.publisher.browser.getDefaultViewName(ob, request2),
            'test2')
        self.assertEqual(
            zope.app.publisher.browser.getDefaultViewName(ob, request), 'test')