Пример #1
0
    def setUp(self):
        self.buildFolders()

        ztapi.provideAdapter(IAnnotations, IPrincipalClipboard,
                             PrincipalClipboard)
        ztapi.provideUtility(IPrincipalAnnotationUtility,
                             PrincipalAnnotationUtility())
Пример #2
0
 def setUp(self):
     PlacefulSetup.setUp(self)
     self.rootFolder = setup.buildSampleFolderTree()
     mgr = setup.createSiteManager(self.rootFolder)
     provideInterface(id, I1)
     provideInterface(id2, I2)
     ztapi.provideAdapter(None, IIntrospector, Introspector)
Пример #3
0
    def testInfoWDublinCore(self):
        container = self._TestView__newContext()
        document = Document()
        container['document'] = document

        from datetime import datetime
        from zope.dublincore.interfaces import IZopeDublinCore
        class FauxDCAdapter(object):
            implements(IZopeDublinCore)

            __Security_checker__ = checker.Checker(
                {"created": "zope.Public",
                 "modified": "zope.Public",
                 "title": "zope.Public",
                 },
                {"title": "zope.app.dublincore.change"})

            def __init__(self, context):
                pass
            title = 'faux title'
            size = 1024
            created = datetime(2001, 1, 1, 1, 1, 1)
            modified = datetime(2002, 2, 2, 2, 2, 2)

        ztapi.provideAdapter(IDocument, IZopeDublinCore, FauxDCAdapter)

        fc = self._TestView__newView(container)
        info = fc.listContentInfo()[0]

        self.assertEqual(info['id'], 'document')
        self.assertEqual(info['url'], 'document')
        self.assertEqual(info['object'], document)
        self.assertEqual(info['title'], 'faux title')
        self.assertEqual(info['created'], '01/01/01 01:01')
        self.assertEqual(info['modified'], '02/02/02 02:02')
Пример #4
0
    def testTransactionAnnotation(self):
        from zope.interface import directlyProvides
        from zope.location.traversing import LocationPhysicallyLocatable
        from zope.location.interfaces import ILocation
        from zope.traversing.interfaces import IPhysicallyLocatable
        from zope.traversing.interfaces import IContainmentRoot
        ztapi.provideAdapter(ILocation, IPhysicallyLocatable,
                             LocationPhysicallyLocatable)

        root = self.db.open().root()
        root['foo'] = foo = LocatableObject()
        root['bar'] = bar = LocatableObject()
        bar.__name__ = 'bar'
        foo.__name__ = 'foo'
        bar.__parent__ = foo
        foo.__parent__ = root
        directlyProvides(root, IContainmentRoot)

        from zope.publisher.interfaces import IRequest
        expected_path = "/foo/bar"
        expected_user = "******" + self.user.id
        expected_request = IRequest.__module__ + '.' + IRequest.getName()

        self.publication.afterCall(self.request, bar)
        txn_info = self.storage.undoInfo()[0]
        self.assertEqual(txn_info['location'], expected_path)
        self.assertEqual(txn_info['user_name'], expected_user)
        self.assertEqual(txn_info['request_type'], expected_request)

        # also, assert that we still get the right location when
        # passing an instance method as object.
        self.publication.afterCall(self.request, bar.foo)
        self.assertEqual(txn_info['location'], expected_path)
Пример #5
0
def sessionSetUp(session_data_container_class=PersistentSessionDataContainer):
    placelesssetup.setUp()
    ztapi.provideAdapter(IRequest, IClientId, TestClientId)
    ztapi.provideAdapter(IRequest, ISession, Session)
    ztapi.provideUtility(IClientIdManager, CookieClientIdManager())
    sdc = session_data_container_class()
    ztapi.provideUtility(ISessionDataContainer, sdc, '')
Пример #6
0
def sessionSetUp(session_data_container_class=PersistentSessionDataContainer):
    placelesssetup.setUp()
    ztapi.provideAdapter(IRequest, IClientId, TestClientId)
    ztapi.provideAdapter(IRequest, ISession, Session)
    ztapi.provideUtility(IClientIdManager, CookieClientIdManager())
    sdc = session_data_container_class()
    ztapi.provideUtility(ISessionDataContainer, sdc, '')
Пример #7
0
def setUpBasicWidgets(test):
    testing.setUp(test)
    ztapi.provideAdapter((IChoice, Interface, Interface), IInputWidget, DropdownWidget)
    ztapi.provideAdapter((IChoice, Interface), IInputWidget, ChoiceInputWidget)
    ztapi.provideAdapter((ISet, IChoice, Interface), IInputWidget, ChoiceCollectionInputWidget)
    ztapi.provideAdapter((ISet, Interface, Interface), IInputWidget, MultiSelectSetWidget)
    ztapi.provideAdapter((ISet, Interface), IInputWidget, CollectionInputWidget)
