Example #1
0
def setUp(test):
    zope.component.testing.setUp(test)
    setup.setUpTraversal()
    zope.component.provideAdapter(
        lambda x, y: x.name,
        (FakeRegistration, TestRequest), zope.interface.Interface,
        name='details')
Example #2
0
def setUp(test):
    setup.placefulSetUp(True)
    setUpDublinCore()
    component.provideAdapter(storage.Storage)
    component.provideAdapter(AttributeAnnotations)

    hooks.setHooks()
    setup.setUpTraversal()
    setup.setUpSiteManagerLookup()
    setup.setUpTestAsModule(test, 'zojax.content.model.README')

    # generate extension
    ExtensionClass = ExtensionType(
        "content.model",
        IViewModelExtension, ViewModelExtension,
        "View Model", "View model extension.", layer=interface.Interface)

    # register adater
    component.provideAdapter(
        Wrapper(ExtensionClass),
        (interface.Interface, interface.Interface, ExtensionMarker),
        IViewModelExtension)

    # register vocabulary
    getVocabularyRegistry().register(
        'zojax.content.model-list', Models())

    component.provideAdapter(
        Renderer, (IViewModelSupport, interface.Interface),
        interface.Interface, name='index.html')
Example #3
0
def setUp(test):
    setup.placefulSetUp(True)
    component.provideAdapter(storage.Storage)
    component.provideAdapter(AttributeAnnotations)

    hooks.setHooks()
    setup.setUpTraversal()
    setup.setUpSiteManagerLookup()
    setup.setUpTestAsModule(test, 'zojax.extensions.README')
Example #4
0
def setUp(test):
    formSetUp(test)
    component.provideAdapter(TestTemplate, name='layout')
    setup.setUpAnnotations()
    setup.setUpDependable()
    setup.setUpTraversal()
    setup.setUpSiteManagerLookup()
    site = setup.rootFolder()
    setup.createSiteManager(site, setsite=True)
    test.globs['site'] = site
Example #5
0
def setUp(test):
    setHooks()
    setup.setUpTraversal()
    setup.setUpSiteManagerLookup()
    site = setup.placefulSetUp(True)
    site.__name__ = u'portal'
    component.provideAdapter(
        PrincipalAnnotations, (IPrincipal,), IAnnotations)
    component.provideAdapter(getMessageStorage)

    setup.setUpTestAsModule(test, name='zojax.messaging.TESTS')
Example #6
0
def setUpControlPanel():
    setup.setUpTraversal()
    setup.setUpSiteManagerLookup()
    
    component.provideAdapter(root.getSettings, name='settings')
    component.provideAdapter(AttributeAnnotations)
    component.provideUtility(root.RootConfiglet(), interfaces.IConfiglet)
    
    component.provideAdapter(storage.getConfigletData)
    component.provideAdapter(storage.getConfigletDataStorage)
    component.provideAdapter(storage.DefaultConfigletDataFactory)
Example #7
0
def setUp(test):
    placelesssetup.setUp(test)
    setup.setUpTraversal()

    zope.component.provideUtility(
        zope.principalannotation.utility.PrincipalAnnotationUtility(),
        zope.principalannotation.interfaces.IPrincipalAnnotationUtility)
    zope.component.provideAdapter(
        zope.principalannotation.utility.annotations,
        adapts=(None,))
    zope.component.provideAdapter(
        PrincipalClipboard)
    def setUp(self):
        TestITranslationDomain.setUp(self)

        # placefulSetup
        setup.setUpTraversal()
        setup.setUpSiteManagerLookup()
        self.rootFolder = setup.buildSampleFolderTree()

        self.sm = setup.createSiteManager(self.rootFolder, setsite=True)
        setup.addUtility(self.sm, 'default', ITranslationDomain, self._domain)

        provideUtility(Factory(MessageCatalog), IFactory,
                       'zope.app.MessageCatalog')
Example #9
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')    
Example #10
0
def setUp(test):
    setup.placefulSetUp(True)
    setup.setUpTraversal()
    setUpControlPanel()

    Engine.registerType(u'formatter', FormatterExpression)
    TrustedEngine.registerType(u'formatter', FormatterExpression)

    provideAdapter(dformatter.DateFormatterFactory, name='date')
    provideAdapter(dtformatter.DatetimeFormatterFactory, name='dateTime')
    provideAdapter(
        fancydatetime.FancyDatetimeFormatterFactory, name='fancyDatetime')
    provideAdapter(
        humandatetime.HumanDatetimeFormatterFactory, name='humanDatetime')
    provideAdapter(timeformatter.TimeFormatterFactory, name='time')
