-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deactivted all BBB to ensure that we use only the latest code in zope…
….app Made almost all tests pass again, except the few that heavily depended on the old way of doing things: apidoc, module, presentation
- Loading branch information
0 parents
commit 75b8433
Showing
2 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2002 Zope Corporation and Contributors. | ||
# All Rights Reserved. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | ||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
# FOR A PARTICULAR PURPOSE. | ||
# | ||
############################################################################## | ||
"""Standard macros for page templates in the ZMI | ||
The macros are drawn from various different page templates. | ||
$Id$ | ||
""" | ||
__docformat__ = 'restructuredtext' | ||
import zope.interface | ||
|
||
from zope.app import zapi | ||
from zope.app.publisher.browser import BrowserView | ||
|
||
class Macros(object): | ||
zope.interface.implements(zope.interface.common.mapping.IItemMapping) | ||
|
||
macro_pages = () | ||
aliases = { | ||
'view': 'page', | ||
'dialog': 'page', | ||
'addingdialog': 'page' | ||
} | ||
|
||
def __getitem__(self, key): | ||
key = self.aliases.get(key, key) | ||
context = self.context | ||
request = self.request | ||
for name in self.macro_pages: | ||
page = zapi.getMultiAdapter((context, request), name=name) | ||
try: | ||
v = page[key] | ||
except KeyError: | ||
pass | ||
else: | ||
return v | ||
raise KeyError, key | ||
|
||
class StandardMacros(BrowserView, Macros): | ||
macro_pages = ('view_macros', 'dialog_macros') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2001, 2002 Zope Corporation and Contributors. | ||
# All Rights Reserved. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | ||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
# FOR A PARTICULAR PURPOSE. | ||
# | ||
############################################################################## | ||
"""Basic skin standard macros | ||
$Id$ | ||
""" | ||
import unittest | ||
from zope.interface import implements, Interface | ||
from zope.publisher.browser import TestRequest | ||
|
||
from zope.app.basicskin.standardmacros import Macros | ||
from zope.app.component.testing import PlacefulSetup | ||
from zope.app.publisher.interfaces.browser import IBrowserView | ||
from zope.app.testing import ztapi | ||
|
||
|
||
class ViewWithMacros(object): | ||
implements(IBrowserView) | ||
|
||
def __init__(self, context, request): | ||
self.context = context | ||
self.request = request | ||
|
||
def __call__(self): | ||
pass | ||
|
||
def __getitem__(self, key): | ||
return self.pages[key] | ||
|
||
pages = {} | ||
|
||
class I(Interface): pass | ||
|
||
class C(object): | ||
implements(I) | ||
|
||
class page1(ViewWithMacros): | ||
pages = {'foo':'page1_foo', | ||
'bar':'page1_bar'} | ||
|
||
class collides_with_page1(ViewWithMacros): | ||
pages = {'foo':'collides_with_page1_foo', | ||
'baz':'collides_with_page1_baz'} | ||
|
||
class works_with_page1(ViewWithMacros): | ||
pages = {'fish':'works_with_page1_fish', | ||
'tree':'works_with_page1_tree'} | ||
|
||
def createMacrosInstance(pages): | ||
|
||
class T(Macros): | ||
aliases = {'afoo': 'foo', 'abar': 'bar'} | ||
|
||
def __init__(self, context, request): | ||
self.context = context | ||
self.request = request | ||
macro_pages = pages | ||
return T(C(), TestRequest()) | ||
|
||
class Test(PlacefulSetup, unittest.TestCase): | ||
|
||
def setUp(self): | ||
PlacefulSetup.setUp(self) | ||
ztapi.browserView(I, 'page1', page1) | ||
ztapi.browserView(I, 'collides_with_page1', collides_with_page1) | ||
ztapi.browserView(I, 'works_with_page1', works_with_page1) | ||
|
||
def testSinglePage(self): | ||
macros = createMacrosInstance(('page1',)) | ||
self.assertEqual(macros['foo'], 'page1_foo') | ||
self.assertEqual(macros['bar'], 'page1_bar') | ||
self.assertRaises(KeyError, macros.__getitem__, 'fish') | ||
|
||
def testConcordentPages(self): | ||
macros = createMacrosInstance(('page1', 'works_with_page1')) | ||
self.assertEqual(macros['foo'], 'page1_foo') | ||
self.assertEqual(macros['bar'], 'page1_bar') | ||
self.assertEqual(macros['fish'], 'works_with_page1_fish') | ||
self.assertEqual(macros['tree'], 'works_with_page1_tree') | ||
self.assertRaises(KeyError, macros.__getitem__, 'pants') | ||
|
||
def testConflictingPages(self): | ||
macros = createMacrosInstance(('page1', 'collides_with_page1')) | ||
self.assertEqual(macros['foo'], 'page1_foo') | ||
self.assertEqual(macros['bar'], 'page1_bar') | ||
self.assertEqual(macros['baz'], 'collides_with_page1_baz') | ||
self.assertRaises(KeyError, macros.__getitem__, 'pants') | ||
|
||
def testMacroAliases(self): | ||
macros = createMacrosInstance(('page1', 'collides_with_page1')) | ||
self.assertEqual(macros['afoo'], 'page1_foo') | ||
self.assertEqual(macros['abar'], 'page1_bar') | ||
|
||
|
||
def test_suite(): | ||
loader = unittest.TestLoader() | ||
return loader.loadTestsFromTestCase(Test) | ||
|
||
if __name__=='__main__': | ||
unittest.TextTestRunner().run(test_suite()) |