[Zope3-checkins] CVS: Products3/NewsSite/tests - test_register.py:1.4
Tres Seaver
tseaver@zope.com
Thu, 27 Mar 2003 10:12:10 -0500
Update of /cvs-repository/Products3/NewsSite/tests
In directory cvs.zope.org:/tmp/cvs-serv26328/tests
Modified Files:
test_register.py
Log Message:
- Add tests for member data adapter, and fix a bug.
=== Products3/NewsSite/tests/test_register.py 1.3 => 1.4 ===
--- Products3/NewsSite/tests/test_register.py:1.3 Thu Mar 27 09:23:21 2003
+++ Products3/NewsSite/tests/test_register.py Thu Mar 27 10:12:09 2003
@@ -29,6 +29,7 @@
from zope.app.interfaces.security import IPrincipal
from zope.app.interfaces.security import IAuthenticationService
+from zope.app.interfaces.annotation import IAttributeAnnotatable
from zope.app.services.servicenames import Authentication
from zope.app.services.tests.placefulsetup import PlacefulSetup
from zope.app.form.widget import CustomWidget
@@ -48,13 +49,23 @@
from zope.testing.cleanup import CleanUp # Base class w registry cleanup
+TEST_EMAIL = 'dummy@example.com'
+TEST_REALNAME = 'I. M. Dumbkopf'
+
class DummyUser:
- __implements__ = IPrincipal
- def __init__(self, id):
+
+ __implements__ = (IPrincipal, IAttributeAnnotatable)
+
+ def __init__(self, id='dummy', **kw):
+ self.__dict__.update(kw)
self._id = id
+
def getId(self):
return self._id
+ def getLogin(self):
+ return self._id
+
class DummyUserFolderAdding:
def __init__(self):
@@ -191,9 +202,46 @@
self.failUnless(self._authsvc.getObject('testing') is user)
+class TestMemberDataAdapter(PlacefulSetup, unittest.TestCase, CleanUp):
+
+ def setUp(self):
+
+ PlacefulSetup.setUp(self)
+
+ def tearDown(self):
+ PlacefulSetup.tearDown(self)
+ CleanUp.tearDown(self)
+
+ def _getTargetClass(self):
+
+ from zopeproducts.NewsSite.register import MemberDataAdapter
+ return MemberDataAdapter
+
+ def _makeOne(self, context, *args, **kw):
+
+ return self._getTargetClass()(context, *args, **kw)
+
+ def test_read(self):
+
+ user = DummyUser('readable')
+ adapter = self._makeOne( user )
+ self.assertEqual(adapter.login, 'readable')
+
+ def test_write(self):
+
+ user = DummyUser('writable')
+ adapter = self._makeOne( user )
+
+ adapter.email = TEST_EMAIL
+ self.assertEqual(adapter.email, TEST_EMAIL)
+
+ adapter.realname = TEST_REALNAME
+ self.assertEqual(adapter.realname, TEST_REALNAME)
+
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestMemberAddView))
+ suite.addTest(unittest.makeSuite(TestMemberDataAdapter))
return suite