Example #11
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)
Example #12
0
    def testPlacefulAuth(self):
        setup.setUpTraversal()
        setup.setUpSiteManagerLookup()
        principalRegistry.defineDefaultPrincipal('anonymous', '')

        root = self.db.open().root()
        app = root[ZopePublication.root_name]
        app['f1'] = rootFolder()
        f1 = app['f1']
        f1['f2'] = Folder()
        sm1 = setup.createSiteManager(f1)
        setup.addUtility(sm1, '', IAuthenticationUtility, AuthUtility1())

        f2 = f1['f2']
        sm2 = setup.createSiteManager(f2)
        setup.addUtility(sm2, '', IAuthenticationUtility, AuthUtility2())
        transaction.commit()

        from zope.app.container.interfaces import ISimpleReadContainer
        from zope.app.container.traversal import ContainerTraverser

        ztapi.provideView(ISimpleReadContainer, IRequest, IPublishTraverse,
                          '', ContainerTraverser)

        from zope.app.folder.interfaces import IFolder
        from zope.security.checker import defineChecker, InterfaceChecker
        defineChecker(Folder, InterfaceChecker(IFolder))

        self.publication.beforeTraversal(self.request)
        self.assertEqual(list(queryInteraction().participations),
                         [self.request])
        self.assertEqual(self.request.principal.id, 'anonymous')
        root = self.publication.getApplication(self.request)
        self.publication.callTraversalHooks(self.request, root)
        self.assertEqual(self.request.principal.id, 'anonymous')
        ob = self.publication.traverseName(self.request, root, 'f1')
        self.publication.callTraversalHooks(self.request, ob)
        self.assertEqual(self.request.principal.id, 'test.anonymous')
        ob = self.publication.traverseName(self.request, ob, 'f2')
        self.publication.afterTraversal(self.request, ob)
        self.assertEqual(self.request.principal.id, 'test.bob')
        self.assertEqual(list(queryInteraction().participations),
                         [self.request])
        self.publication.endRequest(self.request, ob)
        self.assertEqual(queryInteraction(), None)
Example #13
0
    def testPlacefulAuth(self):
        setup.setUpTraversal()
        setup.setUpSiteManagerLookup()
        principalRegistry.defineDefaultPrincipal('anonymous', '')

        root = self.db.open().root()
        app = root[ZopePublication.root_name]
        app['f1'] = rootFolder()
        f1 = app['f1']
        f1['f2'] = Folder()
        sm1 = setup.createSiteManager(f1)
        setup.addUtility(sm1, '', IAuthenticationUtility, AuthUtility1())

        f2 = f1['f2']
        sm2 = setup.createSiteManager(f2)
        setup.addUtility(sm2, '', IAuthenticationUtility, AuthUtility2())
        transaction.commit()

        from zope.app.container.interfaces import ISimpleReadContainer
        from zope.app.container.traversal import ContainerTraverser

        ztapi.provideView(ISimpleReadContainer, IRequest, IPublishTraverse, '',
                          ContainerTraverser)

        from zope.app.folder.interfaces import IFolder
        from zope.security.checker import defineChecker, InterfaceChecker
        defineChecker(Folder, InterfaceChecker(IFolder))

        self.publication.beforeTraversal(self.request)
        self.assertEqual(list(queryInteraction().participations),
                         [self.request])
        self.assertEqual(self.request.principal.id, 'anonymous')
        root = self.publication.getApplication(self.request)
        self.publication.callTraversalHooks(self.request, root)
        self.assertEqual(self.request.principal.id, 'anonymous')
        ob = self.publication.traverseName(self.request, root, 'f1')
        self.publication.callTraversalHooks(self.request, ob)
        self.assertEqual(self.request.principal.id, 'test.anonymous')
        ob = self.publication.traverseName(self.request, ob, 'f2')
        self.publication.afterTraversal(self.request, ob)
        self.assertEqual(self.request.principal.id, 'test.bob')
        self.assertEqual(list(queryInteraction().participations),
                         [self.request])
        self.publication.endRequest(self.request, ob)
        self.assertEqual(queryInteraction(), None)
