/usr/share/pyshared/zope/security/tests/test_simpleinteraction.py is in python-zope.security 3.8.3-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | ##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Unit tests for zope.security.simpleinteraction.
"""
import unittest
from zope.interface.verify import verifyObject
from zope.security.interfaces import IInteraction
from zope.security.simplepolicies import ParanoidSecurityPolicy
class RequestStub(object):
def __init__(self, principal=None):
self.principal = principal
self.interaction = None
class TestInteraction(unittest.TestCase):
def test(self):
interaction = ParanoidSecurityPolicy()
verifyObject(IInteraction, interaction)
def test_add(self):
rq = RequestStub()
interaction = ParanoidSecurityPolicy()
interaction.add(rq)
self.assert_(rq in interaction.participations)
self.assert_(rq.interaction is interaction)
# rq already added
self.assertRaises(ValueError, interaction.add, rq)
interaction2 = ParanoidSecurityPolicy()
self.assertRaises(ValueError, interaction2.add, rq)
def test_remove(self):
rq = RequestStub()
interaction = ParanoidSecurityPolicy()
self.assertRaises(ValueError, interaction.remove, rq)
interaction.add(rq)
interaction.remove(rq)
self.assert_(rq not in interaction.participations)
self.assert_(rq.interaction is None)
def testCreateInteraction(self):
i1 = ParanoidSecurityPolicy()
verifyObject(IInteraction, i1)
self.assertEquals(list(i1.participations), [])
user = object()
request = RequestStub(user)
i2 = ParanoidSecurityPolicy(request)
verifyObject(IInteraction, i2)
self.assertEquals(list(i2.participations), [request])
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestInteraction))
return suite
if __name__ == '__main__':
unittest.main()
|