-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a ZCML directive to create new viewlet manager interfaces. Update…
… docstrings.
- Loading branch information
Showing
14 changed files
with
270 additions
and
9 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
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
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
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
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
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
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
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,10 @@ | ||
<configure xmlns:meta="http://namespaces.zope.org/meta"> | ||
|
||
<meta:directives namespace="http://namespaces.zope.org/browser"> | ||
|
||
<meta:directive | ||
name="newViewletManager" | ||
schema=".zcml.IViewletManagerDirective" | ||
handler=".zcml.viewletManagerDirective" /> | ||
</meta:directives> | ||
</configure> |
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
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
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,77 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Tests for zcml.py | ||
""" | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
|
||
# disable: accessing protected members, too many methods | ||
# pylint: disable=W0212,R0904 | ||
|
||
import unittest | ||
|
||
from hamcrest import assert_that | ||
from hamcrest import has_property | ||
from hamcrest import is_not as does_not | ||
|
||
from zope.configuration import xmlconfig | ||
from zope.testing.cleanup import CleanUp | ||
|
||
from .. import viewlets | ||
|
||
class TestZCML(CleanUp, | ||
unittest.TestCase): | ||
|
||
def test_registers_interface(self): | ||
zcml = """ | ||
<configure xmlns="http://namespaces.zope.org/zope" | ||
xmlns:browser="http://namespaces.zope.org/browser"> | ||
<include package="nti.nikola_chameleon" file="meta.zcml" /> | ||
<browser:newViewletManager | ||
id="ILeftColumn" /> | ||
</configure> | ||
""" | ||
|
||
xmlconfig.string(zcml) | ||
|
||
assert_that(viewlets, has_property('ILeftColumn')) | ||
|
||
def test_viewlet_manager_in_same_zcml(self): | ||
assert_that(viewlets, does_not(has_property('ILeftColumn'))) | ||
zcml = """ | ||
<configure xmlns="http://namespaces.zope.org/zope" | ||
xmlns:browser="http://namespaces.zope.org/browser"> | ||
<include package="nti.nikola_chameleon" file="meta.zcml" /> | ||
<include package="zope.viewlet" file="meta.zcml" /> | ||
<browser:newViewletManager | ||
id="ILeftColumn" /> | ||
<browser:viewletManager | ||
name="left_column" | ||
provides="nti.nikola_chameleon.viewlets.ILeftColumn" | ||
permission="zope.Public" /> | ||
</configure> | ||
""" | ||
|
||
xmlconfig.string(zcml) | ||
assert_that(viewlets, has_property('ILeftColumn')) | ||
|
||
context = object() | ||
from zope.publisher.browser import TestRequest | ||
request = TestRequest() | ||
from zope.publisher.browser import BrowserView | ||
view = BrowserView(context, request) | ||
|
||
import zope.component | ||
from zope.viewlet import interfaces | ||
zope.component.getMultiAdapter( | ||
(context, request, view), | ||
interfaces.IViewletManager, | ||
name='left_column') | ||
|
||
zope.component.getMultiAdapter( | ||
(context, request, view), | ||
viewlets.ILeftColumn, | ||
name='left_column') |
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
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,13 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Holds viewlet manager interfaces defined by | ||
ZCML. | ||
There should be no actual contents in this file. | ||
.. versionadded:: 0.0.1a2 | ||
""" | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function |
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,69 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
ZCML directives. | ||
.. versionadded:: 0.0.1a2 | ||
""" | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
from zope import interface | ||
from zope.interface.interface import InterfaceClass | ||
#from zope.configuration.fields import GlobalInterface | ||
from zope.configuration.fields import PythonIdentifier | ||
from zope.viewlet.interfaces import IViewletManager | ||
|
||
|
||
from . import viewlets | ||
|
||
class IViewletManagerDirective(interface.Interface): | ||
""" | ||
Creates a new viewlet manager interface in the | ||
``nti.nikola_chameleon.viewlets`` package. | ||
""" | ||
|
||
id = PythonIdentifier( | ||
title=u"The class name of the interface", | ||
required=True | ||
) | ||
|
||
# TODO: Extend a viewlet manager interface? | ||
|
||
def viewletManagerDirective(_context, id): | ||
id = str(id) # ensure native string | ||
if id in dir(viewlets): | ||
return | ||
|
||
# We must do our work right now so that it can | ||
# be used by other directives. | ||
|
||
manager = InterfaceClass( | ||
id, (IViewletManager,), | ||
__doc__='Viewlet Manager', | ||
__module__='nti.nikola_chameleon.viewlets' | ||
) | ||
manager.setTaggedValue("zcml_created", True) | ||
|
||
setattr(viewlets, id, manager) | ||
|
||
|
||
def _cleanUp(): | ||
to_remove = [] | ||
for name, value in vars(viewlets).items(): | ||
try: | ||
if value.getTaggedValue('zcml_created'): | ||
to_remove.append(name) | ||
except (AttributeError, KeyError): | ||
pass | ||
|
||
for name in to_remove: | ||
delattr(viewlets, name) | ||
|
||
|
||
try: | ||
from zope.testing import cleanup | ||
except ImportError: | ||
pass | ||
else: | ||
cleanup.addCleanUp(_cleanUp) |