Example #14
0
def catalogSetUp(test):
    """This code is deprecated, to be used only by old evolution tests."""
    setup.placefulSetUp()
    setup.setUpTraversal()
    setUpAnnotations()

    # this is code to set up the catalog for unit testing. it could
    # be extracted and put into general setup functionality

    # Make sure objects can be keyreferenced - necessary for int ids to
    # work:

    from zope.component import provideAdapter
    from persistent.interfaces import IPersistent
    provideAdapter(StupidKeyReference, [IPersistent], IKeyReference)

    # Provide the int id subscribers:

    from zope.component import provideHandler
    from zope.intid import addIntIdSubscriber, removeIntIdSubscriber
    from zope.location.interfaces import ILocation
    from zope.lifecycleevent.interfaces import IObjectAddedEvent
    from zope.lifecycleevent.interfaces import IObjectRemovedEvent
    provideHandler(addIntIdSubscriber,
                   [ILocation, IObjectAddedEvent])
    provideHandler(removeIntIdSubscriber,
                   [ILocation, IObjectRemovedEvent])

    # And the catalog subscribers:

    from zope.catalog import catalog
    from zope.catalog.interfaces import ICatalogIndex
    from zope.intid.interfaces import IIntIdAddedEvent,\
         IIntIdRemovedEvent
    from zope.lifecycleevent.interfaces import IObjectModifiedEvent
    provideHandler(catalog.indexAdded,
                   [ICatalogIndex, IObjectAddedEvent])
    provideHandler(catalog.indexDocSubscriber,
                   [IIntIdAddedEvent])
    provideHandler(catalog.reindexDocSubscriber,
                   [IObjectModifiedEvent])
    provideHandler(catalog.unindexDocSubscriber,
                   [IIntIdRemovedEvent])
def docSetUp(test=None):
    zope_setup.placefulSetUp()
    zope_setup.setUpAnnotations()
    zope_setup.setUpTraversal()
    provideAdapter(getTermContainer, (Interface, ))
    provideAdapter(getSchoolYearForTerm)
    provideAdapter(getCourseContainer)
    provideAdapter(getCourseContainerForApp)
    provideAdapter(getSectionContainer)
    provideAdapter(getTermForSection)
    provideAdapter(getTermForSectionContainer)
    provideAdapter(getTimetableContainer)
    provideAdapter(getScheduleContainer)
    testing_registry.setupTimetablesComponents()

    provideAdapter(SectionNameChooser, (ISectionContainer, ))
    zcml = getIntegrationTestZCML()
    zcml.include('schooltool.schoolyear', file='schoolyear.zcml')
    app = test.globs['app'] = AppStub()
    app['persons'] = BTreeContainer()
def docSetUp(test=None):
    zope_setup.placefulSetUp()
    zope_setup.setUpAnnotations()
    zope_setup.setUpTraversal()
    test.globs['app'] = setUpSchoolToolSite()
    setUpRelationships()

    provideAdapter(getSchoolYearContainer)
    provideAdapter(getTermContainer, (Interface,))
    provideAdapter(getSchoolYearForTerm)
    provideAdapter(getCourseContainer)
    provideAdapter(getCourseContainerForApp)
    provideAdapter(getSectionContainer)
    provideAdapter(getTermForSection)
    provideAdapter(getTermForSectionContainer)
    provideAdapter(getTimetableContainer)
    provideAdapter(getScheduleContainer)
    setUpIntIds()

    provideAdapter(SectionNameChooser, (ISectionContainer,))

    transaction.begin()
def docSetUp(test=None):
    zope_setup.placefulSetUp()
    zope_setup.setUpAnnotations()
    zope_setup.setUpTraversal()
    test.globs['app'] = setUpSchoolToolSite()
    setUpRelationships()

    provideAdapter(getSchoolYearContainer)
    provideAdapter(getTermContainer, (Interface, ))
    provideAdapter(getSchoolYearForTerm)
    provideAdapter(getCourseContainer)
    provideAdapter(getCourseContainerForApp)
    provideAdapter(getSectionContainer)
    provideAdapter(getTermForSection)
    provideAdapter(getTermForSectionContainer)
    provideAdapter(getTimetableContainer)
    provideAdapter(getScheduleContainer)
    setUpIntIds()

    provideAdapter(SectionNameChooser, (ISectionContainer, ))

    transaction.begin()
