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

zopefoundation / Zope / 3956162881

pending completion
3956162881

push

github

Michael Howitz
Update to deprecation warning free releases.

4401 of 7036 branches covered (62.55%)

Branch coverage included in aggregate %.

27161 of 31488 relevant lines covered (86.26%)

0.86 hits per line

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

96.04
/src/OFS/tests/testApplication.py
1
import unittest
1✔
2

3
from Testing.ZopeTestCase import FunctionalTestCase
1✔
4

5

6
class ApplicationTests(unittest.TestCase):
1✔
7

8
    def _getTargetClass(self):
1✔
9
        from OFS.Application import Application
1✔
10
        return Application
1✔
11

12
    def _makeOne(self):
1✔
13
        return self._getTargetClass()()
1✔
14

15
    def test_class_provides_IApplication(self):
1✔
16
        from OFS.interfaces import IApplication
1✔
17
        from zope.interface.verify import verifyClass
1✔
18

19
        verifyClass(IApplication, self._getTargetClass())
1✔
20

21
    def test_instance_conforms_to_IApplication(self):
1✔
22
        from OFS.interfaces import IApplication
1✔
23
        from zope.interface.verify import verifyObject
1✔
24

25
        verifyObject(IApplication, self._makeOne())
1✔
26

27
    def test_instance_attributes(self):
1✔
28
        app = self._makeOne()
1✔
29
        self.assertTrue(app.isTopLevelPrincipiaApplicationObject)
1✔
30
        self.assertEqual(app.title, 'Zope')
1✔
31

32
    def test_id_no_request(self):
1✔
33
        app = self._makeOne()
1✔
34
        self.assertEqual(app.getId(), 'Zope')
1✔
35

36
    def test_id_w_request_no_SCRIPT_NAME(self):
1✔
37
        app = self._makeOne()
1✔
38
        app.REQUEST = {}
1✔
39
        self.assertEqual(app.getId(), 'Zope')
1✔
40

41
    def test_id_w_request_w_SCRIPT_NAME(self):
1✔
42
        app = self._makeOne()
1✔
43
        app.REQUEST = {'SCRIPT_NAME': '/Dummy'}
1✔
44
        self.assertEqual(app.getId(), 'Dummy')
1✔
45

46
    def test_title_and_id_plus_title_or_id(self):
1✔
47
        app = self._makeOne()
1✔
48
        app.title = 'Other'
1✔
49
        self.assertEqual(app.title_and_id(), 'Other')
1✔
50
        self.assertEqual(app.title_or_id(), 'Other')
1✔
51

52
    def test_bobo_traverse_attribute_hit(self):
1✔
53
        app = self._makeOne()
1✔
54
        app.NAME = 'attribute'
1✔
55
        app._getOb = lambda x, y: x
1!
56
        request = {}
1✔
57
        self.assertEqual(app.__bobo_traverse__(request, 'NAME'), 'attribute')
1✔
58

59
    def test_bobo_traverse_attribute_miss_key_hit(self):
1✔
60
        app = self._makeOne()
1✔
61
        app._getOb = lambda x, y: x
1✔
62
        app._objects = [{'id': 'OTHER', 'meta_type': None}]
1✔
63
        request = {}
1✔
64
        self.assertEqual(app.__bobo_traverse__(request, 'OTHER'), 'OTHER')
1✔
65

66
    def test_bobo_traverse_attribute_key_miss_R_M_default_real_request(self):
1✔
67
        from collections import UserDict
1✔
68
        request = UserDict()
1✔
69

70
        class _Response:
1✔
71
            def notFoundError(self, msg):
1✔
72
                1 / 0
1✔
73

74
        request.RESPONSE = _Response()
1✔
75
        app = self._makeOne()
1✔
76
        app._getOb = _noWay
1✔
77

78
        self.assertRaises(ZeroDivisionError,
1✔
79
                          app.__bobo_traverse__, request, 'NONESUCH')
80

81
    def test_bobo_traverse_attribute_key_miss_R_M_default_fake_request(self):
1✔
82
        app = self._makeOne()
1✔
83

84
        app._getOb = _noWay
1✔
85
        request = {}
1✔
86
        self.assertRaises(KeyError, app.__bobo_traverse__, request, 'NONESUCH')
1✔
87

88
    def test_bobo_traverse_attribute_key_miss_R_M_is_GET(self):
1✔
89
        app = self._makeOne()
1✔
90

91
        app._getOb = _noWay
1✔
92
        request = {'REQUEST_METHOD': 'GET'}
1✔
93
        self.assertRaises(KeyError, app.__bobo_traverse__, request, 'NONESUCH')
1✔
94

95
    def test_redirect_regression(self):
1✔
96
        """From code you should still be able to call the Redirect method.
97

98
        And its aliases too.
99
        This is part of PloneHotfix20171128:
100
        Redirect should not be callable as url, but from code it is fine.
101
        """
102
        from zExceptions import Redirect as RedirectException
1✔
103
        app = self._makeOne()
1✔
104
        for name in ('Redirect', 'ZopeRedirect'):
1✔
105
            method = getattr(app, name, None)
1✔
106
            if method is None:
1!
107
                continue
×
108
            self.assertRaises(
1✔
109
                RedirectException,
110
                method, 'http://google.nl', 'http://other.url')
111

112
    def test_ZopeVersion(self):
1✔
113
        import pkg_resources
1✔
114

115
        from App.version_txt import getZopeVersion
1✔
116

117
        app = self._makeOne()
1✔
118
        pkg_version = pkg_resources.get_distribution('Zope').version
1✔
119
        zversion = getZopeVersion()
1✔
120

121
        self.assertEqual(app.ZopeVersion(major=True), zversion.major)
1✔
122
        self.assertEqual(app.ZopeVersion(major=True),
1✔
123
                         int(pkg_version.split('.')[0]))
124

125

126
class ApplicationPublishTests(FunctionalTestCase):
1✔
127

128
    def test_redirect_not_found(self):
1✔
129
        """Accessing Redirect as url should give a 404.
130

131
        This is part of PloneHotfix20171128.
132
        """
133
        # These are all aliases.
134
        for name in ('Redirect', 'ZopeRedirect'):
1✔
135
            response = self.publish(
1✔
136
                f'/{name}?destination=http://google.nl')
137
            # This should *not* return a 302 Redirect.
138
            self.assertEqual(response.status, 404)
1✔
139

140

141
def _noWay(self, key, default=None):
1✔
142
    raise KeyError(key)
×
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