diff options
author | Tres Seaver <tseaver@palladion.com> | 2013-02-12 16:08:47 -0500 |
---|---|---|
committer | Tres Seaver <tseaver@palladion.com> | 2013-02-12 16:08:47 -0500 |
commit | 1eb2ad2c3fcfa40512a47e9183df5ea5b5db07a7 (patch) | |
tree | 860cac24920bb3763df53dda77a28164273a7672 /src/zope | |
parent | 862f4c1fd227537b6ad679c7f1273415e4595ff1 (diff) | |
download | zope-security-1eb2ad2c3fcfa40512a47e9183df5ea5b5db07a7.tar.gz |
100% coverage for z.s.proxy.
Diffstat (limited to 'src/zope')
-rw-r--r-- | src/zope/security/tests/test_proxy.py | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/src/zope/security/tests/test_proxy.py b/src/zope/security/tests/test_proxy.py index 91d68fb..21e7063 100644 --- a/src/zope/security/tests/test_proxy.py +++ b/src/zope/security/tests/test_proxy.py @@ -16,6 +16,57 @@ import unittest +class Test_getTestProxyItems(unittest.TestCase): + + def _callFUT(self, proxy): + from zope.security.proxy import getTestProxyItems + return getTestProxyItems(proxy) + + def test_w_empty_checker(self): + from zope.security.checker import Checker + from zope.security.proxy import Proxy + target = object() + proxy = Proxy(target, Checker({})) + self.assertEqual(self._callFUT(proxy), []) + + def test_w_non_empty_checker(self): + from zope.security.checker import Checker + from zope.security.checker import CheckerPublic + from zope.security.proxy import Proxy + target = object() + permission = object() + proxy = Proxy(target, + Checker({'foo': CheckerPublic, 'bar': permission})) + self.assertEqual(self._callFUT(proxy), + [('bar', permission), ('foo', CheckerPublic)]) + + +class Test_isinstance(unittest.TestCase): + + def _callFUT(self, object, cls): + from zope.security.proxy import isinstance + return isinstance(object, cls) + + def test_w_unproxied_object(self): + class Foo(object): + pass + target = Foo() + self.assertTrue(self._callFUT(target, Foo)) + self.assertFalse(self._callFUT(target, int)) + + def test_w_proxied_object(self): + from zope.security.checker import Checker + from zope.security.proxy import Proxy + class Foo(object): + pass + target = Foo() + proxy = Proxy(target, Checker({})) + self.assertTrue(self._callFUT(proxy, Foo)) + self.assertFalse(self._callFUT(proxy, int)) + + +# pre-geddon + class Checker(object): ok = 1 @@ -448,7 +499,7 @@ def test_using_mapping_slots_hack(): """ -class TestLocationProxySecurityChecker(unittest.TestCase): +class LocationProxySecurityCheckerTests(unittest.TestCase): def test_LocationProxy_gets_a_security_checker_when_importing_z_s_proxy( self): @@ -473,6 +524,9 @@ class TestLocationProxySecurityChecker(unittest.TestCase): def test_suite(): return unittest.TestSuite(( + unittest.makeSuite(Test_getTestProxyItems), + unittest.makeSuite(Test_isinstance), + # pre-geddon unittest.makeSuite(ProxyTests), - unittest.makeSuite(TestLocationProxySecurityChecker), + unittest.makeSuite(LocationProxySecurityCheckerTests), )) |