Esempio n. 1
0
    def setUp(self):
        PlacefulSetup.setUp(self)
        # Build up a wrapper chain
        root = C('root')
        directlyProvides(root, IContainmentRoot)
        folder = C('folder')
        item = C('item')

        self.root = root  # root is not usually wrapped
        self.folder = contained(folder, self.root,   name='folder')
        self.item =   contained(item,   self.folder, name='item')
        self.unwrapped_item = item
        self.broken_chain_folder = contained(folder, None)
        self.broken_chain_item = contained(item,
                                    self.broken_chain_folder,
                                    name='item'
                                    )
        root.folder = folder
        folder.item = item

        self.tr = Traverser(root)
        ztapi.provideAdapter(
              None, ITraverser, Traverser)
        ztapi.provideAdapter(
              None, ITraversable, DefaultTraversable)
        ztapi.provideAdapter(
              None, IPhysicallyLocatable, LocationPhysicallyLocatable)
        ztapi.provideAdapter(
              IContainmentRoot, IPhysicallyLocatable, RootPhysicallyLocatable)
Esempio n. 2
0
    def testBasicContext_unicode(self):
        #Tests so that AbsoluteURL handle unicode names as well
        request = TestRequest()
        root = Root()
        root.__name__ = u'\u0439'

        content = contained(TrivialContent(), root, name=u'\u0442')
        content = contained(TrivialContent(), content, name=u'\u0435')
        content = contained(TrivialContent(), content, name=u'\u0441')
        view = zapi.getMultiAdapter((content, request), name='absolute_url')
        self.assertEqual(str(view),
                         'http://127.0.0.1/%D0%B9/%D1%82/%D0%B5/%D1%81')
        self.assertEqual(view(),
                         'http://127.0.0.1/%D0%B9/%D1%82/%D0%B5/%D1%81')
        self.assertEqual(unicode(view),
                         u'http://127.0.0.1/\u0439/\u0442/\u0435/\u0441')
        self.assertEqual(absoluteURL(content, request),
                         'http://127.0.0.1/%D0%B9/%D1%82/%D0%B5/%D1%81')

        breadcrumbs = view.breadcrumbs()
        self.assertEqual(breadcrumbs,
                         ({'name':  '', 'url': 'http://127.0.0.1'},
                          {'name': u'\u0439', 'url': 'http://127.0.0.1/%D0%B9'},
                          {'name': u'\u0442',
                           'url': 'http://127.0.0.1/%D0%B9/%D1%82'},
                          {'name': u'\u0435',
                           'url': 'http://127.0.0.1/%D0%B9/%D1%82/%D0%B5'},
                          {'name': u'\u0441',
                           'url':
                           'http://127.0.0.1/%D0%B9/%D1%82/%D0%B5/%D1%81'},
                          ))
Esempio n. 3
0
 def setUp(self):
     PlacefulSetup.setUp(self)
     # Build up a wrapper chain
     self.root =   C('root')
     self.folder = contained(C('folder'), self.root,   name='folder')
     self.item =   contained(C('item'),   self.folder, name='item')
     self.tr = Traverser(self.item)
Esempio n. 4
0
 def test_not_deletable(self):
     container = UnwritableContainer()
     container.a = 'spam'
     item = contained(UnwritableContainer(), container, name='a')
     request = TestRequest()
     delete = zope.app.http.delete.DELETE(item, request)
     self.assertRaises(MethodNotAllowed, delete.DELETE)
Esempio n. 5
0
    def test(self):
        page = DTMLPage()
        page.setSource(
            u'<html>'
            u'<head><title><dtml-var title></title></head>'
            u'<body>'
            u'<a href="<dtml-var "REQUEST.URL[\'1\']">">'
            u'<dtml-var name>'
            u'</a></body></html>'
            )

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

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


        self.assertEqual(
            out,
            u'<html><head><title>Zope rules</title></head><body>'
            u'<a href="http://foo.com/">'
            u'zope'
            u'</a></body></html>'
            )
Esempio n. 6
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>'
            )