Example #18
0
def catalogSetUp(test):
    """This code is deprecated, to be used only by old evolution tests."""
    setup.placefulSetUp()
    setup.setUpTraversal()
    setUpAnnotations()

    # this is code to set up the catalog for unit testing. it could
    # be extracted and put into general setup functionality

    # Make sure objects can be keyreferenced - necessary for int ids to
    # work:

    from zope.component import provideAdapter
    from persistent.interfaces import IPersistent
    provideAdapter(StupidKeyReference, [IPersistent], IKeyReference)

    # Provide the int id subscribers:

    from zope.component import provideHandler
    from zope.intid import addIntIdSubscriber, removeIntIdSubscriber
    from zope.location.interfaces import ILocation
    from zope.lifecycleevent.interfaces import IObjectAddedEvent
    from zope.lifecycleevent.interfaces import IObjectRemovedEvent
    provideHandler(addIntIdSubscriber, [ILocation, IObjectAddedEvent])
    provideHandler(removeIntIdSubscriber, [ILocation, IObjectRemovedEvent])

    # And the catalog subscribers:

    from zope.catalog import catalog
    from zope.catalog.interfaces import ICatalogIndex
    from zope.intid.interfaces import IIntIdAddedEvent,\
         IIntIdRemovedEvent
    from zope.lifecycleevent.interfaces import IObjectModifiedEvent
    provideHandler(catalog.indexAdded, [ICatalogIndex, IObjectAddedEvent])
    provideHandler(catalog.indexDocSubscriber, [IIntIdAddedEvent])
    provideHandler(catalog.reindexDocSubscriber, [IObjectModifiedEvent])
    provideHandler(catalog.unindexDocSubscriber, [IIntIdRemovedEvent])
Example #19
0
def setUp(test):
    setup.placefulSetUp()
    setup.setUpTraversal()
Example #20
0
def setUp(test):
    setup.placelessSetUp()
    setup.setUpTraversal()
    provideAdapter(view, (None, None), ITraversable, name="view")