Пример #8
0
 def testExceptionSideEffects(self):
     from zope.publisher.interfaces import IExceptionSideEffects
     class SideEffects(object):
         implements(IExceptionSideEffects)
         def __init__(self, exception):
             self.exception = exception
         def __call__(self, obj, request, exc_info):
             self.obj = obj
             self.request = request
             self.exception_type = exc_info[0]
             self.exception_from_info = exc_info[1]
     class SideEffectsFactory:
         def __call__(self, exception):
             self.adapter = SideEffects(exception)
             return self.adapter
     factory = SideEffectsFactory()
     from ZODB.POSException import ConflictError
     from zope.interface import Interface
     class IConflictError(Interface):
         pass
     classImplements(ConflictError, IConflictError)
     ztapi.provideAdapter(IConflictError, IExceptionSideEffects, factory)
     exception = ConflictError()
     try:
         raise exception
     except:
         pass
     self.publication.handleException(
         self.object, self.request, sys.exc_info(), retry_allowed=False)
     adapter = factory.adapter
     self.assertEqual(exception, adapter.exception)
     self.assertEqual(exception, adapter.exception_from_info)
     self.assertEqual(ConflictError, adapter.exception_type)
     self.assertEqual(self.object, adapter.obj)
     self.assertEqual(self.request, adapter.request)
Пример #9
0
    def testTransactionAnnotation(self):
        from zope.interface import directlyProvides
        from zope.app.location.traversing import LocationPhysicallyLocatable
        from zope.app.location.interfaces import ILocation
        from zope.app.traversing.interfaces import IPhysicallyLocatable
        from zope.app.traversing.interfaces import IContainmentRoot
        ztapi.provideAdapter(ILocation, IPhysicallyLocatable,
                             LocationPhysicallyLocatable)

        root = self.db.open().root()
        root['foo'] = foo = LocatableObject()
        root['bar'] = bar = LocatableObject()
        bar.__name__ = 'bar'
        foo.__name__ = 'foo'
        bar.__parent__ = foo
        foo.__parent__ = root
        directlyProvides(root, IContainmentRoot)

        from zope.publisher.interfaces import IRequest
        expected_path = "/foo/bar"
        expected_user = "******" + self.user.id
        expected_request = IRequest.__module__ + '.' + IRequest.getName()

        self.publication.afterCall(self.request, bar)
        txn_info = self.db.undoInfo()[0]
        self.assertEqual(txn_info['location'], expected_path)
        self.assertEqual(txn_info['user_name'], expected_user)
        self.assertEqual(txn_info['request_type'], expected_request)

        # also, assert that we still get the right location when
        # passing an instance method as object.
        self.publication.afterCall(self.request, bar.foo)
        self.assertEqual(txn_info['location'], expected_path)
Пример #10
0
def setUpBBB(test):
    baseIntegration(test)
    ztapi.provideAdapter(IEditorRatable, IEditorialRating, EditorialRating)
    ztapi.provideAdapter(IUserRatable, IUserRating, UserRating)
    container = test.globs['my_container']
    directlyProvides(container,
                     IAttributeAnnotatable, IEditorRatable, IUserRatable)
Пример #11
0
 def setUp(self):
     placelesssetup.setUp()
     factory = self.getTestClass()
     iface = self.getTestInterface()
     required = self.getAdaptedClass()
     # register language switch for test interface adapter
     ztapi.provideAdapter(required, iface, factory)
Пример #12
0
def setUpCategory(test):
    placelesssetup.setUp(test)
    ztapi.provideAdapter(IAttributeAnnotatable, IAnnotations,
                         AttributeAnnotations)
    container = SampleContainer()
    test.globs = {'my_container': container}
    directlyProvides(container, IAttributeAnnotatable)
Пример #13
0
def setUpCategory(test):
    placelesssetup.setUp(test)
    ztapi.provideAdapter(IAttributeAnnotatable, IAnnotations,
                         AttributeAnnotations)
    container = SampleContainer()
    test.globs = {'my_container': container}
    directlyProvides(container, IAttributeAnnotatable)
Пример #14
0
    def setUp(self):
        super(TranslateTest, self).setUp()

        # Setup the registries
        ztapi.provideAdapter(IHTTPRequest, IUserPreferredCharsets,
                             HTTPCharsets)

        ztapi.provideUtility(IFactory, Factory(MessageCatalog),
                             'zope.app.MessageCatalog')

        domain = TranslationDomain()
        domain.domain = 'default'

        en_catalog = MessageCatalog('en', 'default')
        de_catalog = MessageCatalog('de', 'default')

        en_catalog.setMessage('short_greeting', 'Hello!')
        de_catalog.setMessage('short_greeting', 'Hallo!')

        en_catalog.setMessage('greeting', 'Hello $name, how are you?')
        de_catalog.setMessage('greeting', 'Hallo $name, wie geht es Dir?')

        domain['en-1'] = en_catalog
        domain['de-1'] = de_catalog

        self._view = Translate(domain, self._getRequest())
Пример #15
0
def setUpBBB(test):
    baseIntegration(test)
    ztapi.provideAdapter(IEditorRatable, IEditorialRating, EditorialRating)
    ztapi.provideAdapter(IUserRatable, IUserRating, UserRating)
    container = test.globs['my_container']
    directlyProvides(container,
                     IAttributeAnnotatable, IEditorRatable, IUserRatable)
Пример #16
0
def setUpObjectEventDocTest(test) :
    setUp()
        
    ztapi.provideAdapter(IAttributeAnnotatable,
                                IAnnotations, AttributeAnnotations) 
    ztapi.provideAdapter(IAnnotatable,
                                IZopeDublinCore, ZDCAnnotatableAdapter)    
Пример #17
0
def nonHTTPSessionTestCaseSetUp(sdc_class=PersistentSessionDataContainer):
    # I am getting an error with ClientId and not TestClientId
    placelesssetup.setUp()
    ztapi.provideAdapter(IRequest, IClientId, ClientId)
    ztapi.provideAdapter(IRequest, ISession, Session)
    ztapi.provideUtility(IClientIdManager, CookieClientIdManager())
    sdc = sdc_class()
    ztapi.provideUtility(ISessionDataContainer, sdc, '')
Пример #18
0
def nonHTTPSessionTestCaseSetUp(sdc_class=PersistentSessionDataContainer):
    # I am getting an error with ClientId and not TestClientId
    placelesssetup.setUp()
    ztapi.provideAdapter(IRequest, IClientId, ClientId)
    ztapi.provideAdapter(IRequest, ISession, Session)
    ztapi.provideUtility(IClientIdManager, CookieClientIdManager())
    sdc = sdc_class()
    ztapi.provideUtility(ISessionDataContainer, sdc, '')
Пример #19
0
def setUpCategoryTests(test):
    testing.setUp(test)
    # Setup our adapter from category to rating api
    ztapi.provideAdapter(IAttributeAnnotatable, IAnnotations,
                         AttributeAnnotations)
    container = SampleContainer()
    directlyProvides(container, IAttributeAnnotatable)
    test.globs = {'my_container': container}
Пример #20
0
def setUpCategoryTests(test):
    testing.setUp(test)
    # Setup our adapter from category to rating api
    ztapi.provideAdapter(IAttributeAnnotatable, IAnnotations,
                         AttributeAnnotations)
    container = SampleContainer()
    directlyProvides(container, IAttributeAnnotatable)
    test.globs = {'my_container': container}
Пример #21
0
 def setUp(self):
     super(Test, self).setUp()
     ztapi.provideAdapter(IAttributeAnnotatable, IAnnotations,
                          AttributeAnnotations)
     ztapi.provideAdapter(IAnnotatable, ICacheable,
                          AnnotationCacheable)
     self._cache = CacheStub()
     ztapi.provideUtility(ICache, self._cache, "my_cache")
Пример #22
0
        def test_empty(self):
            ztapi.provideAdapter(None, ITraversable, AttrItemTraverser)

            app, registry = self._initRegistry()
            exporter = self._makeOne(registry).__of__(registry)
            xml = exporter.generateXML()

            self._compareDOM(xml, _EMPTY_PLUGINREGISTRY_EXPORT)
Пример #23
0
def setUp(test):
    test.globs['rootFolder'] = setup.placefulSetUp(True)

    class RootModule(str):
        implements(IAPIDocRootModule)
    ztapi.provideUtility(IAPIDocRootModule, RootModule('zope'), "zope")

    module = CodeModule()
    module.__name__ = ''
    directlyProvides(module, IContainmentRoot)
    ztapi.provideUtility(IDocumentationModule, module, "Code")

    module = ZCMLModule()
    module.__name__ = ''
    directlyProvides(module, IContainmentRoot)
    ztapi.provideUtility(IDocumentationModule, module, "ZCML")

    # Register Renderer Components
    ztapi.provideUtility(IFactory, ReStructuredTextSourceFactory,
                         'zope.source.rest')
    ztapi.browserView(IReStructuredTextSource, '',
                      ReStructuredTextToHTMLRenderer)
    # Cheat and register the ReST factory for STX as well.
    ztapi.provideUtility(IFactory, ReStructuredTextSourceFactory,
                         'zope.source.stx')

    # Register ++apidoc++ namespace
    from zope.app.apidoc.apidoc import apidocNamespace
    from zope.app.traversing.interfaces import ITraversable
    ztapi.provideAdapter(None, ITraversable, apidocNamespace, name="apidoc")
    ztapi.provideView(None, None, ITraversable, "apidoc", apidocNamespace)

    # Register ++apidoc++ namespace
    from zope.app.traversing.namespace import view
    from zope.app.traversing.interfaces import ITraversable
    ztapi.provideAdapter(None, ITraversable, view, name="view")
    ztapi.provideView(None, None, ITraversable, "view", view)

    context = xmlconfig.string(meta)

    # Fix up path for tests.
    global old_context
    old_context = zope.app.appsetup.appsetup.__config_context
    zope.app.appsetup.appsetup.__config_context = context

    # Fix up path for tests.
    global old_source_file
    old_source_file = zope.app.appsetup.appsetup.__config_source
    zope.app.appsetup.appsetup.__config_source = os.path.join(
        os.path.dirname(zope.app.__file__), 'meta.zcml')

    # Register the index.html view for codemodule.class_.Class
    from zope.app.apidoc.codemodule.class_ import Class
    from zope.app.apidoc.codemodule.browser.class_ import ClassDetails
    from zope.app.publisher.browser import BrowserView
    class Details(ClassDetails, BrowserView):
        pass
    ztapi.browserView(Class, 'index.html', Details)
Пример #24
0
        def test_normal_no_plugins(self):
            ztapi.provideAdapter(None, ITraversable, AttrItemTraverser)

            app, registry = self._initRegistry(
                                    plugin_type_info=_PLUGIN_TYPE_INFO)
            exporter = self._makeOne(registry).__of__(registry)
            xml = exporter.generateXML()

            self._compareDOM(xml, _NO_PLUGINS_PLUGINREGISTRY_EXPORT)
Пример #25
0
 def setUp(self):
     super(Test, self).setUp()
     TestII18nAware.setUp(self)
     ztapi.provideAdapter(IHTTPRequest, IUserPreferredCharsets,
                          HTTPCharsets)
     ztapi.provideAdapter(IHTTPRequest, IUserPreferredLanguages,
                          BrowserLanguages)
     # Setup the negotiator utility
     ztapi.provideUtility(INegotiator, negotiator)
Пример #26
0
 def setUp(self):
     super(Test, self).setUp()
     TestII18nAware.setUp(self)
     ztapi.provideAdapter(IHTTPRequest, IUserPreferredCharsets,
                          HTTPCharsets)
     ztapi.provideAdapter(IHTTPRequest, IUserPreferredLanguages,
                          BrowserLanguages)
     # Setup the negotiator utility
     ztapi.provideUtility(INegotiator, negotiator)
Пример #27
0
 def setUp(self):
     super(TestAbsoluteURL, self).setUp()
     from zope.app.traversing.browser import AbsoluteURL, SiteAbsoluteURL
     ztapi.browserView(None, 'absolute_url', AbsoluteURL)
     ztapi.browserView(IRoot, 'absolute_url', SiteAbsoluteURL)
     ztapi.browserView(None, '', AbsoluteURL, providing=IAbsoluteURL)
     ztapi.browserView(IRoot, '', SiteAbsoluteURL, providing=IAbsoluteURL)
     ztapi.provideAdapter(IHTTPRequest, IUserPreferredCharsets,
                          HTTPCharsets)
Пример #28
0
 def setUp(self):
     super(AdapterTestCase, self).setUp()
     # provide necessary components
     ztapi.provideAdapter(None, IUniqueId, StubUniqueId)
     ztapi.provideAdapter(None, IChildObjects, StubChildObjects)
     ztapi.provideAdapter(ILocation, IUniqueId, LocationUniqueId)
     ztapi.provideAdapter(IReadContainer, IChildObjects, ContainerChildObjects)
     ztapi.provideAdapter(ISite, IChildObjects, ContainerSiteChildObjects)
     ztapi.provideUtility(ITreeStateEncoder, TreeStateEncoder())
     self.makeObjects()
Пример #29
0
def setUp(session_data_container_class=PersistentSessionDataContainer):
    placelesssetup.setUp()
    ztapi.provideAdapter(IRequest, IClientId, ClientId)
    ztapi.provideAdapter(IRequest, ISession, Session)
    ztapi.provideUtility(IClientIdManager, CookieClientIdManager())
    sdc = session_data_container_class()
    for product_id in ('', 'products.foo', 'products.bar', 'products.baz'):
        ztapi.provideUtility(ISessionDataContainer, sdc, product_id)
    request = HTTPRequest(StringIO(), {}, None)
    return request
Пример #30
0
def setUpViewTests(test):
    setUp(test)
    # Setup our adapter from category to rating api
    ztapi.provideAdapter((IRatingCategory, Interface), IRatingManager,
                         RatingCategoryAdapter)
    ztapi.provideAdapter(IAttributeAnnotatable, IAnnotations,
                         AttributeAnnotations)
    container = SampleContainer()
    directlyProvides(container, IAttributeAnnotatable)
    test.globs = {'my_container': container}
Пример #31
0
def defineMenuItem(menuItemType, for_, action, title=u'', extra=None):
    newclass = type(title, (BrowserMenuItem, ), {
        'title': title,
        'action': action,
        '_for': for_,
        'extra': extra
    })
    zope.interface.classImplements(newclass, menuItemType)
    ztapi.provideAdapter((for_, IBrowserRequest), menuItemType, newclass,
                         title)
Пример #32
0
def baseIntegration(test):
    placelesssetup.setUp(test)
    directlyProvides(IEditorialRating, IRatingType)
    directlyProvides(IUserRating, IRatingType)
    ztapi.provideAdapter(IAttributeAnnotatable, IAnnotations,
                         AttributeAnnotations)
    ztapi.provideAdapter((IRatingCategory, Interface),
                         IRatingManager, RatingCategoryAdapter)
    container = SampleContainer()
    test.globs = {'my_container': container}
Пример #33
0
def setUpViewTests(test):
    setUp(test)
    # Setup our adapter from category to rating api
    ztapi.provideAdapter((IRatingCategory, Interface),
                             IRatingManager, RatingCategoryAdapter)
    ztapi.provideAdapter(IAttributeAnnotatable, IAnnotations,
                         AttributeAnnotations)
    container = SampleContainer()
    directlyProvides(container, IAttributeAnnotatable)
    test.globs = {'my_container': container}
Пример #34
0
    def setUp(self):
        PlacefulSetup.setUp(self)
        PlacefulSetup.buildFolders(self)
        ztapi.provideAdapter(IContained, IObjectCopier, ObjectCopier)
        ztapi.provideAdapter(IContained, IObjectMover, ObjectMover)
        ztapi.provideAdapter(IContainer, IContainerItemRenamer,
                             ContainerItemRenamer)

        ztapi.provideAdapter(IAnnotations, IPrincipalClipboard,
                             PrincipalClipboard)
        ztapi.provideAdapter(Principal, IAnnotations, PrincipalAnnotations)
Пример #35
0
    def setUp(self):
        super(Test, self).setUp()
        XMLConfig('meta.zcml', zope.app.component)()
        XMLConfig('meta.zcml', zope.app.form.browser)()
        XMLConfig('meta.zcml', zope.app.publisher.browser)()

        from zope.app.testing import ztapi
        from zope.app.traversing.adapters import DefaultTraversable
        from zope.app.traversing.interfaces import ITraversable

        ztapi.provideAdapter(None, ITraversable, DefaultTraversable)
Пример #36
0
    def test_error(self):
        ztapi.provideAdapter(
                required=(MissingInputError, TestRequest),
                provided=IWidgetInputErrorView,
                factory=ObjectWidgetInputErrorView)

        widget = self._WidgetFactory(self.field, self.request)
        self.assertRaises(MissingInputError, widget.getInputValue)
        error_html = widget.error()
        self.failUnless("email: <zope.app.form.interfaces.Mis" in error_html)
        self.failUnless("name: <zope.app.form.interfaces.Miss" in error_html)
Пример #37
0
def setUp(test):
    root_folder = setup.placefulSetUp(True)
    ztapi.provideAdapter(None, IUniqueId, LocationUniqueId)
    ztapi.provideAdapter(None, IPhysicallyLocatable,
                         LocationPhysicallyLocatable)

    # Set up apidoc module
    test.globs['apidoc'] = APIDocumentation(root_folder, '++apidoc++')

    # Register documentation modules
    ztapi.provideUtility(IDocumentationModule, UtilityModule(), 'Utility')
Пример #38
0
def setUpBasicWidgets(test):
    testing.setUp(test)
    ztapi.provideAdapter((IChoice, Interface, Interface), IInputWidget,
                         DropdownWidget)
    ztapi.provideAdapter((IChoice, Interface), IInputWidget,
                         ChoiceInputWidget)
    ztapi.provideAdapter((ISet, IChoice, Interface), IInputWidget,
                         ChoiceCollectionInputWidget)
    ztapi.provideAdapter((ISet, Interface, Interface), IInputWidget,
                         MultiSelectSetWidget)
    ztapi.provideAdapter((ISet, Interface), IInputWidget,
                         CollectionInputWidget)
Пример #39
0
    def setUp(self):
        PlacefulSetup.setUp(self)

        ztapi.provideAdapter(
            IHTTPCredentials, ILoginPassword, BasicAuthAdapter)

        self.reg = PrincipalRegistry()

        self.reg.definePrincipal('1', 'Tim Peters', 'Sir Tim Peters',
                                 'tim', '123')
        self.reg.definePrincipal('2', 'Jim Fulton', 'Sir Jim Fulton',
                                 'jim', '456')
Пример #40
0
    def setUp(self):
        PlacefulSetup.setUp(self)
        PlacefulSetup.buildFolders(self)
        ztapi.provideAdapter(IContained, IObjectCopier, ObjectCopier)
        ztapi.provideAdapter(IContained, IObjectMover, ObjectMover)
        ztapi.provideAdapter(IContainer, IContainerItemRenamer,
            ContainerItemRenamer)

        ztapi.provideAdapter(IAnnotations, IPrincipalClipboard,
                             PrincipalClipboard)
        ztapi.provideAdapter(Principal, IAnnotations,
                             PrincipalAnnotations)
Пример #41
0
def baseIntegration(test):
    placelesssetup.setUp(test)
    directlyProvides(IEditorialRating, IRatingType)
    directlyProvides(IUserRating, IRatingType)
    # We use SampleContainers in our tests, so let's make it annotatable
    classImplements(SampleContainer, IAttributeAnnotatable)
    ztapi.provideAdapter(IAttributeAnnotatable, IAnnotations,
                         AttributeAnnotations)
    ztapi.provideAdapter((IRatingCategory, Interface),
                         IRatingManager, RatingCategoryAdapter)
    container = SampleContainer()
    test.globs = {'my_container': container}
Пример #42
0
def setUp(test):
    placelesssetup.setUp()
    setup.setUpTraversal()
    
    ztapi.provideAdapter(IInterface, IUniqueId, LocationUniqueId)

    # Register Renderer Components
    ztapi.provideUtility(IFactory, ReStructuredTextSourceFactory,
                         'zope.source.rest')    
    ztapi.browserView(IReStructuredTextSource, '', 
                      ReStructuredTextToHTMLRenderer)
    # Cheat and register the ReST factory for STX as well
    ztapi.provideUtility(IFactory, ReStructuredTextSourceFactory,
                         'zope.source.stx')    
