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

zopefoundation / zc.form / 16248976557

21 Oct 2024 07:16AM UTC coverage: 82.759%. Remained the same
16248976557

push

github

icemac
Back to development: 2.2

126 of 180 branches covered (70.0%)

Branch coverage included in aggregate %.

786 of 922 relevant lines covered (85.25%)

0.85 hits per line

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

96.88
/src/zc/form/browser/tests/test_functional.py
1
##############################################################################
2
#
3
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
4
# All Rights Reserved.
5
#
6
# This software is subject to the provisions of the Zope Public License,
7
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
# FOR A PARTICULAR PURPOSE.
12
#
13
##############################################################################
14
"""functional test harness for zc.mruwidget"""
15
import doctest
1✔
16
import unittest
1✔
17

18
import zope.app.wsgi.testlayer
1✔
19
import zope.browser.interfaces
1✔
20
import zope.formlib.interfaces
1✔
21
import zope.schema.interfaces
1✔
22
from zope import component
1✔
23
from zope import interface
1✔
24

25
import zc.form.browser
1✔
26

27

28
colors = ['red', 'green', 'cerulean blue']
1✔
29

30

31
@interface.implementer(zope.schema.interfaces.ISource)
1✔
32
class AvailableColors:
1✔
33

34
    def __contains__(self, value):
1✔
35
        return value in colors
1✔
36

37

38
@interface.implementer(zope.schema.interfaces.ITitledTokenizedTerm)
1✔
39
class Term:
1✔
40

41
    def __init__(self, title, token):
1✔
42
        self.title = title
1✔
43
        self.token = token
1✔
44

45

46
@component.adapter(zope.schema.interfaces.ISource,
1✔
47
                   zope.publisher.interfaces.browser.IBrowserRequest)
48
@interface.implementer(zope.browser.interfaces.ITerms)
1✔
49
class ColorTerms:
1✔
50
    """Term and value support needed by query widgets."""
51

52
    def __init__(self, source, request):
1✔
53
        self.request = request
1✔
54
        self.source = source
1✔
55

56
    def getTerm(self, value):
1✔
57
        if value not in self.source:
1✔
58
            raise LookupError
1✔
59
        token = value + '_token'
1✔
60
        title = value.capitalize()
1✔
61
        return Term(title, token)
1✔
62

63
    def getValue(self, token):
1✔
64
        return token.split('_')[0]
1✔
65

66

67
@component.adapter(zope.schema.interfaces.ISource,
1✔
68
                   zope.publisher.interfaces.browser.IBrowserRequest)
69
@interface.implementer(zope.formlib.interfaces.ISourceQueryView)
1✔
70
class SimpleColorSourceQueryView:
1✔
71

72
    def __init__(self, source, request):
1✔
73
        self.context = source
1✔
74
        self.request = request
1✔
75

76
    def render(self, name):
1✔
77
        return '<query view for colors>'
1✔
78

79
    def results(self, name):
1✔
80
        if not (name + '.search' in self.request):
1✔
81
            return None
1✔
82
        searchstring = self.request[name + '.searchstring']
1✔
83
        return [c for c in colors if searchstring in c]
1✔
84

85

86
ZCFormLayer = zope.app.wsgi.testlayer.BrowserLayer(zc.form.browser)
1✔
87

88

89
def setUp(test):
1✔
90
    component.provideAdapter(ColorTerms)
1✔
91
    component.provideAdapter(SimpleColorSourceQueryView)
1✔
92

93

94
def test_suite():
1✔
95
    # This function must return something test case/suite like to keep
96
    # zope.testrunner happy.
97
    tests = unittest.TestSuite()
1✔
98
    try:
1✔
99
        import zc.resourcelibrary  # noqa
1✔
100
    except ModuleNotFoundError:
×
101
        # We want to skip the mruwidget tests
102
        pass
×
103
    else:
104
        suite = doctest.DocFileSuite(
1✔
105
            "../mruwidget.rst",
106
            globs={'AvailableColors': AvailableColors(),
107
                   'getRootFolder': ZCFormLayer.getRootFolder},
108
            optionflags=(doctest.NORMALIZE_WHITESPACE
109
                         | doctest.ELLIPSIS
110
                         | doctest.REPORT_ONLY_FIRST_FAILURE
111
                         | doctest.IGNORE_EXCEPTION_DETAIL
112
                         | doctest.REPORT_NDIFF),
113
            setUp=setUp,
114
        )
115
        suite.layer = ZCFormLayer
1✔
116
        tests = suite
1✔
117
    return tests
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