Example #21
0
def setUp(test=None):
    """Set up the test fixture for schooltool.app.browser doctests.

    Performs what is called a "placeless setup" in the Zope 3 world, then sets
    up annotations, relationships, and registers widgets as views for some
    schema fields.

    In effect, duplicates a subset of ZCML configuration -- just enough to
    actually render our page templates in unit tests.
    """
    setup.placefulSetUp()
    setup.setUpAnnotations()
    setup.setUpTraversal()
    # relationships
    setUpRelationships()
    # widgets
    ztapi.browserViewProviding(IPassword, PasswordWidget, IInputWidget)
    ztapi.browserViewProviding(ITextLine, TextWidget, IInputWidget)
    ztapi.browserViewProviding(IText, TextAreaWidget, IInputWidget)
    ztapi.browserViewProviding(IBytes, BytesWidget, IInputWidget)
    ztapi.browserViewProviding(IBool, CheckBoxWidget, IInputWidget)
    ztapi.browserViewProviding(IDate, DateWidget, IInputWidget)
    ztapi.browserViewProviding(IInt, IntWidget, IInputWidget)
    ztapi.browserViewProviding(IChoice, ChoiceInputWidget, IInputWidget)
    ztapi.browserViewProviding(ICollection, CollectionInputWidget, IInputWidget)

    ztapi.provideMultiView((IChoice, IIterableVocabulary), IBrowserRequest,
                           IInputWidget, '', DropdownWidget)

    ztapi.provideMultiView((ISet, IChoice), IBrowserRequest,
                           IInputWidget, '', ChoiceCollectionInputWidget)
    ztapi.provideMultiView((IList, IChoice), IBrowserRequest,
                           IInputWidget, '', ChoiceCollectionInputWidget)
    ztapi.provideMultiView((IList, IVocabularyTokenized), IBrowserRequest,
                           IInputWidget, '', OrderedMultiSelectWidget)
    # XXX MultiSelectWidget doesn't work with sets :/
    #     http://www.zope.org/Collectors/Zope3-dev/360
    ztapi.provideMultiView((ISet, IIterableVocabulary), IBrowserRequest,
                           IInputWidget, '', MultiSelectWidget)

    # errors in forms
    ztapi.browserViewProviding(IWidgetInputError, WidgetInputErrorView,
                               IWidgetInputErrorView)


    # Now, the question is: does the speed of the tests run with the
    # setup below justify this complex setup that duplicates the ZCML?
    # For now, I say yes. -- not mg, perhaps alga or gintas

    # ++view++
    ztapi.provideView(None, None, ITraversable, 'view', view)
    ztapi.provideView(None, None, ITraversable, 'resource', resource)

    # schooltool: namespace in tal
    provideAdapter(SchoolToolAPI, (None,), IPathAdapter, 'schooltool')

    # sortby: namespace in tal
    provideAdapter(SortBy, (None,), IPathAdapter, 'sortby')

    # standard_macros, schooltool_macros and schooltool_navigation
    ztapi.browserView(None, 'standard_macros', StandardMacros)
    ztapi.browserView(None, 'view_macros',
                      SimpleViewClass("../../skin/templates/view_macros.pt"))

    ztapi.browserView(None, 'schooltool_macros', SchoolToolMacros)
    ztapi.browserView(None, 'calendar_macros',
                      SimpleViewClass("./templates/calendar_macros.pt"))
    ztapi.browserView(None, 'generic_macros',
                      SimpleViewClass("../../skin/templates/generic_macros.pt"))

    # form macros
    ztapi.browserView(None, 'form_macros', FormMacros)
    import zope.formlib
    base = zope.formlib.__path__[0]
    ztapi.browserView(None, 'widget_macros',
                      SimpleViewClass(os.path.join(base, 'widget_macros.pt')))

    # resources
    class ResourceStub:
        def __init__(self, request):
            self.request = request
        def __getitem__(self, key):
            return ResourceStub(self.request)
        def __call__(self):
            return "a dummy resource"

    for name in ['layout.css', 'schooltool.css', 'schooltool.js',
                 'next.png', 'prev.png', 'favicon.ico',
                 'print.css', 'jquery.js',
                 'zonki-regular.png']:
        ztapi.browserResource(name, ResourceStub)

    # menus
    ztapi.browserView(None, 'view_get_menu', MenuAccessView)
    provideUtility(BrowserMenuStub('schooltool_actions'), IBrowserMenu,
                   'schooltool_actions')

    # `provider` TALES namespaces
    from zope.browserpage import metaconfigure
    from zope.contentprovider import tales
    metaconfigure.registerType('provider', tales.TALESProviderExpression)

    # viewlet manager registrations
    from zope.viewlet import manager
    from schooltool import skin
    name = 'schooltool.Header'
    provideAdapter(
        manager.ViewletManager(name, skin.IHeaderManager),
        (Interface, IDefaultBrowserLayer, IBrowserView),
        skin.IHeaderManager,
        name=name)

    name = 'schooltool.JavaScript'
    provideAdapter(
        manager.ViewletManager(name, skin.IJavaScriptManager),
        (Interface, IDefaultBrowserLayer, IBrowserView),
        skin.IJavaScriptManager,
        name=name)

    name = 'schooltool.CSS'
    provideAdapter(
        manager.ViewletManager(name, skin.ICSSManager),
        (Interface, IDefaultBrowserLayer, IBrowserView),
        skin.ICSSManager,
        name=name)

    name = 'schooltool.MenuBar'
    provideAdapter(
        manager.ViewletManager(name, skin.skin.IMenuBarMenuManager),
        (Interface, IDefaultBrowserLayer, IBrowserView),
        skin.skin.IMenuBarMenuManager,
        name=name)

    name = 'schooltool.NavigationMenu'
    provideAdapter(
        manager.ViewletManager(name, skin.skin.INavigationManager),
        (Interface, IDefaultBrowserLayer, IBrowserView),
        skin.skin.INavigationManager,
        name=name)

    name = 'schooltool.ActionsMenu'
    provideAdapter(
        manager.ViewletManager(name, skin.skin.IActionMenuManager),
        (Interface, IDefaultBrowserLayer, IBrowserView),
        skin.skin.IActionMenuManager,
        name=name)
Example #22
0
def setUp(test):
    setup.placelessSetUp()
    setup.setUpTraversal()
def setUp(test):
    placelesssetup.setUp(test)
    setup.setUpAnnotations()
    setup.setUpDependable()
    setup.setUpTraversal()
Example #24
0
def setUp(test):
    setup.placefulSetUp()
    setup.setUpTraversal()
Example #25
0
 def setUp(self):
     super(BindingTestCase, self).setUp()
     setup.setUpTraversal()
Example #26
0
def setUp(test):
    setup.placelessSetUp()
    setup.setUpTraversal()
    setSite()
Example #27
0
def setUp(test):
    setup.placefulSetUp()
    setup.setUpTraversal()
    provideAdapters()
    provideUtilities()