Skip to content

Commit

Permalink
100% coverage for presentation.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed May 18, 2017
1 parent 489d7ad commit 130e1d3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/zope/app/apidoc/codemodule/README.rst
Expand Up @@ -89,7 +89,7 @@ still get to them:

>>> names = sorted(module['tests'].keys())
>>> names
['BrowserTestCase', 'LayerDocFileSuite', 'LayerDocTestSuite', 'Root', 'setUp', 'standard_checker', 'tearDown', 'test_suite']
['BrowserTestCase', 'LayerDocFileSuite', 'LayerDocTestSuite', 'Root', ...]


Classes
Expand Down
57 changes: 23 additions & 34 deletions src/zope/app/apidoc/presentation.py
Expand Up @@ -53,8 +53,7 @@ def getViewFactoryData(factory):
while hasattr(factory, 'factory'):
factory = factory.factory

if hasattr(factory, '__name__') and \
factory.__name__.startswith('SimpleViewClass'):
if getattr(factory, '__name__', '').startswith('SimpleViewClass'):
# In the case of a SimpleView, the base is really what we are
# interested in. Usually the first listed class is the interesting one.
base = factory.__bases__[0]
Expand All @@ -66,37 +65,27 @@ def getViewFactoryData(factory):
elif isinstance(factory, (six.string_types, float, int, list, tuple)):
info['referencable'] = False

elif factory.__module__ is not None and \
factory.__module__.startswith(BROWSER_DIRECTIVES_MODULE):
info['path'] = getPythonPath(factory.__bases__[0])

# XML-RPC view factory, generated during registration
elif factory.__module__ is not None and \
factory.__module__.startswith(XMLRPC_DIRECTIVES_MODULE):

# Those factories are method publisher and security wrapped
info['path'] = getPythonPath(factory.__bases__[0].__bases__[0])

# JSON-RPC view factory, generated during registration
# This is needed for the 3rd party jsonserver implementation
# TODO: See issue http://www.zope.org/Collectors/Zope3-dev/504, ri
elif factory.__module__ is not None and \
factory.__module__.startswith(JSONRPC_DIRECTIVES_MODULE):

# Those factories are method publisher and security wrapped
info['path'] = getPythonPath(factory.__bases__[0].__bases__[0])

# A factory that is a class instance; since we cannot reference instances,
# reference the class.
elif not hasattr(factory, '__name__'):
elif factory.__module__ is not None:
if factory.__module__.startswith(BROWSER_DIRECTIVES_MODULE):
info['path'] = getPythonPath(factory.__bases__[0])
# XML-RPC view factory, generated during registration
elif (factory.__module__.startswith(XMLRPC_DIRECTIVES_MODULE)
# JSON-RPC view factory, generated during registration
# This is needed for the 3rd party jsonserver implementation
# TODO: See issue http://www.zope.org/Collectors/Zope3-dev/504, ri
or factory.__module__.startswith(JSONRPC_DIRECTIVES_MODULE)):
# Those factories are method publisher and security wrapped
info['path'] = getPythonPath(factory.__bases__[0].__bases__[0])

if not info['path'] and not hasattr(factory, '__name__'):
# A factory that is a class instance; since we cannot reference instances,
# reference the class.
info['path'] = getPythonPath(factory.__class__)

# A simple class-based factory
elif isinstance(factory, six.class_types):
info['path'] = getPythonPath(factory)

# We have tried our best; just get the Python path as good as you can.
else:
if not info['path']:
# Either a simple class-based factory, or not. It doesn't
# matter. We have tried our best; just get the Python path as
# good as you can.
info['path'] = getPythonPath(factory)

if info['referencable']:
Expand All @@ -113,9 +102,9 @@ def getPresentationType(iface):
# Note that the order of the requests matters here, since we want to
# inspect the most specific one first. For example, IBrowserRequest is also
# an IHTTPRequest.
for type in [IBrowserRequest, IXMLRPCRequest, IHTTPRequest, IFTPRequest]:
if iface.isOrExtends(type):
return type
for kind in [IBrowserRequest, IXMLRPCRequest, IHTTPRequest, IFTPRequest]:
if iface.isOrExtends(kind):
return kind
return iface


Expand Down
2 changes: 1 addition & 1 deletion src/zope/app/apidoc/presentation.rst
Expand Up @@ -50,7 +50,7 @@ cases we cannot retrieve any useful information:

>>> info = presentation.getViewFactoryData(3)
>>> pprint(info)
{'path': None,
{'path': '__builtin__.int',
'referencable': False,
'resource': None,
'template': None,
Expand Down
11 changes: 11 additions & 0 deletions src/zope/app/apidoc/tests.py
Expand Up @@ -147,6 +147,16 @@ def tearDown(test):
zope.testing.module.tearDown(test, 'zope.app.apidoc.doctest')


class TestPresentation(unittest.TestCase):

def test_iconviewfactory(self):
from zope.browserresource.icon import IconViewFactory
from .presentation import getViewFactoryData
factory = IconViewFactory('rname', 'alt', 0, 0)

data = getViewFactoryData(factory)
self.assertEqual(data['resource'], factory.rname)

# Generally useful classes and functions

@implementer(IContainmentRoot)
Expand Down Expand Up @@ -217,6 +227,7 @@ def file_test(name, **kwargs):
file_test('presentation.rst',
globs={'__file__': __file__}),
file_test('utilities.rst'),
unittest.defaultTestLoader.loadTestsFromName(__name__),
))

if __name__ == '__main__':
Expand Down

0 comments on commit 130e1d3

Please sign in to comment.