[Zope-Checkins] CVS: Zope3/lib/python/Zope/Security/tests - testSecProxy.py:1.1.2.1

Guido van Rossum guido@python.org
Thu, 18 Apr 2002 01:01:26 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/Security/tests
In directory cvs.zope.org:/tmp/cvs-serv32627

Added Files:
      Tag: SecurityProxy-branch
	testSecProxy.py 
Log Message:
Rudimentary test suite for secproxy.


=== Added File Zope3/lib/python/Zope/Security/tests/testSecProxy.py ===
import unittest

from Zope.Security.secproxy.secproxy import secproxy

class Checker:
    def check_getattr(self, object, name):
        ##print "check_getattr", (object, name)
        if name != "foo":
            raise RuntimeError
        return "hello"
    def checkValue(self, value, allowed_by_default=1):
        ##print "checkValue", (value, allowed_by_default)
        return [value, allowed_by_default]

class Something:
    foo = "whatever"

class SecProxyTests(unittest.TestCase):

    def setUp(self):
        self.x = Something()
        self.c = Checker()
        self.p = secproxy(self.x, self.c)

    def testStr(self):
        self.assertEqual(str(self.p), str(self.x))

    def testRepr(self):
        self.assertEqual(repr(self.p), repr(self.x))

    def testGetAttrOK(self):
        self.assertEqual(self.p.foo, ["whatever", "hello"])

    def testGetAttrFail(self):
        try:
            self.p.bar
        except RuntimeError:
            pass
        else:
            self.fail("p.bar didn't raise RuntimeError")

def test_suite():
    return unittest.makeSuite(SecProxyTests)