コード例 #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
ファイル: tests.py プロジェクト: wpjunior/proled
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
ファイル: tests.py プロジェクト: bendavis78/zope
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
ファイル: test_rating.py プロジェクト: eaudeweb/naaya
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
ファイル: testing.py プロジェクト: felixonmars/z3c.language
 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
ファイル: test_category.py プロジェクト: zjs2k/contentratings
def setUpCategory(test):
    placelesssetup.setUp(test)
    ztapi.provideAdapter(IAttributeAnnotatable, IAnnotations,
                         AttributeAnnotations)
    container = SampleContainer()
    test.globs = {'my_container': container}
    directlyProvides(container, IAttributeAnnotatable)
コード例 #13
0
ファイル: test_category.py プロジェクト: CGTIC/Plone_SP
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
ファイル: tests.py プロジェクト: wpjunior/proled
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
ファイル: tests.py プロジェクト: bendavis78/zope
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
ファイル: tests.py プロジェクト: CGTIC/Plone_SP
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
ファイル: test_exportimport.py プロジェクト: c0ns0le/zenoss-4
        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
ファイル: tests.py プロジェクト: wpjunior/proled
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
ファイル: test_exportimport.py プロジェクト: c0ns0le/zenoss-4
        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
ファイル: test_adapters.py プロジェクト: wpjunior/proled
 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
ファイル: tests.py プロジェクト: eaudeweb/naaya
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
ファイル: tests.py プロジェクト: jean/zope.app.apidoc
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
ファイル: tests.py プロジェクト: zjs2k/plone.contentratings
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
ファイル: test_rating.py プロジェクト: eaudeweb/naaya
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
ファイル: tests.py プロジェクト: wpjunior/proled
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
ファイル: test_exportimport.py プロジェクト: c0ns0le/zenoss-4
        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
ファイル: test_objectwidget.py プロジェクト: bendavis78/zope
    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
ファイル: tests.py プロジェクト: mohalfaki/bungeni-portal
    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
ファイル: test_content.py プロジェクト: bendavis78/zope
    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,
        )