Esempio n. 7
0
    def test(self):

        class Template(object):
            def render(self, request, **kw):
                self.called = request, kw
                request.response.setHeader('content-type', self.content_type)
                return 42

            content_type = 'text/x-test'

        class Folder(object):
            name='zope'

        folder = Folder()

        class Request(object):

            def _getResponse(self):
                return self

            response = property(_getResponse)

            def setHeader(self, name, value):
                setattr(self, name, value)

        request = Request()
        template = contained(Template(), folder, 'foo')

        view = DTMLPageEval()
        # Do manually, since directive adds BrowserView as base class
        view.context = template
        view.request = request
        self.assertEqual(view.index(request), 42)
        self.assertEqual(template.called, (request, {}))
        self.assertEqual(getattr(request, 'content-type'), 'text/x-test')
Esempio n. 8
0
    def test(self):
        setup.setUpTraversal()

        root = Root()
        f1 = contained(C(), root, name='f1')
        f2 = contained(SiteManagerContainer(), f1, name='f2')
        f3 = contained(C(), f2, name='f3')
        
        adapter = IPhysicallyLocatable(f3)

        self.assertEqual(adapter.getPath(), '/f1/f2/f3')
        self.assertEqual(adapter.getName(), 'f3')
        self.assertEqual(adapter.getRoot(), root)
        self.assertEqual(adapter.getNearestSite(), root)

        setup.createSiteManager(f2)
        self.assertEqual(adapter.getNearestSite(), f2)
Esempio n. 9
0
    def testVirtualHostingWithVHElements(self):
        request = TestRequest()

        vh_root = TrivialContent()
        content = contained(vh_root, Root(), name='a')
        request._vh_root = content
        content = contained(TrivialContent(), content, name='b')
        content = contained(TrivialContent(), content, name='c')
        view = zapi.getMultiAdapter((content, request), name='absolute_url')
        self.assertEqual(str(view), 'http://127.0.0.1/b/c')

        breadcrumbs = view.breadcrumbs()
        self.assertEqual(breadcrumbs,
         ({'name':  '', 'url': 'http://127.0.0.1'},
          {'name': 'b', 'url': 'http://127.0.0.1/b'},
          {'name': 'c', 'url': 'http://127.0.0.1/b/c'},
          ))
Esempio n. 10
0
    def testBasicContext(self):
        request = TestRequest()

        content = contained(TrivialContent(), Root(), name='a')
        content = contained(TrivialContent(), content, name='b')
        content = contained(TrivialContent(), content, name='c')
        view = zapi.getMultiAdapter((content, request), name='absolute_url')
        self.assertEqual(str(view), 'http://127.0.0.1/a/b/c')
        self.assertEqual(absoluteURL(content, request),
                         'http://127.0.0.1/a/b/c')

        breadcrumbs = view.breadcrumbs()
        self.assertEqual(breadcrumbs,
                         ({'name':  '', 'url': 'http://127.0.0.1'},
                          {'name': 'a', 'url': 'http://127.0.0.1/a'},
                          {'name': 'b', 'url': 'http://127.0.0.1/a/b'},
                          {'name': 'c', 'url': 'http://127.0.0.1/a/b/c'},
                          ))
Esempio n. 11
0
    def setUp(self):
        PlacefulSetup.setUp(self)

        ztapi.provideAdapter(
             None, ITraversable, DefaultTraversable)
        ztapi.provideAdapter(
              None, IPhysicallyLocatable, LocationPhysicallyLocatable)
        ztapi.provideAdapter(
              IContainmentRoot, IPhysicallyLocatable, RootPhysicallyLocatable)

        self.root = root = C('root')
        directlyProvides(root, IContainmentRoot)
        self.folder = folder = contained(C('folder'), root, 'folder')
        self.item = item = contained(C('item'), folder, 'item')

        root.folder = folder
        folder.item = item

        self.tr = Traverser(ProxyFactory(root))