Пример #43
0
        def test_empty(self):
            from Products.PluginRegistry.exportimport \
                import exportPluginRegistry
            ztapi.provideAdapter(None, ITraversable, AttrItemTraverser)

            app, registry = self._initRegistry()
            context = DummyExportContext(app)
            exportPluginRegistry(context)

            self.assertEqual( len(context._wrote), 1 )
            filename, text, content_type = context._wrote[0]
            self.assertEqual(filename, 'pluginregistry.xml')
            self._compareDOM(text, _EMPTY_PLUGINREGISTRY_EXPORT)
            self.assertEqual(content_type, 'text/xml')
Пример #44
0
 def test_unmoveable_object(self):
     ztapi.provideAdapter(IImmovable, copypastemove.interfaces.IObjectMover,
                          ObjectNonMover)
     root = self.getRootFolder()
     root['immovable'] = ImmovableFile()
     transaction.commit()
     response = self.publish('/@@contents.html',
                             basic='mgr:mgrpw',
                             form={
                                 'ids': [u'immovable'],
                                 'container_cut_button': u'Cut'
                             })
     self.assertEqual(response.getStatus(), 200)
     body = response.getBody()
     self.assert_("cannot be moved" in body)
Пример #45
0
 def setUp(self):
     super(ZPTPageTests, self).setUp()
     ztapi.provideAdapter(None, ITraverser, Traverser)
     ztapi.provideAdapter(None, ITraversable, DefaultTraversable)
     ztapi.provideAdapter(None, IPhysicallyLocatable,
                          LocationPhysicallyLocatable)
     ztapi.provideAdapter(IContainmentRoot, IPhysicallyLocatable,
                          RootPhysicallyLocatable)
     defineChecker(Data, NamesChecker(['URL', 'name']))
Пример #46
0
        def test_normal_with_plugins(self):
            from Products.PluginRegistry.exportimport \
                import exportPluginRegistry
            ztapi.provideAdapter(None, ITraversable, AttrItemTraverser)

            app, registry = self._initRegistry(
                plugin_type_info=_PLUGIN_TYPE_INFO,
                plugins={IFoo: ('foo_plugin_1', 'foo_plugin_2')},
            )
            context = DummyExportContext(app)
            exportPluginRegistry(context)

            self.assertEqual(len(context._wrote), 1)
            filename, text, content_type = context._wrote[0]
            self.assertEqual(filename, 'pluginregistry.xml')
            self._compareDOM(text, _NORMAL_PLUGINREGISTRY_EXPORT)
            self.assertEqual(content_type, 'text/xml')
Пример #47
0
    def testExceptionSideEffects(self):
        from zope.publisher.interfaces import IExceptionSideEffects

        class SideEffects(object):
            implements(IExceptionSideEffects)

            def __init__(self, exception):
                self.exception = exception

            def __call__(self, obj, request, exc_info):
                self.obj = obj
                self.request = request
                self.exception_type = exc_info[0]
                self.exception_from_info = exc_info[1]

        class SideEffectsFactory:
            def __call__(self, exception):
                self.adapter = SideEffects(exception)
                return self.adapter

        factory = SideEffectsFactory()
        from ZODB.POSException import ConflictError
        from zope.interface import Interface

        class IConflictError(Interface):
            pass

        classImplements(ConflictError, IConflictError)
        ztapi.provideAdapter(IConflictError, IExceptionSideEffects, factory)
        exception = ConflictError()
        try:
            raise exception
        except:
            pass
        self.publication.handleException(self.object,
                                         self.request,
                                         sys.exc_info(),
                                         retry_allowed=False)
        adapter = factory.adapter
        self.assertEqual(exception, adapter.exception)
        self.assertEqual(exception, adapter.exception_from_info)
        self.assertEqual(ConflictError, adapter.exception_type)
        self.assertEqual(self.object, adapter.obj)
        self.assertEqual(self.request, adapter.request)
Пример #48
0
    def test_error(self):
        ztapi.provideAdapter(
                required=(MissingInputError, TestRequest),
                provided=IWidgetInputErrorView,
                factory=ObjectWidgetInputErrorView)

        widget = self._WidgetFactory(self.field, self.request)
        self.assertRaises(MissingInputError, widget.getInputValue)
        error_html = widget.error()
        if sys.version_info < (2, 5):
            self.failUnless("email: <zope.formlibwidget.interfaces.Mis" 
                             in error_html)
            self.failUnless("name: <zope.formlibwidget.interfaces.Miss"
                             in error_html)
        else:
            self.failUnless("email: MissingInputError(u'field.foo.email', u'', None)"
                             in error_html)
            self.failUnless("name: MissingInputError(u'field.foo.name', u'', None)"
                             in error_html)
