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

zopefoundation / Products.StandardCacheManagers / 16399753970

17 Mar 2025 07:54AM UTC coverage: 50.611% (-2.0%) from 52.597%
16399753970

push

github

web-flow
Update Python version support. (#13)

* Drop support for Python 3.8.
* Add support for Python 3.13.

13 of 124 branches covered (10.48%)

Branch coverage included in aggregate %.

360 of 613 relevant lines covered (58.73%)

0.59 hits per line

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

100.0
/src/Products/StandardCacheManagers/tests/test_CacheManagerLocation.py
1
##############################################################################
2
#
3
# Copyright (c) 2010 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
""" Unit tests for AcceleratedCacheManager module.
15
"""
16

17
import transaction
1✔
18
import zope.component
1✔
19
from AccessControl import SecurityManager
1✔
20
from AccessControl.SecurityManagement import newSecurityManager
1✔
21
from AccessControl.SecurityManagement import noSecurityManager
1✔
22
from OFS.tests.testCopySupport import CopySupportTestBase
1✔
23
from OFS.tests.testCopySupport import UnitTestSecurityPolicy
1✔
24
from OFS.tests.testCopySupport import UnitTestUser
1✔
25
from Zope2.App import zcml
1✔
26
from zope.component import eventtesting
1✔
27
from zope.component import testing as componenttesting
1✔
28

29
import Products.StandardCacheManagers
1✔
30
from Products.StandardCacheManagers.AcceleratedHTTPCacheManager import \
1✔
31
    AcceleratedHTTPCacheManager
32
from Products.StandardCacheManagers.RAMCacheManager import RAMCacheManager
1✔
33

34

35
CACHE_META_TYPES = tuple(dict(name=instance_class.meta_type,
1✔
36
                              action='unused_constructor_name',
37
                              permission="Add %ss" % instance_class.meta_type)
38
                         for instance_class in (RAMCacheManager,
39
                                                AcceleratedHTTPCacheManager))
40

41

42
class CacheManagerLocationTests:
1✔
43

44
    _targetClass = None
1✔
45

46
    def _makeOne(self, *args, **kw):
1✔
47
        return self._targetClass(*args, **kw)
1✔
48

49
    def setUp(self):
1✔
50
        componenttesting.setUp()
1✔
51
        eventtesting.setUp()
1✔
52
        zcml.load_config('meta.zcml', zope.component)
1✔
53
        zcml.load_config('configure.zcml', Products.StandardCacheManagers)
1✔
54

55
        folder1, folder2 = self._initFolders()
1✔
56

57
        folder1.all_meta_types = folder2.all_meta_types = CACHE_META_TYPES
1✔
58

59
        self.folder1 = folder1
1✔
60
        self.folder2 = folder2
1✔
61

62
        self.policy = UnitTestSecurityPolicy()
1✔
63
        self.oldPolicy = SecurityManager.setSecurityPolicy(self.policy)
1✔
64

65
        cm_id = 'cache'
1✔
66
        manager = self._makeOne(cm_id)
1✔
67
        self.folder1._setObject(cm_id, manager)
1✔
68
        self.cachemanager = self.folder1[cm_id]
1✔
69
        transaction.savepoint(optimistic=True)
1✔
70

71
        newSecurityManager(None, UnitTestUser().__of__(self.root))
1✔
72

73
        CopySupportTestBase.setUp(self)
1✔
74

75
    def tearDown(self):
1✔
76
        noSecurityManager()
1✔
77
        SecurityManager.setSecurityPolicy(self.oldPolicy)
1✔
78
        del self.oldPolicy
1✔
79
        del self.policy
1✔
80
        del self.folder2
1✔
81
        del self.folder1
1✔
82

83
        self._cleanApp()
1✔
84
        componenttesting.tearDown()
1✔
85
        CopySupportTestBase.tearDown(self)
1✔
86

87
    def test_cache_differs_on_copy(self):
1✔
88
        # ensure copies don't hit the same cache
89
        cache = self.cachemanager.ZCacheManager_getCache()
1✔
90
        cachemanager_copy = self.folder2.manage_clone(self.cachemanager,
1✔
91
                                                      'cache_copy')
92
        cache_copy = cachemanager_copy.ZCacheManager_getCache()
1✔
93
        self.assertNotEqual(cache, cache_copy)
1✔
94

95
    def test_cache_remains_on_move(self):
1✔
96
        # test behaviour of cache on move.
97
        # NOTE: This test verifies current behaviour, but there is no actual
98
        # need for cache managers to maintain the same cache on move.
99
        # if physical path starts being used as a cache key, this test might
100
        # need to be fixed.
101
        cache = self.cachemanager.ZCacheManager_getCache()
1✔
102
        cut = self.folder1.manage_cutObjects(['cache'])
1✔
103
        self.folder2.manage_pasteObjects(cut)
1✔
104
        cachemanager_moved = self.folder2['cache']
1✔
105
        cache_moved = cachemanager_moved.ZCacheManager_getCache()
1✔
106
        self.assertEqual(cache, cache_moved)
1✔
107

108
    def test_cache_deleted_on_remove(self):
1✔
109
        old_cache = self.cachemanager.ZCacheManager_getCache()
1✔
110
        self.folder1.manage_delObjects(['cache'])
1✔
111
        new_cache = self.cachemanager.ZCacheManager_getCache()
1✔
112
        self.assertNotEqual(old_cache, new_cache)
1✔
113

114

115
class AcceleratedHTTPCacheManagerLocationTests(
1✔
116
        CacheManagerLocationTests, CopySupportTestBase):
117

118
    _targetClass = AcceleratedHTTPCacheManager
1✔
119

120

121
class RamCacheManagerLocationTests(
1✔
122
        CacheManagerLocationTests, CopySupportTestBase):
123

124
    _targetClass = RAMCacheManager
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