示例#1
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")
示例#2
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')
示例#3
0
    def addObject(self):
        request = self.request
        if IContainerNamesContainer.providedBy(self.context):
            new = ""
        else:
            new = request["new_value"]

        adding = zapi.queryMultiAdapter((self.context, self.request), name="+")
        if adding is None:
            adding = Adding(self.context, request)
        else:
            # Set up context so that the adding can build a url
            # if the type name names a view.
            # Note that we can't so this for the "adding is None" case
            # above, because there is no "+" view.
            adding.__parent__ = self.context
            adding.__name__ = '+'

        adding.action(request['type_name'], new)
示例#4
0
    def addObject(self):
        request = self.request
        if IContainerNamesContainer.providedBy(self.context):
            new = ""
        else:
            new = request["new_value"]

        adding = queryMultiAdapter((self.context, self.request), name="+")
        if adding is None:
            adding = Adding(self.context, request)
        else:
            # Set up context so that the adding can build a url
            # if the type name names a view.
            # Note that we can't so this for the "adding is None" case
            # above, because there is no "+" view.
            adding.__parent__ = self.context
            adding.__name__ = '+'

        adding.action(request['type_name'], new)
示例#5
0
    def testAction(self):
        # make a private factory
        ztapi.provideUtility(IFactory, Factory(), 'fooprivate')

        factory = Factory()
        factory.__Security_checker__ = zope.security.checker.NamesChecker(
            ['__call__'])
        ztapi.provideUtility(IFactory, factory, 'foo')

        container = Container()
        adding = Adding(container, TestRequest())
        adding.nextURL = lambda: '.'
        adding.nameAllowed = lambda: True

        # we can't use a private factory:
        self.assertRaises(ForbiddenAttribute,
                          adding.action,
                          type_name='fooprivate',
                          id='bar')

        # typical add - id is provided by user
        adding.action(type_name='foo', id='bar')
        self.assert_('bar' in container)

        # missing type_name
        self.assertRaises(UserError, adding.action, id='bar')

        # missing id
        self.assertRaises(KeyError, adding.action, type_name='foo')

        # bad type_name
        self.assertRaises(ComponentLookupError,
                          adding.action,
                          type_name='***',
                          id='bar')

        # alternative add - id is provided internally instead of from user
        adding.nameAllowed = lambda: False
        adding.contentName = 'baz'
        adding.action(type_name='foo')
        self.assert_('baz' in container)

        # alternative add w/missing contentName
        # Note: Passing is None as object name might be okay, if the container
        #       is able to hand out ids itself. Let's not require a content
        #       name to be specified!
        # For the container, (or really, the chooser, to choose, we have to
        # marke the container as a ContainerNamesContainer
        directlyProvides(container, IContainerNamesContainer)
        adding.contentName = None
        adding.action(type_name='foo')
        self.assert_('Content' in container)
示例#6
0
    def testAction(self):
        # make a private factory
        ztapi.provideUtility(IFactory, Factory(), 'fooprivate')

        factory = Factory()
        factory.__Security_checker__ = zope.security.checker.NamesChecker(
            ['__call__'])
        ztapi.provideUtility(IFactory, factory, 'foo')

        container = Container()
        adding = Adding(container, TestRequest())
        adding.nextURL = lambda: '.'
        adding.nameAllowed = lambda: True

        # we can't use a private factory:
        self.assertRaises(ForbiddenAttribute,
                          adding.action, type_name='fooprivate', id='bar')

        # typical add - id is provided by user
        adding.action(type_name='foo', id='bar')
        self.assert_('bar' in container)

        # missing type_name
        self.assertRaises(UserError, adding.action, id='bar')

        # missing id
        self.assertRaises(KeyError, adding.action, type_name='foo')

        # bad type_name
        self.assertRaises(ComponentLookupError, adding.action,
            type_name='***', id='bar')

        # alternative add - id is provided internally instead of from user
        adding.nameAllowed = lambda: False
        adding.contentName = 'baz'
        adding.action(type_name='foo')
        self.assert_('baz' in container)

        # alternative add w/missing contentName
        # Note: Passing is None as object name might be okay, if the container
        #       is able to hand out ids itself. Let's not require a content
        #       name to be specified!
        # For the container, (or really, the chooser, to choose, we have to
        # marke the container as a ContainerNamesContainer
        directlyProvides(container, IContainerNamesContainer)
        adding.contentName = None
        adding.action(type_name='foo')
        self.assert_('Content' in container)