Пример #49
0
    def setUp(self):
        super(BasePublicationTests, self).setUp()
        from zope.security.management import endInteraction
        endInteraction()
        ztapi.provideAdapter(IHTTPRequest, IUserPreferredCharsets,
                             HTTPCharsets)
        self.policy = setSecurityPolicy(
            simplepolicies.PermissiveSecurityPolicy)
        self.storage = DemoStorage('test_storage')
        self.db = db = DB(self.storage)

        ztapi.provideUtility(IAuthentication, principalRegistry)

        connection = db.open()
        root = connection.root()
        app = getattr(root, ZopePublication.root_name, None)

        if app is None:
            from zope.app.folder import rootFolder
            app = rootFolder()
            root[ZopePublication.root_name] = app
            transaction.commit()

        connection.close()
        self.app = app

        from zope.traversing.namespace import view, resource, etc
        ztapi.provideNamespaceHandler('view', view)
        ztapi.provideNamespaceHandler('resource', resource)
        ztapi.provideNamespaceHandler('etc', etc)

        self.request = TestRequest('/f1/f2')
        self.user = Principal('test.principal')
        self.request.setPrincipal(self.user)
        from zope.interface import Interface
        self.presentation_type = Interface
        self.request._presentation_type = self.presentation_type
        self.object = object()
        self.publication = ZopePublication(self.db)
Пример #50
0
 def setUp(self):
     placelesssetup.setUp()
     ztapi.provideAdapter(IUtilityRegistration, IRegistrySearch,
                          UtilitySearch)
     ztapi.provideAdapter(IHandlerRegistration, IRegistrySearch,
                          HandlerSearch)
     ztapi.provideAdapter(IAdapterRegistration, IRegistrySearch,
                          AdapterSearch)
Пример #51
0
    def test_create_content_factory_id(self):
        class Adding(object):

            implements(IAdding)

            def __init__(self, test):
                self.test = test

            def add(self, ob):
                self.ob = ob
                self.test.assertEqual(
                    ob.__dict__, {
                        'args': ("bar", "baz"),
                        'kw': {
                            'email': '*****@*****.**'
                        },
                        '_foo': 'foo',
                    })
                return ob

            def nextURL(self):
                return "."

        # register content factory for content factory id lookup
        ztapi.provideAdapter(None, IComponentLookup, SiteManagerAdapter)
        ztapi.provideUtility(IFactory, Factory(C), name='C')

        adding = Adding(self)
        self._invoke_add(content_factory='C')
        (descriminator, callable, args, kw) = self._context.last_action
        factory = AddViewFactory(*args)
        request = TestRequest()
        view = getMultiAdapter((adding, request), name='addthis')
        content = view.create('a', 0, abc='def')

        self.failUnless(isinstance(content, C))
        self.assertEqual(content.args, ('a', 0))
        self.assertEqual(content.kw, {'abc': 'def'})
Пример #52
0
    def testChangeTitle(self):
        container = self._TestView__newContext()
        document = Document()
        container['document'] = document

        from zope.dublincore.interfaces import IDCDescriptiveProperties

        class FauxDCDescriptiveProperties(object):
            implements(IDCDescriptiveProperties)

            __Security_checker__ = checker.Checker(
                {
                    "title": "zope.Public",
                }, {"title": "zope.app.dublincore.change"})

            def __init__(self, context):
                self.context = context

            def setTitle(self, title):
                self.context.title = title

            def getTitle(self):
                return self.context.title

            title = property(getTitle, setTitle)

        ztapi.provideAdapter(IDocument, IDCDescriptiveProperties,
                             FauxDCDescriptiveProperties)

        fc = self._TestView__newView(container)

        dc = IDCDescriptiveProperties(document)

        fc.request.form.update({'retitle_id': 'document', 'new_value': 'new'})
        fc.changeTitle()
        events = getEvents()
        self.assertEquals(dc.title, 'new')
        self.failIf('title' not in events[-1].descriptions[0].attributes)
Пример #53
0
    def testInfoWDublinCore(self):
        container = self._TestView__newContext()
        document = Document()
        container['document'] = document

        from datetime import datetime
        from zope.dublincore.interfaces import IZopeDublinCore

        class FauxDCAdapter(object):
            implements(IZopeDublinCore)

            __Security_checker__ = checker.Checker(
                {
                    "created": "zope.Public",
                    "modified": "zope.Public",
                    "title": "zope.Public",
                }, {"title": "zope.app.dublincore.change"})

            def __init__(self, context):
                pass

            title = 'faux title'
            size = 1024
            created = datetime(2001, 1, 1, 1, 1, 1)
            modified = datetime(2002, 2, 2, 2, 2, 2)

        ztapi.provideAdapter(IDocument, IZopeDublinCore, FauxDCAdapter)

        fc = self._TestView__newView(container)
        info = fc.listContentInfo()[0]

        self.assertEqual(info['id'], 'document')
        self.assertEqual(info['url'], 'document')
        self.assertEqual(info['object'], document)
        self.assertEqual(info['title'], 'faux title')
        self.assertEqual(info['created'], '01/01/01 01:01')
        self.assertEqual(info['modified'], '02/02/02 02:02')
Пример #54
0
    def _setUp(test):
        setUp(test)
        ztapi.provideAdapter(
            (interfaces.IBungeniContent, interfaces.IBungeniGroup),
            IAssignmentFactory, assignment.GroupAssignmentFactory)

        ztapi.provideAdapter(interfaces.IBungeniContent, IContentAssignments,
                             assignment.ContentAssignments)

        ztapi.provideAdapter(interfaces.IBungeniGroup, IContextAssignments,
                             assignment.GroupContextAssignments)
