def test_resources(self): ztapi.browserResource('quux', Resource) # Only register the checker once, so that multiple test runs pass. if Resource not in _checkers: defineChecker(Resource, NamesChecker(['__call__'])) self.addPage('/foo/bar/pt', u'<span tal:replace="context/++resource++quux" />') self.verify('/foo/bar/pt', 'http://localhost/@@/quux\n') self.verify('/foo/++vh++https:otherhost:443/fake/folders/++/bar/pt', 'https://otherhost/fake/folders/@@/quux\n')
def test_getitem(self): from zope.app.publisher.browser.resources import Resources request = TestRequest() class Resource(object): def __init__(self, request): pass def __call__(self): return 42 ztapi.browserResource('test', Resource) view = Resources(None, request) resource = view['test'] self.assertEqual(resource(), 42)
def testResource(self): ztapi.browserResource('foo', Resource) ob = Content() r = resource(ob, TestRequest()).traverse('foo', ()) self.assertEqual(r.__class__, Resource)
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)