Commit 0fdad843 authored by Florent Guillaume's avatar Florent Guillaume

Use a better __repr__ for User objects.

(NullUnrestrictedUser had a non-string repr that made it impossible to
debug properly.)
parent 5cff5316
......@@ -86,6 +86,8 @@ Zope Changes
Other
- AccessControl.User: Use a better __repr__.
- ZSQLMethod.manage_main: Moved the error message that warns of a
non-existing or closed database connection next to the Connection ID
dropdown and present it using red to increase its visibility.
......
......@@ -276,7 +276,8 @@ class BasicUser(Implicit):
def __len__(self): return 1
def __str__(self): return self.getUserName()
__repr__=__str__
def __repr__(self):
return '<%s %r>' % (self.__class__.__name__, self.getUserName())
class SimpleUser(BasicUser):
......
......@@ -275,6 +275,21 @@ class UserTests(unittest.TestCase):
f = User('chris', '123', ['Manager'], [])
self.assertEqual(f.getDomains(), ())
def testRepr(self):
f = User('flo', '123', ['Manager'], [])
self.assertEqual(repr(f), "<User 'flo'>")
def testReprSpecial(self):
from AccessControl.User import NullUnrestrictedUser
from AccessControl.User import nobody
from AccessControl.User import system
# NullUnrestrictedUser is used when there is no emergency user
self.assertEqual(repr(NullUnrestrictedUser()),
"<NullUnrestrictedUser (None, None)>")
self.assertEqual(repr(nobody),
"<SpecialUser 'Anonymous User'>")
self.assertEqual(repr(system),
"<UnrestrictedUser 'System Processes'>")
def test_suite():
suite = unittest.TestSuite()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment