[Checkins] SVN: zope.app.apidoc/trunk/src/zope/app/apidoc/ Fix functional test failures.
Yusei Tahara
yusei at domen.cx
Sun Apr 26 10:58:08 EDT 2009
Log message for revision 99524:
Fix functional test failures.
Stop using relative url for link and replace with absolute url.
Use placefulsetup in tests in order to check the real generated urls.
Changed:
A zope.app.apidoc/trunk/src/zope/app/apidoc/browser/utilities.py
U zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/README.txt
U zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/menu.py
U zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/module.py
U zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/module_index.pt
U zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/tests.py
U zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/zcml.py
U zope.app.apidoc/trunk/src/zope/app/apidoc/ifacemodule/browser.py
U zope.app.apidoc/trunk/src/zope/app/apidoc/ifacemodule/browser.txt
U zope.app.apidoc/trunk/src/zope/app/apidoc/ifacemodule/index.pt
U zope.app.apidoc/trunk/src/zope/app/apidoc/ifacemodule/tests.py
U zope.app.apidoc/trunk/src/zope/app/apidoc/typemodule/browser.py
U zope.app.apidoc/trunk/src/zope/app/apidoc/utilitymodule/browser.py
U zope.app.apidoc/trunk/src/zope/app/apidoc/utilitymodule/browser.txt
U zope.app.apidoc/trunk/src/zope/app/apidoc/utilitymodule/index.pt
U zope.app.apidoc/trunk/src/zope/app/apidoc/utilitymodule/tests.py
U zope.app.apidoc/trunk/src/zope/app/apidoc/zcmlmodule/browser.py
U zope.app.apidoc/trunk/src/zope/app/apidoc/zcmlmodule/browser.txt
U zope.app.apidoc/trunk/src/zope/app/apidoc/zcmlmodule/index.pt
U zope.app.apidoc/trunk/src/zope/app/apidoc/zcmlmodule/tests.py
-=-
Added: zope.app.apidoc/trunk/src/zope/app/apidoc/browser/utilities.py
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/browser/utilities.py (rev 0)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/browser/utilities.py 2009-04-26 14:58:08 UTC (rev 99524)
@@ -0,0 +1,27 @@
+##############################################################################
+#
+# Copyright (c) 2009 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.
+#
+##############################################################################
+"""Common Utilities for Browser View
+
+$Id$
+"""
+from zope.app.apidoc.apidoc import APIDocumentation
+from zope.traversing.browser import absoluteURL
+from zope.traversing.api import getParent
+from zope.security.proxy import isinstance
+
+def findAPIDocumentationRootURL(context, request):
+ if isinstance(context, APIDocumentation):
+ return absoluteURL(context, request)
+ else:
+ return findAPIDocumentationRootURL(getParent(context), request)
Modified: zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/README.txt
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/README.txt 2009-04-26 14:53:06 UTC (rev 99523)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/README.txt 2009-04-26 14:58:08 UTC (rev 99524)
@@ -9,9 +9,7 @@
We will also need the code browser documentation module:
- >>> from zope.component import getUtility
- >>> from zope.app.apidoc.interfaces import IDocumentationModule
- >>> cm = getUtility(IDocumentationModule, 'Code')
+ >>> cm = apidoc.get('Code')
The `zope` package is already registered and available with the code module.
@@ -45,7 +43,7 @@
>>> pprint(details.getClasses())
[{'doc': 'Represent the code browser documentation root',
'name': 'CodeModule',
- 'url': 'http://127.0.0.1/zope/app/apidoc/codemodule/codemodule/CodeModule'}]
+ 'url': 'http://127.0.0.1/++apidoc++/Code/zope/app/apidoc/codemodule/codemodule/CodeModule'}]
This module doesn't contain anything else.
@@ -76,17 +74,17 @@
>>> bc.request = details.request
>>> pprint(bc())
[{'name': u'[top]',
- 'url': 'http://127.0.0.1'},
+ 'url': 'http://127.0.0.1/++apidoc++/Code'},
{'name': u'zope',
- 'url': 'http://127.0.0.1/zope'},
+ 'url': 'http://127.0.0.1/++apidoc++/Code/zope'},
{'name': 'app',
- 'url': 'http://127.0.0.1/zope/app'},
+ 'url': 'http://127.0.0.1/++apidoc++/Code/zope/app'},
{'name': 'apidoc',
- 'url': 'http://127.0.0.1/zope/app/apidoc'},
+ 'url': 'http://127.0.0.1/++apidoc++/Code/zope/app/apidoc'},
{'name': 'codemodule',
- 'url': 'http://127.0.0.1/zope/app/apidoc/codemodule'},
+ 'url': 'http://127.0.0.1/++apidoc++/Code/zope/app/apidoc/codemodule'},
{'name': 'codemodule',
- 'url': 'http://127.0.0.1/zope/app/apidoc/codemodule/codemodule'}]
+ 'url': 'http://127.0.0.1/++apidoc++/Code/zope/app/apidoc/codemodule/codemodule'}]
Class Details
@@ -110,7 +108,7 @@
>>> pprint(details.getBases())
[{'path': 'zope.app.apidoc.codemodule.module.Module',
- 'url': 'http://127.0.0.1/zope/app/apidoc/codemodule/module/Module'}]
+ 'url': 'http://127.0.0.1/++apidoc++/Code/zope/app/apidoc/codemodule/module/Module'}]
`getKnownSubclasses()`
~~~~~~~~~~~~~~~~~~~~~~
@@ -131,9 +129,9 @@
... zope.app.apidoc.apidoc.APIDocumentation,
... zope.app.apidoc.codemodule.codemodule.Module]))
[{'path': 'zope.app.apidoc.apidoc.APIDocumentation',
- 'url': 'http://127.0.0.1/zope/app/apidoc/apidoc/APIDocumentation'},
+ 'url': 'http://127.0.0.1/++apidoc++/Code/zope/app/apidoc/apidoc/APIDocumentation'},
{'path': 'zope.app.apidoc.codemodule.module.Module',
- 'url': 'http://127.0.0.1/zope/app/apidoc/codemodule/module/Module'}]
+ 'url': 'http://127.0.0.1/++apidoc++/Code/zope/app/apidoc/codemodule/module/Module'}]
`getBaseURL()`
~~~~~~~~~~~~~~
@@ -144,7 +142,7 @@
we have not setup all path elements.
>>> details.getBaseURL()
- 'http://127.0.0.1'
+ 'http://127.0.0.1/++apidoc++'
`getInterfaces()`
~~~~~~~~~~~~~~~~~
@@ -251,11 +249,8 @@
Return the URL for the API Documentation Tool.
-Note that the following output is a bit different than usual, since
-we have not setup all path elements.
-
>>> details.getBaseURL()
- 'http://127.0.0.1'
+ 'http://127.0.0.1/++apidoc++'
Text File Details
@@ -334,11 +329,8 @@
module.
>>> details.url()
- u'http://127.0.0.1/../ZCML/ALL/configure/index.html'
+ u'http://127.0.0.1/++apidoc++/ZCML/ALL/configure/index.html'
-The result is a bit strange, since the ZCML Documentation module is the
-containment root.
-
`objectURL(value, field, rootURL)`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -349,7 +341,7 @@
>>> field = GlobalObject()
>>> details.objectURL('.interfaces.IZCMLFile', field, '')
- '/../Interface/zope.app.apidoc.codemodule.interfaces.IZCMLFile/index.html'
+ 'http://127.0.0.1/++apidoc++/Interface/zope.app.apidoc.codemodule.interfaces.IZCMLFile/index.html'
>>> details.objectURL('.zcml.ZCMLFile', field, '')
'/zope/app/apidoc/codemodule/zcml/ZCMLFile/index.html'
@@ -379,7 +371,7 @@
>>> pprint(details.attributes())
[{'name': u'class',
'url':
- 'http://127.0.0.1/zope/app/apidoc/codemodule/module/Module/index.html',
+ 'http://127.0.0.1/++apidoc++/Code/zope/app/apidoc/codemodule/module/Module/index.html',
'value': u'.module.Module',
'values': []}]
@@ -514,7 +506,7 @@
You can also get the base URL of the request:
>>> inspect.getBaseURL()
- 'http://127.0.0.1'
+ 'http://127.0.0.1/++apidoc++'
Next you can get a list of all directly provided interfaces:
Modified: zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/menu.py
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/menu.py 2009-04-26 14:53:06 UTC (rev 99523)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/menu.py 2009-04-26 14:58:08 UTC (rev 99524)
@@ -34,11 +34,9 @@
"""Find the classes that match a partial path.
Examples::
- >>> from zope.component import getUtility
>>> from zope.app.apidoc.codemodule.class_ import Class
- >>> from zope.app.apidoc.interfaces import IDocumentationModule
- >>> cm = getUtility(IDocumentationModule, 'Code')
+ >>> cm = apidoc.get('Code')
>>> mod = cm['zope']['app']['apidoc']['codemodule']['browser']
Setup a couple of classes and register them.
@@ -58,7 +56,7 @@
>>> from zope.app.apidoc.codemodule.browser.menu import Menu
>>> from zope.publisher.browser import TestRequest
>>> menu = Menu()
- >>> menu.context = None
+ >>> menu.context = cm
Testing the method with various inputs.
@@ -67,22 +65,22 @@
>>> pprint(info)
[{'path': 'zope.app.apidoc.codemodule.browser.Foo',
- 'url': 'http://127.0.0.1/zope/app/apidoc/codemodule/browser/Foo/'},
+ 'url': 'http://127.0.0.1/++apidoc++/Code/zope/app/apidoc/codemodule/browser/Foo/'},
{'path': 'zope.app.apidoc.codemodule.browser.Foo2',
- 'url': 'http://127.0.0.1/zope/app/apidoc/codemodule/browser/Foo2/'}]
+ 'url': 'http://127.0.0.1/++apidoc++/Code/zope/app/apidoc/codemodule/browser/Foo2/'}]
>>> menu.request = TestRequest(form={'path': 'o2'})
>>> info = menu.findClasses()
>>> pprint(info)
[{'path': 'zope.app.apidoc.codemodule.browser.Foo2',
- 'url': 'http://127.0.0.1/zope/app/apidoc/codemodule/browser/Foo2/'}]
+ 'url': 'http://127.0.0.1/++apidoc++/Code/zope/app/apidoc/codemodule/browser/Foo2/'}]
>>> menu.request = TestRequest(form={'path': 'Blah'})
>>> info = menu.findClasses()
>>> pprint(info)
[{'path': 'zope.app.apidoc.codemodule.browser.Blah',
- 'url': 'http://127.0.0.1/zope/app/apidoc/codemodule/browser/Blah/'}]
+ 'url': 'http://127.0.0.1/++apidoc++/Code/zope/app/apidoc/codemodule/browser/Blah/'}]
"""
path = self.request.get('path', None)
@@ -105,12 +103,8 @@
"""Find all classes
Examples::
- >>> from zope.component import getUtility
>>> from zope.app.apidoc.codemodule.class_ import Class
- >>> from zope.app.apidoc.interfaces import IDocumentationModule
-
-
- >>> cm = getUtility(IDocumentationModule, 'Code')
+ >>> cm = apidoc.get('Code')
>>> mod = cm['zope']['app']['apidoc']['codemodule']['browser']
Setup a couple of classes and register them.
@@ -130,7 +124,7 @@
>>> from zope.app.apidoc.codemodule.browser.menu import Menu
>>> from zope.publisher.browser import TestRequest
>>> menu = Menu()
- >>> menu.context = None
+ >>> menu.context = cm
Testing the method with various inputs.
Modified: zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/module.py
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/module.py 2009-04-26 14:53:06 UTC (rev 99523)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/module.py 2009-04-26 14:58:08 UTC (rev 99524)
@@ -32,11 +32,8 @@
from zope.app.apidoc.codemodule.interfaces import IFunctionDocumentation
from zope.app.apidoc.codemodule.interfaces import IZCMLFile
from zope.app.apidoc.codemodule.interfaces import ITextFile
+from zope.app.apidoc.browser.utilities import findAPIDocumentationRootURL
-def findAPIDocumentationRoot(obj, request):
- if isinstance(obj, APIDocumentation):
- return absoluteURL(obj, request)
- return findAPIDocumentationRoot(getParent(obj), request)
def formatDocString(text, module=None, summary=False):
"""Format a doc string for display.
@@ -67,12 +64,6 @@
def __init__(self, context, request):
super(ModuleDetails, self).__init__(context, request)
- try:
- self.apidocRoot = findAPIDocumentationRoot(context, request)
- except TypeError:
- # Probably context without location; it's a test
- self.apidocRoot = ''
-
items = list(self.context.items())
items.sort()
self.text_files = []
@@ -106,6 +97,9 @@
elif ITextFile.providedBy(obj):
self.text_files.append(entry)
+ def getAPIDocRootURL(self):
+ return findAPIDocumentationRootURL(self.context, self.request)
+
def getDoc(self):
"""Get the doc string of the module, formatted as HTML."""
return formatDocString(
Modified: zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/module_index.pt
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/module_index.pt 2009-04-26 14:53:06 UTC (rev 99523)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/module_index.pt 2009-04-26 14:58:08 UTC (rev 99524)
@@ -1,6 +1,7 @@
<html metal:use-macro="views/apidoc_macros/details"
i18n:domain="zope">
-<body metal:fill-slot="contents">
+<body metal:fill-slot="contents"
+ tal:define="rootURL view/getAPIDocRootURL">
<!-- Note: don't use path expressions of the form "context/*" in this
template, since module objects have items, and path expressions
@@ -39,7 +40,7 @@
<b tal:repeat="iface ifaces">
<a href=""
tal:attributes="
- href string:${view/apidocRoot}/Interface/${iface/path}/index.html"
+ href string:${rootURL}/Interface/${iface/path}/index.html"
tal:content="iface/name" /><span tal:condition="not:repeat/iface/end">,</span>
</b>
</p>
@@ -87,7 +88,7 @@
<td width="20%">
<a href=""
tal:attributes="
- href string:${view/apidocRoot}/Interface/${iface/path}/index.html"
+ href string:${rootURL}/Interface/${iface/path}/index.html"
tal:content="iface/name" />
</td>
<td width="80%" tal:content="iface/doc">
Modified: zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/tests.py
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/tests.py 2009-04-26 14:53:06 UTC (rev 99523)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/tests.py 2009-04-26 14:58:08 UTC (rev 99524)
@@ -20,7 +20,7 @@
import re
from zope.component.interfaces import IFactory
from zope.configuration import xmlconfig
-from zope.interface import directlyProvides, implements
+from zope.interface import implements
from zope.testing import doctest, doctestunit, renormalizing
from zope.traversing.interfaces import IContainmentRoot
@@ -34,6 +34,7 @@
from zope.app.testing.functional import FunctionalDocFileSuite
from zope.app.apidoc.interfaces import IDocumentationModule
+from zope.app.apidoc.apidoc import APIDocumentation
from zope.app.apidoc.codemodule.interfaces import IAPIDocRootModule
from zope.app.apidoc.codemodule.codemodule import CodeModule
from zope.app.apidoc.testing import APIDocLayer
@@ -67,17 +68,17 @@
class RootModule(str):
implements(IAPIDocRootModule)
+
+ # Register zope package to apidoc
ztapi.provideUtility(IAPIDocRootModule, RootModule('zope'), "zope")
- module = CodeModule()
- module.__name__ = ''
- directlyProvides(module, IContainmentRoot)
- ztapi.provideUtility(IDocumentationModule, module, "Code")
+ # Set up apidoc module
+ test.globs['apidoc'] = APIDocumentation(test.globs['rootFolder'],
+ '++apidoc++')
- module = ZCMLModule()
- module.__name__ = ''
- directlyProvides(module, IContainmentRoot)
- ztapi.provideUtility(IDocumentationModule, module, "ZCML")
+ # Register documentation modules
+ ztapi.provideUtility(IDocumentationModule, CodeModule(), "Code")
+ ztapi.provideUtility(IDocumentationModule, ZCMLModule(), "ZCML")
# Register Renderer Components
ztapi.provideUtility(IFactory, ReStructuredTextSourceFactory,
Modified: zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/zcml.py
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/zcml.py 2009-04-26 14:53:06 UTC (rev 99523)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/zcml.py 2009-04-26 14:58:08 UTC (rev 99524)
@@ -26,6 +26,7 @@
from zope.app.apidoc.interfaces import IDocumentationModule
from zope.app.apidoc.utilities import getPythonPath, isReferencable
+from zope.app.apidoc.browser.utilities import findAPIDocumentationRootURL
from zope.app.apidoc.zcmlmodule import quoteNS
from zope.app.apidoc.codemodule.interfaces import IRootDirective
@@ -83,8 +84,8 @@
zcml = getUtility(IDocumentationModule, 'ZCML')
if name not in zcml[ns]:
ns = 'ALL'
- link = '%s/../ZCML/%s/%s/index.html' %(
- absoluteURL(findDocModule(self), self.request), ns, name)
+ link = '%s/ZCML/%s/%s/index.html' % (
+ findAPIDocumentationRootURL(self.context, self.request), ns, name)
if subDirective:
link += '#' + subDirective.name[1]
return link
@@ -101,12 +102,13 @@
# probably an object that does not like to play nice with the CA
isInterface = False
- # The object mught be an instance; in this case get a link to the class
+ # The object might be an instance; in this case get a link to the class
if not hasattr(obj, '__name__'):
obj = getattr(obj, '__class__')
path = getPythonPath(obj)
if isInterface:
- return rootURL+'/../Interface/%s/index.html' % path
+ apidoc_url = findAPIDocumentationRootURL(self.context, self.request)
+ return '%s/Interface/%s/index.html' % (apidoc_url, path)
if isReferencable(path):
return rootURL + '/%s/index.html' %(path.replace('.', '/'))
Modified: zope.app.apidoc/trunk/src/zope/app/apidoc/ifacemodule/browser.py
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/ifacemodule/browser.py 2009-04-26 14:53:06 UTC (rev 99523)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/ifacemodule/browser.py 2009-04-26 14:58:08 UTC (rev 99524)
@@ -36,25 +36,18 @@
from zope.app.apidoc.apidoc import APIDocumentation
from zope.app.apidoc import classregistry
from zope.app.apidoc import interface, component, presentation
+from zope.app.apidoc.browser.utilities import findAPIDocumentationRootURL
-
-def findAPIDocumentationRoot(obj, request):
- if isinstance(obj, APIDocumentation):
- return absoluteURL(obj, request)
- return findAPIDocumentationRoot(getParent(obj), request)
-
class InterfaceDetails(BrowserView):
"""View class for an Interface."""
def __init__(self, context, request):
super(InterfaceDetails, self).__init__(context, request)
self._prepareViews()
- try:
- self.apidocRoot = findAPIDocumentationRoot(context, request)
- except TypeError:
- # Probably context without location; it's a test
- self.apidocRoot = ''
+ def getAPIDocRootURL(self):
+ return findAPIDocumentationRootURL(self.context, self.request)
+
def getId(self):
"""Return the id of the field as it is defined for the interface
utility.
Modified: zope.app.apidoc/trunk/src/zope/app/apidoc/ifacemodule/browser.txt
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/ifacemodule/browser.txt 2009-04-26 14:53:06 UTC (rev 99523)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/ifacemodule/browser.txt 2009-04-26 14:58:08 UTC (rev 99524)
@@ -153,13 +153,7 @@
Now that the initial setup is done, we can create an interface that is located
in the interface documentation module
- >>> from zope.app.apidoc.ifacemodule.ifacemodule import InterfaceModule
- >>> ifacemodule = InterfaceModule()
-
- >>> from zope.app.apidoc.tests import Root
- >>> ifacemodule.__parent__ = Root()
- >>> ifacemodule.__name__ = 'Interfaces'
-
+ >>> ifacemodule = apidoc.get('Interface')
>>> from zope.location import LocationProxy
>>> iface = LocationProxy(IFoo, ifacemodule, 'IFoo')
@@ -324,6 +318,17 @@
'name': 'Interface'}],
'zcml': None},
{'doc': u'',
+ 'factory': 'zope.site.site.SiteManagerAdapter',
+ 'factory_url': 'zope/site/site/SiteManagerAdapter',
+ 'name': u'',
+ 'provided': {'module': 'zope.component.interfaces',
+ 'name': 'IComponentLookup'},
+ 'required': [{'isInterface': True,
+ 'isType': False,
+ 'module': 'zope.interface',
+ 'name': 'Interface'}],
+ 'zcml': None},
+ {'doc': u'',
'factory': 'zope.traversing.adapters.DefaultTraversable',
'factory_url': 'zope/traversing/adapters/DefaultTraversable',
'name': u'',
Modified: zope.app.apidoc/trunk/src/zope/app/apidoc/ifacemodule/index.pt
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/ifacemodule/index.pt 2009-04-26 14:53:06 UTC (rev 99523)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/ifacemodule/index.pt 2009-04-26 14:58:08 UTC (rev 99524)
@@ -1,7 +1,7 @@
<html metal:use-macro="context/@@apidoc_macros/details"
i18n:domain="zope">
<body metal:fill-slot="contents"
- tal:define="rootURL view/apidocRoot">
+ tal:define="rootURL view/getAPIDocRootURL">
<h1 class="details-header">
<span class="pre-header" i18n:translate="">Interface</span><br />
Modified: zope.app.apidoc/trunk/src/zope/app/apidoc/ifacemodule/tests.py
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/ifacemodule/tests.py 2009-04-26 14:53:06 UTC (rev 99523)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/ifacemodule/tests.py 2009-04-26 14:58:08 UTC (rev 99524)
@@ -22,20 +22,28 @@
from zope.testing import doctest, doctestunit
from zope.app.apidoc.testing import APIDocLayer
+from zope.app.apidoc.apidoc import APIDocumentation
+from zope.app.apidoc.interfaces import IDocumentationModule
+from zope.app.apidoc.ifacemodule.ifacemodule import InterfaceModule
from zope.app.renderer.rest import ReStructuredTextSourceFactory
from zope.app.renderer.rest import IReStructuredTextSource
from zope.app.renderer.rest import ReStructuredTextToHTMLRenderer
-from zope.app.testing import placelesssetup, ztapi, setup
+from zope.app.testing import ztapi, setup
from zope.app.testing.functional import BrowserTestCase
from zope.app.tree.interfaces import IUniqueId
from zope.app.tree.adapters import LocationUniqueId
def setUp(test):
- placelesssetup.setUp()
- setup.setUpTraversal()
+ root_folder = setup.placefulSetUp(True)
ztapi.provideAdapter(IInterface, IUniqueId, LocationUniqueId)
+ # Set up apidoc module
+ test.globs['apidoc'] = APIDocumentation(root_folder, '++apidoc++')
+
+ # Register InterfaceModule
+ ztapi.provideUtility(IDocumentationModule, InterfaceModule(), "Interface")
+
# Register Renderer Components
ztapi.provideUtility(IFactory, ReStructuredTextSourceFactory,
'zope.source.rest')
@@ -46,6 +54,10 @@
'zope.source.stx')
+def tearDown(test):
+ setup.placefulTearDown()
+
+
class InterfaceModuleTests(BrowserTestCase):
"""Just a couple of tests ensuring that the templates render."""
@@ -82,11 +94,11 @@
InterfaceModuleTests.layer = APIDocLayer
return unittest.TestSuite((
doctest.DocFileSuite('README.txt',
- setUp=setUp, tearDown=placelesssetup.tearDown,
+ setUp=setUp, tearDown=tearDown,
globs={'pprint': doctestunit.pprint},
optionflags=doctest.NORMALIZE_WHITESPACE),
doctest.DocFileSuite('browser.txt',
- setUp=setUp, tearDown=placelesssetup.tearDown,
+ setUp=setUp, tearDown=tearDown,
globs={'pprint': doctestunit.pprint},
optionflags=doctest.NORMALIZE_WHITESPACE),
unittest.makeSuite(InterfaceModuleTests),
Modified: zope.app.apidoc/trunk/src/zope/app/apidoc/typemodule/browser.py
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/typemodule/browser.py 2009-04-26 14:53:06 UTC (rev 99523)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/typemodule/browser.py 2009-04-26 14:58:08 UTC (rev 99524)
@@ -20,7 +20,9 @@
from zope.security.proxy import isinstance, removeSecurityProxy
from zope.traversing.api import getName
+from zope.app.apidoc.browser.utilities import findAPIDocumentationRootURL
+
class Menu(object):
"""Menu View Helper Class"""
@@ -35,4 +37,5 @@
def getMenuLink(self, node):
"""Return the HTML link of the node that is displayed in the menu."""
- return '../Interface/%s/index.html' % getName(node.context)
+ root_url = findAPIDocumentationRootURL(self.context, self.request)
+ return '%s/Interface/%s/index.html' % (root_url, getName(node.context))
Modified: zope.app.apidoc/trunk/src/zope/app/apidoc/utilitymodule/browser.py
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/utilitymodule/browser.py 2009-04-26 14:53:06 UTC (rev 99523)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/utilitymodule/browser.py 2009-04-26 14:58:08 UTC (rev 99524)
@@ -26,10 +26,14 @@
from zope.app.apidoc.utilities import getPythonPath
from zope.app.apidoc.utilitymodule.utilitymodule import NONAME, Utility
from zope.app.apidoc.utilitymodule.utilitymodule import UtilityInterface
+from zope.app.apidoc.browser.utilities import findAPIDocumentationRootURL
class UtilityDetails(object):
"""Utility Details View."""
+ def getAPIDocRootURL(self):
+ return findAPIDocumentationRootURL(self.context, self.request)
+
def getName(self):
"""Get the name of the utility."""
name = self.context.name
@@ -68,9 +72,10 @@
def getMenuLink(self, node):
"""Return the HTML link of the node that is displayed in the menu."""
obj = node.context
+ apidoc_url = findAPIDocumentationRootURL(self.context, self.request)
if isinstance(obj, Utility):
iface = getParent(obj)
- return './'+getName(iface) + '/' + getName(obj) + '/index.html'
+ return '%s/Utility/%s/%s/index.html' % (apidoc_url, getName(iface), getName(obj))
if isinstance(obj, UtilityInterface):
- return '../Interface/'+getName(obj) + '/index.html'
+ return '%s/Interface/%s/index.html' % (apidoc_url, getName(obj))
return None
Modified: zope.app.apidoc/trunk/src/zope/app/apidoc/utilitymodule/browser.txt
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/utilitymodule/browser.txt 2009-04-26 14:53:06 UTC (rev 99523)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/utilitymodule/browser.txt 2009-04-26 14:58:08 UTC (rev 99524)
@@ -15,6 +15,14 @@
>>> from zope.app.apidoc.utilitymodule.browser import Menu
>>> menu = Menu()
+then we need a Utility module instance and add context and request to menu:
+
+ >>> from zope.publisher.browser import TestRequest
+ >>> module = apidoc.get('Utility')
+ >>> request = TestRequest()
+ >>> menu.context = module
+ >>> menu.request = request
+
Now we want to get the menu title and link for a utility interface. To do that
we first have to create a utility interface
@@ -32,7 +40,7 @@
>>> menu.getMenuTitle(node)
'iface'
>>> menu.getMenuLink(node)
- '../Interface/foo.bar.iface/index.html'
+ 'http://127.0.0.1/++apidoc++/Interface/foo.bar.iface/index.html'
Next, let's get the menu title and link for a utility with a name. We first
have to create a utility registration
@@ -53,7 +61,7 @@
>>> menu.getMenuTitle(node)
'FooBar'
>>> menu.getMenuLink(node)
- './foo.bar.iface/Rm9vQmFy/index.html'
+ 'http://127.0.0.1/++apidoc++/Utility/foo.bar.iface/Rm9vQmFy/index.html'
Finally, we get menu title and link for a utility without a name:
@@ -68,7 +76,7 @@
>>> menu.getMenuTitle(node)
'no name'
>>> menu.getMenuLink(node)
- './foo.bar.iface/X19ub25hbWVfXw==/index.html'
+ 'http://127.0.0.1/++apidoc++/Utility/foo.bar.iface/X19ub25hbWVfXw==/index.html'
`UtilityDetails` class
Modified: zope.app.apidoc/trunk/src/zope/app/apidoc/utilitymodule/index.pt
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/utilitymodule/index.pt 2009-04-26 14:53:06 UTC (rev 99523)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/utilitymodule/index.pt 2009-04-26 14:58:08 UTC (rev 99524)
@@ -2,7 +2,7 @@
i18n:domain="zope">
<body metal:fill-slot="contents"
tal:define="iface view/getInterface;
- rootURL iface/apidocRoot">
+ rootURL string:${view/getAPIDocRootURL}">
<h1 class="details-header">
<a href=""
Modified: zope.app.apidoc/trunk/src/zope/app/apidoc/utilitymodule/tests.py
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/utilitymodule/tests.py 2009-04-26 14:53:06 UTC (rev 99523)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/utilitymodule/tests.py 2009-04-26 14:58:08 UTC (rev 99524)
@@ -21,20 +21,33 @@
from zope.traversing.interfaces import IPhysicallyLocatable
from zope.location.traversing import LocationPhysicallyLocatable
+from zope.app.apidoc.utilitymodule.utilitymodule import UtilityModule
+from zope.app.apidoc.interfaces import IDocumentationModule
+from zope.app.apidoc.apidoc import APIDocumentation
from zope.app.apidoc.testing import APIDocLayer
-from zope.app.testing import placelesssetup, ztapi
+from zope.app.testing import setup, ztapi
from zope.app.testing.functional import BrowserTestCase
from zope.app.tree.interfaces import IUniqueId
from zope.app.tree.adapters import LocationUniqueId
+
def setUp(test):
- placelesssetup.setUp()
-
+ root_folder = setup.placefulSetUp(True)
ztapi.provideAdapter(None, IUniqueId, LocationUniqueId)
ztapi.provideAdapter(None, IPhysicallyLocatable,
LocationPhysicallyLocatable)
+ # Set up apidoc module
+ test.globs['apidoc'] = APIDocumentation(root_folder, '++apidoc++')
+ # Register documentation modules
+ ztapi.provideUtility(IDocumentationModule, UtilityModule(), 'Utility')
+
+
+def tearDown(test):
+ setup.placefulTearDown()
+
+
class UtilityModuleTests(BrowserTestCase):
"""Just a couple of tests ensuring that the templates render."""
@@ -79,13 +92,13 @@
return unittest.TestSuite((
doctest.DocFileSuite('README.txt',
setUp=setUp,
- tearDown=placelesssetup.tearDown,
+ tearDown=tearDown,
globs={'pprint': doctestunit.pprint},
optionflags=doctest.NORMALIZE_WHITESPACE|
doctest.ELLIPSIS),
doctest.DocFileSuite('browser.txt',
setUp=setUp,
- tearDown=placelesssetup.tearDown,
+ tearDown=tearDown,
globs={'pprint': doctestunit.pprint},
optionflags=doctest.NORMALIZE_WHITESPACE),
unittest.makeSuite(UtilityModuleTests),
Modified: zope.app.apidoc/trunk/src/zope/app/apidoc/zcmlmodule/browser.py
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/zcmlmodule/browser.py 2009-04-26 14:53:06 UTC (rev 99523)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/zcmlmodule/browser.py 2009-04-26 14:58:08 UTC (rev 99524)
@@ -28,6 +28,7 @@
from zope.app.apidoc.ifacemodule.browser import InterfaceDetails
from zope.app.apidoc.utilities import getPythonPath, isReferencable
from zope.app.apidoc.utilities import relativizePath
+from zope.app.apidoc.browser.utilities import findAPIDocumentationRootURL
class Menu(object):
"""Menu View Helper Class"""
@@ -47,7 +48,9 @@
obj = node.context
if isinstance(obj, Directive):
ns = getParent(obj)
- return './'+getName(ns) + '/' + getName(obj) + '/index.html'
+ apidoc_url = findAPIDocumentationRootURL(self.context, self.request)
+ return '%s/%s/%s/index.html' % (apidoc_url, getName(ns),
+ getName(obj))
return None
@@ -61,6 +64,9 @@
class DirectiveDetails(object):
"""View class for a Directive."""
+ def getAPIDocRootURL(self):
+ return findAPIDocumentationRootURL(self.context, self.request)
+
def _getInterfaceDetails(self, schema):
schema = LocationProxy(schema,
self.context,
Modified: zope.app.apidoc/trunk/src/zope/app/apidoc/zcmlmodule/browser.txt
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/zcmlmodule/browser.txt 2009-04-26 14:53:06 UTC (rev 99523)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/zcmlmodule/browser.txt 2009-04-26 14:58:08 UTC (rev 99524)
@@ -13,11 +13,10 @@
then we create a ZCML module instance:
- >>> from zope.app.apidoc.zcmlmodule import ZCMLModule
- >>> from zope.app.apidoc.tests import Root
- >>> module = ZCMLModule()
- >>> module.__parent__ = Root()
- >>> module.__name__ = 'ZCML'
+ >>> from zope.publisher.browser import TestRequest
+ >>> module = apidoc.get('ZCML')
+ >>> menu.context = module
+ >>> menu.request = TestRequest()
Now we create a namespace representing directives available in all namespaces
@@ -63,7 +62,7 @@
>>> menu.getMenuTitle(node)
'page'
>>> menu.getMenuLink(node)
- './http_co__sl__sl_namespaces.zope.org_sl_browser/page/index.html'
+ 'http://127.0.0.1/++apidoc++/http_co__sl__sl_namespaces.zope.org_sl_browser/page/index.html'
Note that the directive's namespace URL is encoded, so it can be used in a
URL.
@@ -87,7 +86,6 @@
Now we can isntantiate the view:
- >>> from zope.publisher.browser import TestRequest
>>> from zope.app.apidoc.zcmlmodule.browser import DirectiveDetails
>>> details = DirectiveDetails()
@@ -214,4 +212,4 @@
'info': 'info',
'name': 'foo',
'namespace': 'browser',
- 'schema': <zope.app.apidoc.ifacemodule.browser.InterfaceDetails ...>}]
\ No newline at end of file
+ 'schema': <zope.app.apidoc.ifacemodule.browser.InterfaceDetails ...>}]
Modified: zope.app.apidoc/trunk/src/zope/app/apidoc/zcmlmodule/index.pt
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/zcmlmodule/index.pt 2009-04-26 14:53:06 UTC (rev 99523)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/zcmlmodule/index.pt 2009-04-26 14:58:08 UTC (rev 99524)
@@ -2,7 +2,7 @@
i18n:domain="zope">
<body metal:fill-slot="contents"
tal:define="schema view/getSchema;
- rootURL string:../../..">
+ rootURL view/getAPIDocRootURL">
<h1 class="details-header">
<span tal:replace="context/zope:name" />
@@ -39,7 +39,7 @@
<i i18n:translate="">Handler:</i>
<a href=""
tal:attributes="href
- string:../../../Code/${handler/url}/index.html"
+ string:${rootURL}/Code/${handler/url}/index.html"
tal:content="handler/path">
</a>
</div>
@@ -48,7 +48,7 @@
<div class="indent">
<a href="" tal:attributes="href
- string:../../../Interface/${schema/getId}/index.html">
+ string:${rootURL}/Interface/${schema/getId}/index.html">
<h3 tal:content="schema/getId">zope.fields.Schema</h3>
</a>
</div>
@@ -97,7 +97,7 @@
<i i18n:translate="">Handler:</i>
<a href=""
tal:attributes="href
- string:../../../Code/${dir/handler/url}/index.html"
+ string:${rootURL}/Code/${dir/handler/url}/index.html"
tal:content="dir/handler/path">
</a>
</div>
@@ -105,7 +105,7 @@
<div class="indent">
<a href=""
tal:attributes="href
- string:../../../Interface/${dir/schema/getId}/index.html">
+ string:${rootURL}/Interface/${dir/schema/getId}/index.html">
<h3 tal:content="dir/schema/getId">zope.fields.Schema</h3>
</a>
</div>
Modified: zope.app.apidoc/trunk/src/zope/app/apidoc/zcmlmodule/tests.py
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/zcmlmodule/tests.py 2009-04-26 14:53:06 UTC (rev 99523)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/zcmlmodule/tests.py 2009-04-26 14:58:08 UTC (rev 99524)
@@ -25,11 +25,13 @@
import zope.app.appsetup.appsetup
from zope.app.tree.interfaces import IUniqueId
from zope.app.tree.adapters import LocationUniqueId
-from zope.app.testing import placelesssetup, ztapi
+from zope.app.testing import setup, ztapi
from zope.app.testing.functional import BrowserTestCase
from zope.app.apidoc.testing import APIDocLayer
from zope.app.apidoc.tests import Root
+from zope.app.apidoc.apidoc import APIDocumentation
+from zope.app.apidoc.interfaces import IDocumentationModule
from zope.app.apidoc.zcmlmodule import Namespace, Directive
from zope.app.apidoc.zcmlmodule import ZCMLModule
from zope.app.apidoc.tests import Root
@@ -37,12 +39,18 @@
def setUp(test):
- placelesssetup.setUp()
+ root_folder = setup.placefulSetUp(True)
ztapi.provideAdapter(None, IUniqueId, LocationUniqueId)
ztapi.provideAdapter(None, IPhysicallyLocatable,
LocationPhysicallyLocatable)
+ # Set up apidoc module
+ test.globs['apidoc'] = APIDocumentation(root_folder, '++apidoc++')
+
+ # Register documentation modules
+ ztapi.provideUtility(IDocumentationModule, ZCMLModule(), 'ZCML')
+
config_file = os.path.join(
os.path.dirname(zope.app.zcmlfiles.__file__), 'meta.zcml')
@@ -53,7 +61,7 @@
config_file, zope.app.zcmlfiles, execute=False)
def tearDown(test):
- placelesssetup.tearDown()
+ setup.placefulTearDown()
zope.app.appsetup.appsetup.__config_context = old_context
from zope.app.apidoc import zcmlmodule
zcmlmodule.namespaces = None
More information about the Checkins
mailing list