Esempio n. 12
0
    def testRetainSkin(self):
        request = TestRequest()
        request._traversed_names = ('a', 'b')
        request._app_names = ('++skin++test', )

        content = contained(TrivialContent(), Root(), name='a')
        content = contained(TrivialContent(), content, name='b')
        content = contained(TrivialContent(), content, name='c')
        view = zapi.getMultiAdapter((content, request), name='absolute_url')
        base = 'http://127.0.0.1/++skin++test'
        self.assertEqual(str(view), base + '/a/b/c')

        breadcrumbs = view.breadcrumbs()
        self.assertEqual(breadcrumbs,
                         ({'name':  '', 'url': base + ''},
                          {'name': 'a', 'url': base + '/a'},
                          {'name': 'b', 'url': base + '/a/b'},
                          {'name': 'c', 'url': base + '/a/b/c'},
                          ))
Esempio n. 13
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)
Esempio n. 14
0
    def test(self):
        container = Container()
        container.a = 'spam'
        item = contained(Container(), container, name='a')

        request = TestRequest()
        delete = zope.app.http.delete.DELETE(item, request)
        self.assert_(hasattr(container, 'a'))
        self.assertEqual(delete.DELETE(), '')
        self.assert_(not hasattr(container, 'a'))
Esempio n. 15
0
 def tempNodeGenerator(self):
     print "tempNodeGenerator"
     retDict = {}
     parentObj = self
     for i in range(25):
         iname = u"Name %d" % i
         # Node 1
         newNodeObj = createObject(\
             "org.ict_ok.admin_utils.linux_ha.linux_ha_node.LinuxHaObjNode")
         newNodeObj.name = iname
         contained(newNodeObj, parentObj, iname)
         newNodeObj.__parent__ = parentObj
         retDict[iname] = newNodeObj
     ## Node 2
     #newNodeObj = createObject(\
     #"org.ict_ok.admin_utils.linux_ha.linux_ha_node.LinuxHaObjNode")
     #newNodeObj.name = u'Node xyz2'
     #contained(newNodeObj, parentObj, u'Node xyz2')
     #newNodeObj.__parent__ = parentObj
     #retDict[u"Node xyz2"] = newNodeObj
     return retDict
Esempio n. 16
0
 def publishTraverse(self, request, name):
     try:
         job = removeSecurityProxy(self.context.jobs[int(name)])
         # we provide a location proxy
         return contained(job, self.context, name)
     except (KeyError, ValueError):
         pass
     view = zope.component.queryMultiAdapter((self.context, request),
                                             name=name)
     if view is not None:
         return view
     raise NotFound(self.context, name, request)
Esempio n. 17
0
 def test_action(self):
     container = Container()
     container = contained(container, Root(), "container")
     request = TestRequest()
     adding = Adding(container, request)
     adding.__name__ = "+"
     ztapi.browserView(IAdding, "Thing", CreationView)
     ztapi.browserView(Interface, "absolute_url", AbsoluteURL)
     ztapi.browserView(None, "", AbsoluteURL, providing=IAbsoluteURL)
     self.assertRaises(UserError, adding.action, "", "foo")
     adding.action("Thing", "foo")
     self.assertEqual(adding.request.response.getHeader("location"), "/container/+/Thing=foo")
     adding.action("Thing/screen1", "foo")
     self.assertEqual(adding.request.response.getHeader("location"), "/container/+/Thing/screen1=foo")
Esempio n. 18
0
        def getAnnotation(context):
            annotations = IAnnotations(context)
            try:
                result = annotations[key]
            except KeyError:
                result = factory()
                annotations[key] = result

            # Containment has to be set up late to allow containment
            # proxies to be applied, if needed. This does not trigger
            # an event and is idempotent if containment is set up
            # already.
            contained_result = contained(result, context, key)
            return contained_result
Esempio n. 19
0
 def test_action(self):
     container = Container()
     container = contained(container, Root(), "container")
     request = TestRequest()
     adding = Adding(container, request)
     adding.__name__ = '+'
     ztapi.browserView(IAdding, "Thing", CreationView)
     ztapi.browserView(Interface, "absolute_url", AbsoluteURL)
     ztapi.browserView(None, '', AbsoluteURL, providing=IAbsoluteURL)
     self.assertRaises(UserError, adding.action, '', 'foo')
     adding.action('Thing', 'foo')
     self.assertEqual(adding.request.response.getHeader('location'),
                      '/container/+/Thing=foo')
     adding.action('Thing/screen1', 'foo')
     self.assertEqual(adding.request.response.getHeader('location'),
                      '/container/+/Thing/screen1=foo')