Пример #55
0
    def setUp(self):
        super(TestLockStorage, self).setUp()
        setup.placelessSetUp()
        zope.security.management.endInteraction()

        ztapi.provideAdapter(Interface, IKeyReference, FakeKeyReference)
        ztapi.provideAdapter(Interface, ILockable, LockingAdapterFactory)
        ztapi.provideAdapter(None, IPathAdapter, LockingPathAdapter, "locking")

        self.storage = storage = PersistentLockStorage()
        ztapi.provideUtility(ILockStorage, storage)
        ztapi.provideUtility(ILockTracker, storage)
Пример #56
0
def setUp(test):
    ps.setUp()
    dict = test.globs
    dict.clear()
    dict['__name__'] = name
    sys.modules[name] = FakeModule(dict)

    ztapi.provideAdapter(Interface, IKeyReference, maybeFakeKeyReference)
    ztapi.provideAdapter(Interface, ILockable, LockingAdapterFactory)
    ztapi.provideAdapter(None, IPathAdapter, LockingPathAdapter, "locking")
    storage = PersistentLockStorage()
    ztapi.provideUtility(ILockStorage, storage)
    ztapi.provideUtility(ILockTracker, storage)
    test._storage = storage  # keep-alive
Пример #57
0
    def _setUpAdapters(self):
        from OFS.Folder import Folder
        try:
            from zope.app.testing import ztapi
        except ImportError:  # BBB, Zope3 < 3.1
            from zope.app.tests import ztapi
        #from OFS.Image import File

        from Products.GenericSetup.interfaces import IFilesystemExporter
        from Products.GenericSetup.interfaces import IFilesystemImporter
        from Products.GenericSetup.interfaces import ICSVAware
        from Products.GenericSetup.interfaces import IINIAware
        from Products.GenericSetup.interfaces import IDAVAware

        from Products.GenericSetup.content import \
             SimpleINIAware
        from Products.GenericSetup.content import \
             FolderishExporterImporter
        from Products.GenericSetup.content import \
             CSVAwareFileAdapter
        from Products.GenericSetup.content import \
             INIAwareFileAdapter
        from Products.GenericSetup.content import \
             DAVAwareFileAdapter

        ztapi.provideAdapter(
            IObjectManager,
            IFilesystemExporter,
            FolderishExporterImporter,
        )

        ztapi.provideAdapter(
            IObjectManager,
            IFilesystemImporter,
            FolderishExporterImporter,
        )

        ztapi.provideAdapter(
            IPropertyManager,
            IINIAware,
            SimpleINIAware,
        )

        ztapi.provideAdapter(
            ICSVAware,
            IFilesystemExporter,
            CSVAwareFileAdapter,
        )

        ztapi.provideAdapter(
            ICSVAware,
            IFilesystemImporter,
            CSVAwareFileAdapter,
        )

        ztapi.provideAdapter(
            IINIAware,
            IFilesystemExporter,
            INIAwareFileAdapter,
        )

        ztapi.provideAdapter(
            IINIAware,
            IFilesystemImporter,
            INIAwareFileAdapter,
        )

        ztapi.provideAdapter(
            IDAVAware,
            IFilesystemExporter,
            DAVAwareFileAdapter,
        )

        ztapi.provideAdapter(
            IDAVAware,
            IFilesystemImporter,
            DAVAwareFileAdapter,
        )
Пример #58
0
    def _setUpAdapters(self):
        from zope.app.testing import ztapi
        #from OFS.Image import File

        from Products.GenericSetup.interfaces import IFilesystemExporter
        from Products.GenericSetup.interfaces import IFilesystemImporter
        from Products.GenericSetup.interfaces import ICSVAware
        from Products.GenericSetup.interfaces import IINIAware
        from Products.CMFCore.interfaces import IFolderish

        from Products.CMFCore.exportimport.content import \
             StructureFolderWalkingAdapter
        from Products.GenericSetup.content import \
             CSVAwareFileAdapter
        from Products.GenericSetup.content import \
             INIAwareFileAdapter

        #from Products.CMFCore.exportimport.content import \
        #        OFSFileAdapter

        ztapi.provideAdapter(
            IFolderish,
            IFilesystemExporter,
            StructureFolderWalkingAdapter,
        )

        ztapi.provideAdapter(
            IFolderish,
            IFilesystemImporter,
            StructureFolderWalkingAdapter,
        )

        ztapi.provideAdapter(
            ICSVAware,
            IFilesystemExporter,
            CSVAwareFileAdapter,
        )

        ztapi.provideAdapter(
            ICSVAware,
            IFilesystemImporter,
            CSVAwareFileAdapter,
        )

        ztapi.provideAdapter(
            IINIAware,
            IFilesystemExporter,
            INIAwareFileAdapter,
        )

        ztapi.provideAdapter(
            IINIAware,
            IFilesystemImporter,
            INIAwareFileAdapter,
        )