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

zopefoundation / grokcore.formlib / 16861221675

18 Jun 2025 06:33AM UTC coverage: 96.005%. Remained the same
16861221675

push

github

icemac
Back to development: 5.1

92 of 106 branches covered (86.79%)

Branch coverage included in aggregate %.

701 of 720 relevant lines covered (97.36%)

0.97 hits per line

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

100.0
/src/grokcore/formlib/tests/base/form/form.py
1
"""
2
A grok.EditForm is a special view that renders an edit form.
3

4
  >>> from zope import component
5
  >>> from zope.publisher.browser import TestRequest
6
  >>> grok.testing.grok(__name__)
7
  >>> manfred = Mammoth()
8

9
  >>> request = TestRequest()
10
  >>> view = component.getMultiAdapter((manfred, request), name='edit')
11
  >>> len(view.form_fields)
12
  2
13
  >>> [w.__name__ for w in view.form_fields]
14
  ['name', 'size']
15

16
Let's assert that forms are indeed Zope 3-style browser views and
17
browser pages:
18

19
  >>> from zope.publisher.interfaces.browser import IBrowserPage, IBrowserView
20
  >>> IBrowserPage.providedBy(view)
21
  True
22
  >>> IBrowserView.providedBy(view)
23
  True
24

25
It is important to keep the order of the fields:
26

27
  >>> view = component.getMultiAdapter(
28
  ...    (DifferentMammoth(), request), name='editdifferent')
29
  >>> len(view.form_fields)
30
  2
31
  >>> [w.__name__ for w in view.form_fields]
32
  ['size', 'name']
33

34
"""
35
from zope import schema
1✔
36
from zope.interface import Interface
1✔
37
from zope.interface import implementer
1✔
38

39
import grokcore.formlib as grok
1✔
40

41

42
class IMammoth(Interface):
1✔
43
    name = schema.TextLine(title="Name")
1✔
44
    size = schema.TextLine(title="Size", default="Quite normal")
1✔
45

46

47
@implementer(IMammoth)
1✔
48
class Mammoth(grok.Context):
1✔
49
    pass
1✔
50

51

52
class Edit(grok.EditForm):
1✔
53
    grok.context(Mammoth)
1✔
54

55

56
class IDifferentMammoth(Interface):
1✔
57
    # mind the different order of fields
58
    size = schema.TextLine(title="Size", default="Quite normal")
1✔
59
    name = schema.TextLine(title="Name")
1✔
60

61

62
@implementer(IDifferentMammoth)
1✔
63
class DifferentMammoth(grok.Context):
1✔
64
    pass
1✔
65

66

67
class EditDifferent(grok.EditForm):
1✔
68
    grok.context(DifferentMammoth)
1✔
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