• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / grokcore.viewlet / 5776423262

pending completion
5776423262

push

github

web-flow
Config with pure python template (#7)

* Drop support for Python 2.7, 3.5, 3.6.

46 of 54 branches covered (85.19%)

Branch coverage included in aggregate %.

81 of 81 new or added lines in 21 files covered. (100.0%)

580 of 604 relevant lines covered (96.03%)

0.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.33
/src/grokcore/viewlet/tests/functional/viewlet/viewlet_context.py
1
"""
2
Viewlets and viewlet managers auto-associate with the context object that
3
may be in a module.
4

5
Set up the model object to view::
6

7
  >>> root = getRootFolder()
8
  >>> root['cave'] = cave = Cave()
9

10
We also set up another model that the viewlet manager and viewlets should
11
not be associated with::
12

13
  >>> from .viewlet_context2 import Club
14
  >>> root['club'] = club = Club()
15

16
Let's get a viewletmanager associated with ``cave``::
17

18
  >>> from zope.publisher.browser import TestRequest
19
  >>> request = TestRequest()
20
  >>> from zope import component
21
  >>> view = component.getMultiAdapter((cave, request), name='index')
22
  >>> from zope.contentprovider.interfaces import IContentProvider
23
  >>> mgr = component.getMultiAdapter((cave, request, view), IContentProvider,
24
  ...   'manage.cavemen')
25

26
We cannot get this viewletmanager for ``club``, as there is no viewlet
27
manager associated with that as a context::
28

29
  >>> component.queryMultiAdapter((club, request, view), IContentProvider,
30
  ...   'manage.caveman') is None
31
  True
32

33
We can get the viewlet for ``cave``::
34

35
  >>> mgr['fredviewlet']
36
  <grokcore.viewlet.tests.functional.viewlet.viewlet_context.FredViewlet object at ...>
37

38
We can also directly look it up using a manual lookup::
39

40
  >>> from zope.viewlet.interfaces import IViewlet
41
  >>> viewlet = component.getMultiAdapter((cave, request, view, mgr),
42
  ...   IViewlet, name='fredviewlet')
43

44
We cannot get the viewlet for the ``club`` however, as it is not associated
45
with the same context::
46

47
  >>> viewlet = component.getMultiAdapter((club, request, view, mgr),
48
  ...   IViewlet, name='fredviewlet')
49
  Traceback (most recent call last):
50
    ...
51
  zope.interface.interfaces.ComponentLookupError: ...
52

53
"""  # noqa: E501 line too long
54

55
import grokcore.viewlet as grok
1✔
56

57

58
class CavemenViewletManager(grok.ViewletManager):
1✔
59
    grok.name('manage.cavemen')
1✔
60

61

62
class FredViewlet(grok.Viewlet):
1✔
63
    grok.viewletmanager(CavemenViewletManager)
1✔
64

65
    def render(self):
1✔
66
        return "Me Fred"
×
67

68

69
class Cave(grok.Context):
1✔
70
    pass
1✔
71

72

73
class Index(grok.View):
1✔
74
    def render(self):
1✔
75
        return "hoi"
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc