def _testBaseTags(self, url, expected): # Make sure I1 and O1 are visible in the module namespace # so that the classes can be pickled. import transaction pub = BrowserPublication(self.db) ztapi.browserView(I1, 'view', DummyView) ztapi.setDefaultViewName(I1, 'view') ztapi.browserViewProviding(None, TestTraverser, IBrowserPublisher) ob = O1() ## the following is for running the tests standalone principalRegistry.defineDefaultPrincipal( 'tim', 'timbot', 'ai at its best') # now place our object inside the application connection = self.db.open() app = connection.root()['Application'] app.somepath = ob transaction.commit() connection.close() defineChecker(app.__class__, NamesChecker(somepath='xxx')) req = self._createRequest(url, pub) response = req.response publish(req, handle_errors=0) self.assertEqual(response.getBase(), expected)
def _testBaseTags(self, url, expected): # Make sure I1 and O1 are visible in the module namespace # so that the classes can be pickled. import transaction pub = BrowserPublication(self.db) ztapi.browserView(I1, 'view', DummyView) ztapi.setDefaultViewName(I1, 'view') ztapi.browserViewProviding(None, TestTraverser, IBrowserPublisher) ob = O1() ## the following is for running the tests standalone principalRegistry.defineDefaultPrincipal('tim', 'timbot', 'ai at its best') # now place our object inside the application connection = self.db.open() app = connection.root()['Application'] app.somepath = ob transaction.commit() connection.close() defineChecker(app.__class__, NamesChecker(somepath='xxx')) req = self._createRequest(url, pub) response = req.response publish(req, handle_errors=0) self.assertEqual(response.getBase(), expected)
def testTraverseName(self): pub = self.klass(self.db) class C(object): x = SimpleObject(1) ob = C() r = self._createRequest('/x',pub) ztapi.browserViewProviding(None, TestTraverser, IBrowserPublisher) ob2 = pub.traverseName(r, ob, 'x') self.assertRaises(ForbiddenAttribute, getattr, ob2, 'v') self.assertEqual(removeSecurityProxy(ob2).v, 1)
def testTraverseName(self): pub = self.klass(self.db) class C(object): x = SimpleObject(1) ob = C() r = self._createRequest('/x', pub) ztapi.browserViewProviding(None, TestTraverser, IBrowserPublisher) ob2 = pub.traverseName(r, ob, 'x') self.assertRaises(ForbiddenAttribute, getattr, ob2, 'v') self.assertEqual(removeSecurityProxy(ob2).v, 1)
def setUp(test=None): testing.setUp() from bibliograph.rendering.renderers.pdf import PdfRenderView from bibliograph.rendering.utility import ExternalTransformUtility ztapi.provideView(IBibliographicReference, None, None, name=u'reference.bib', factory=BibtexRenderView) ztapi.provideView(IBibliographicReference, None, None, name=u'reference.pdf', factory=PdfRenderView) ztapi.provideUtility(IBibTransformUtility, ExternalTransformUtility(), name=u'external') ztapi.browserViewProviding(None, AbsoluteURL, IAbsoluteURL)
def setUpContent(self, desc=u'', title=u'Foo Title'): ztapi.browserViewProviding(ITextLine, TextWidget, IInputWidget) class ITestContent(Interface): foo = self._FieldFactory( ITestContact, title=title, description=desc ) class TestObject(object): implements(ITestContent) self.content = TestObject() self.field = ITestContent['foo'] self.request = TestRequest(HTTP_ACCEPT_LANGUAGE='pl') self.request.form['field.foo'] = u'Foo Value' self._widget = self._WidgetFactory(self.field, self.request)
def setUp(self, doctesttest=None): CAPlacelessSetup.setUp(self) EventPlacelessSetup.setUp(self) ContainerPlacelessSetup.setUp(self) I18nPlacelessSetup.setUp(self) setUpPasswordManagers() ztapi.browserView(None, 'absolute_url', AbsoluteURL) ztapi.browserViewProviding(None, AbsoluteURL, IAbsoluteURL) from zope.security.testing import addCheckerPublic addCheckerPublic() from zope.security.management import newInteraction newInteraction() setVocabularyRegistry(None)
def testAdaptedTraverseDefaultWrapping(self): # Test default content and make sure that it's wrapped. class Adapter(object): implements(IBrowserPublisher) def __init__(self, context, request): self.context = context def browserDefault(self, request): return (self.context['bruce'], 'dummy') ztapi.browserViewProviding(I1, Adapter, IBrowserPublisher) ob = mydict() ob['bruce'] = SimpleObject('bruce') ob['bruce2'] = SimpleObject('bruce2') pub = self.klass(self.db) ob2, x = pub.getDefaultTraversal(self._createRequest('/bruce',pub), ob) self.assertEqual(x, 'dummy') self.assertRaises(ForbiddenAttribute, getattr, ob2, 'v') self.assertEqual(removeSecurityProxy(ob2).v, 'bruce')
def setUp(self, doctesttest=None): CAPlacelessSetup.setUp(self) ContainerPlacelessSetup.setUp(self) EventPlacelessSetup.setUp(self) I18nPlacelessSetup.setUp(self) AuthenticationPlacelessSetup.setUp(self) # Register app-specific security declarations protect() ztapi.browserView(None, 'absolute_url', AbsoluteURL) ztapi.browserViewProviding(None, AbsoluteURL, IAbsoluteURL) from zope.app.security.tests import addCheckerPublic addCheckerPublic() from zope.security.management import newInteraction newInteraction() setVocabularyRegistry(None)
def testAdaptedTraverseNameWrapping(self): class Adapter(object): implements(IBrowserPublisher) def __init__(self, context, request): self.context = context self.counter = 0 def publishTraverse(self, request, name): self.counter += 1 return self.context[name] ztapi.browserViewProviding(I1, Adapter, IBrowserPublisher) ob = mydict() ob['bruce'] = SimpleObject('bruce') ob['bruce2'] = SimpleObject('bruce2') pub = self.klass(self.db) ob2 = pub.traverseName(self._createRequest('/bruce', pub), ob, 'bruce') self.assertRaises(ForbiddenAttribute, getattr, ob2, 'v') self.assertEqual(removeSecurityProxy(ob2).v, 'bruce')
def testAdaptedTraverseDefaultWrapping(self): # Test default content and make sure that it's wrapped. class Adapter(object): implements(IBrowserPublisher) def __init__(self, context, request): self.context = context def browserDefault(self, request): return (self.context['bruce'], 'dummy') ztapi.browserViewProviding(I1, Adapter, IBrowserPublisher) ob = mydict() ob['bruce'] = SimpleObject('bruce') ob['bruce2'] = SimpleObject('bruce2') pub = self.klass(self.db) ob2, x = pub.getDefaultTraversal(self._createRequest('/bruce', pub), ob) self.assertEqual(x, 'dummy') self.assertRaises(ForbiddenAttribute, getattr, ob2, 'v') self.assertEqual(removeSecurityProxy(ob2).v, 'bruce')
def setUp(test): setup.placefulSetUp() ztapi.browserViewProviding(IChoice, ChoiceInputWidget, IInputWidget) ztapi.browserViewProviding(IDate, DateWidget, IInputWidget) ztapi.provideMultiView((IChoice, IIterableVocabulary), IBrowserRequest, IInputWidget, '', DropdownWidget) # errors in forms ztapi.browserViewProviding(IWidgetInputError, WidgetInputErrorView, IWidgetInputErrorView)
def setUp(test): testing.setUp() ztapi.browserViewProviding(ITextLine, TextWidget, IInputWidget)
def setUp(test): setup.placefulSetUp() ztapi.browserViewProviding(ITextLine, TextWidget, IInputWidget) ztapi.browserViewProviding(IWidgetInputError, WidgetInputErrorView, IWidgetInputErrorView)
def setUp(self): self.setUpContent() self.request = TestRequest() self.widget = self._WidgetFactory( self.field, self.field.value_type, self.request) ztapi.browserViewProviding(ITextLine, DisplayWidget, IDisplayWidget)
def setUp(self): self.setUpContent() self.request = TestRequest() self.widget = self._WidgetFactory(self.field, self.field.value_type, self.request) ztapi.browserViewProviding(ITextLine, DisplayWidget, IDisplayWidget)
def setUp(self): super(Test, self).setUp() ztapi.browserViewProviding(ITextLine, TextWidget, IInputWidget) ztapi.provideAdapter(IFoo, IBar, FooBarAdapter) clearEvents()
def setUp(test): setup.placefulSetUp() ztapi.browserViewProviding(ITextLine, TextWidget, IInputWidget) # errors in forms ztapi.browserViewProviding(IWidgetInputError, WidgetInputErrorView, IWidgetInputErrorView)
def setUp(self): super(SequenceWidgetTest, self).setUp() ztapi.browserViewProviding(ITextLine, TextWidget, IInputWidget) ztapi.browserViewProviding(IWidgetInputError, WidgetInputErrorView, IWidgetInputErrorView)
def setUp(test): setup.placelessSetUp() ztapi.browserViewProviding(ITextLine, TextWidget, IInputWidget) ztapi.browserViewProviding(IWidgetInputError, WidgetInputErrorView, IWidgetInputErrorView)
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)
def setUp(self): super(ObjectWidgetTest, self).setUp() self.field = Object(ITestContact, __name__=u'foo') ztapi.browserViewProviding(ITextLine, TextWidget, IInputWidget)
def setUp(test): placelesssetup.setUp() ztapi.browserViewProviding(ITextLine, TextWidget, IInputWidget)