Esempio n. 20
0
    def get_EsxVimAllDict(self, localEsxUtil, parentObj):
        retDict = {}

        objFolder = createObject(\
            "org.ict_ok.admin_utils.esx_vim.esx_vim_folder.EsxVimFolder")
        objFolder.localEsxUtil = localEsxUtil
        objFolder.name = u'Datacenters'
        objFolder.esxObjectTypes = r'Datacenter'
        contained(objFolder, parentObj, u'Datacenters')
        objFolder.__parent__ = parentObj
        retDict[u"Datacenters"] = objFolder

        objFolder = createObject(\
            "org.ict_ok.admin_utils.esx_vim.esx_vim_folder.EsxVimFolder")
        objFolder.localEsxUtil = localEsxUtil
        objFolder.name = u'HostSystems'
        objFolder.esxObjectTypes = r'HostSystem'
        contained(objFolder, parentObj, u'HostSystems')
        objFolder.__parent__ = parentObj
        retDict[u'HostSystems'] = objFolder

        objFolder = createObject(\
            "org.ict_ok.admin_utils.esx_vim.esx_vim_folder.EsxVimFolder")
        objFolder.localEsxUtil = localEsxUtil
        objFolder.name = u'VirtualMachines'
        objFolder.esxObjectTypes = r'VirtualMachine'
        contained(objFolder, parentObj, u'VirtualMachines')
        objFolder.__parent__ = parentObj
        retDict[u'VirtualMachines'] = objFolder

        objFolder = createObject(\
            "org.ict_ok.admin_utils.esx_vim.esx_vim_folder.EsxVimFolder")
        objFolder.localEsxUtil = localEsxUtil
        objFolder.name = u'Folder'
        objFolder.esxObjectTypes = r'Folder'
        contained(objFolder, parentObj, u'Folder')
        objFolder.__parent__ = parentObj
        retDict[u'Folder'] = objFolder
        return retDict
Esempio n. 21
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')
Esempio n. 22
0
    def testTemplateRendering(self):
        class Template(object):
            def render(self, request, **kw):
                self.called = request, kw
                return 42

            content_type = "text/x-test"

        class Folder(object):
            name = "zope"

        folder = Folder()

        class Response(object):

            base = None

            def setBase(self, base):
                self.base = base

            def setHeader(self, name, value):
                setattr(self, name, value)

        class Request(object):

            response = Response()

            URL = ["http://localhost", "http://localhost/pt"]

        request = Request()
        template = contained(Template(), folder)

        view = ZPTPageEval()
        # Do manually, since directive adds BrowserView as base class
        view.context = template
        view.request = request
        self.assertEqual(view.index(), 42)
        self.assertEqual(template.called, (request, {}))
        self.assertEqual(getattr(request.response, "content-type"), "text/x-test")
Esempio n. 23
0
    def test_external_edit(self):
        basic = "Basic %s" % encodestring("%s:%s" % ("testuser", "testpass"))
        env = {"HTTP_AUTHORIZATION": basic}
        request = TestRequest(environ=env)
        container = zapi.traverse(self.rootFolder, "folder1")
        file = EditableFile("Foobar", "text/plain")
        self.assertEqual(file.contentType, "text/plain")
        self.assertEqual(file.data, "Foobar")
        file = contained(file, container, "file")
        view = zapi.queryMultiAdapter((file, request), name="external_edit")
        self.failIf(view is None)
        expected = (
            """\
url:http://127.0.0.1/folder1/file
content_type:text/plain
meta_type:IEditableFile
auth:%s
cookie:

Foobar"""
            % basic[:-1]
        )
        self.assertEqual(view(), expected)
Esempio n. 24
0
 def get_EsxVimObject_Dict(self, myParams, parentObj):
     """ TODO: caching here please
     """
     #print "get_EsxVimDatacenter_Dict"
     if self.esxThread is None:
         return {}
     localEsxUtil = myParams['admUtilEsxVim']
     utilOId = localEsxUtil.getObjectId()
     #print "aa12"
     #myParams = {\
     #'cmd': 'find_entity_views',
     #'view_type': 'Datacenter',
     #'admUtilEsxVim': localEsxUtil,
     #}
     #print "aa0a"
     if self.esxThread.getQueue(utilOId)['in'].join():
         pass
         #print "aa0b"
     #print "aa1"
     self.esxThread.getQueue(utilOId)['in'].put(myParams, True, 15)
     #print "aa2"
     #print "aa13:", utilOId
     self.esxThread.getQueue(utilOId)['in'].join()
     #print "aa3"
     #print "aa14"
     #self.esxThread.queue1_in.put(localEsxUtil, True, 5)
     #self.esxThread.queue1_in.join()
     esxObjList = self.esxThread.getQueue(utilOId)['out'].get(True, 15)
     #print "aa4"
     #print "esxObjList: ", esxObjList
     #print "aa15"
     self.esxThread.getQueue(utilOId)['out'].task_done()
     if len(esxObjList) == 0:
         return None
     #print "aa5"
     #print "aa16"
     retDict = {}
     for esxObj in esxObjList:
         #print "datacenter0123:", datacenter
         newObj = None
         if esxObj['esxType'] == 'Datacenter':
             newObj = createObject(\
                 "org.ict_ok.admin_utils.esx_vim.esx_vim_datacenter.EsxVimDatacenter")
         elif esxObj['esxType'] == 'HostSystem':
             newObj = createObject(\
                 "org.ict_ok.admin_utils.esx_vim.esx_vim_hostsystem.EsxVimHostSystem")
         elif esxObj['esxType'] == 'VirtualMachine':
             newObj = createObject(\
                 "org.ict_ok.admin_utils.esx_vim.esx_vim_virtual_machine.EsxVimVirtualMachine")
         elif esxObj['esxType'] == 'Folder':
             newObj = createObject(\
                 "org.ict_ok.admin_utils.esx_vim.esx_vim_folder.EsxVimFolder")
         if newObj:
             contained(newObj, parentObj, esxObj['name'])
             newObj.localEsxUtil = localEsxUtil
             newObj.overallStatus = esxObj['overallStatus']
             newObj.name = esxObj['name']
             newObj.uuid = esxObj['uuid']
             if esxObj.has_key('perlRef'):
                 newObj.perlEsxObjRef = esxObj['perlRef']
             newObj.__parent__ = parentObj
             retDict[esxObj['name']] = newObj
     return retDict
Esempio n. 25
0
 def pageInContext(self, page):
     root = Data()
     directlyProvides(root, IContainmentRoot)
     folder = contained(Data(), root, name='folder')
     return contained(page, folder, name='zpt')
Esempio n. 26
0
 def _TestView__newContext(self):
     from zope.app.container.sample import SampleContainer
     from zope.site.folder import rootFolder
     root = rootFolder()
     container = SampleContainer()
     return contained(container, root, 'sample')
Esempio n. 27
0
    def test_interface(self):
        request = TestRequest()
        content = contained(TrivialContent(), Root(), name='a')
        view = zapi.getMultiAdapter((content, request), name='absolute_url')

        verifyObject(IAbsoluteURL, view)
Esempio n. 28
0
 def _TestView__newContext(self):
     from zope.app.container.sample import SampleContainer
     from zope.app.folder import rootFolder
     root = rootFolder()
     container = SampleContainer()
     return contained(container, root, 'sample')
Esempio n. 29
0
 def testVirtualHostingWithoutContextInformation(self):
     request = TestRequest()
     request._vh_root = contained(TrivialContent(), Root(), name='a')
     view = zapi.getMultiAdapter((None, request), name='absolute_url')
     self.assertEqual(str(view), 'http://127.0.0.1')
     self.assertEqual(absoluteURL(None, request), 'http://127.0.0.1')