[Zope3-checkins] CVS: Products3/NewsSite/tests - __init__.py:1.1 test_register.py:1.1
Tres Seaver
tseaver@zope.com
Tue, 25 Mar 2003 11:28:02 -0500
Update of /cvs-repository/Products3/NewsSite/tests
In directory cvs.zope.org:/tmp/cvs-serv7546/tests
Added Files:
__init__.py test_register.py
Log Message:
- Add interfaces and view code for a new add view, MemberAddView, which
collects "member" data along with "user" data; it will store the
"member" data as an annotaion on the user, via an adapter to
IMember.
=== Added File Products3/NewsSite/tests/__init__.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""NewsSite product unit tests.
$Id: __init__.py,v 1.1 2003/03/25 16:28:01 tseaver Exp $
"""
=== Added File Products3/NewsSite/tests/test_register.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""Test registration views.
$Id: test_register.py,v 1.1 2003/03/25 16:28:01 tseaver Exp $
"""
import unittest
from zope.publisher.browser import TestRequest
from zope.app.interfaces.security import IPrincipal
from zope.component import getAdapter
from zope.component.interfaces import IFactory
from zope.component.factory import provideFactory
from zope.component.adapter import provideAdapter
from zope.app.form.widget import CustomWidget
from zope.app.browser.form.widget import TextWidget
from zope.app.browser.form.add import AddView
from zope.app.tests.placelesssetup import PlacelessSetup
from zopeproducts.NewsSite.interfaces import IMember
#############################################################################
# If your tests change any global registries, then uncomment the
# following import and include CleanUp as a base class of your
# test. It provides a setUp and tearDown that clear global data that
# has registered with the test cleanup framework. If your class has
# its own setUp or tearDown, make sure you call the CleanUp setUp and
# tearDown from them, or the benefits of using CleanUp will be lost.
# Don't use CleanUp based tests outside the Zope package.
from zope.testing.cleanup import CleanUp # Base class w registry cleanup
class DummyUser:
__implements__ = ( IPrincipal, )
def __init__(self, id, title, description, login, pw):
self._id = id
self._title = title
self._description = description
self._login = login
self._pw = pw
self.roles = []
def getId(self):
return self._id
def setRoles(self, roles):
self.roles = roles
class DUFactory: # XXX
"""Sacrifice dead chickens to appease factory framework.
"""
__implements__ = ( IFactory, )
def __call__( self, *args, **kw ):
return DummyUser( *args, **kw )
def getInterfaces( self ):
raise "D'oh!"
class DummyUserFolderAdding:
def __init__(self):
self._things = {}
def add(self,content):
self._things[content._id] = content
class DummyMemberAdapter( object ):
__implements__ = ( IMember, )
def __init__( self, context ):
self.context = context
def _setLogin(self, login):
self.context._login = login
login = property( lambda self: self.context._login,
_setLogin )
def _setPassword(self, password):
self.context._pw = password
password = property( lambda self: self.context._pw,
_setPassword )
def _setEmail(self, email): # XXX
self.context._email = email
email = property( lambda self: self.context._email,
_setEmail )
def _setRealName(self, realname): # XXX
self.context._realname = realname
realname = property( lambda self: self.context._realname,
_setRealName )
#############################################################################
class TestMemberAddView(PlacelessSetup, unittest.TestCase, CleanUp):
def setUp(self):
PlacelessSetup.setUp(self)
provideFactory('User', DUFactory() )
provideAdapter( IPrincipal, IMember, DummyMemberAdapter )
def _getTargetClass(self):
from zopeproducts.NewsSite.register import MemberAddView
class UnderTest(MemberAddView, AddView):
schema = IMember
login = CustomWidget(TextWidget)
realname = CustomWidget(TextWidget)
email = CustomWidget(TextWidget)
password = CustomWidget(TextWidget)
_arguments = _set_after_add = ()
_set_before_add = ( 'email', 'realname' )
_keyword_arguments = ( 'id', 'title', 'description', 'login',
'password' )
return UnderTest
def _makeOne(self, context=None, request=None, *args, **kw):
if request is None:
request = TestRequest()
return self._getTargetClass()(context, request, *args, **kw)
def test_create(self):
view = self._makeOne()
user = view.create(login='login',
password='xyzzy'
)
self.failUnless(IPrincipal.isImplementedBy(user))
self.assertEqual(user._id, 'login')
self.assertEqual(user._title, '')
self.assertEqual(user._description, '')
self.assertEqual(user._login, 'login')
self.assertEqual(user._pw, 'xyzzy')
def test_createAndAdd(self):
ufa = DummyUserFolderAdding()
view = self._makeOne(ufa)
view.createAndAdd({'login' : 'login',
'realname' : 'Real Name',
'email' : 'login@example.com',
'password' : 'xyzzy' })
user = ufa._things['login']
self.failUnless(IPrincipal.isImplementedBy(user))
self.assertEqual(user._id, 'login')
self.assertEqual(user._title, '')
self.assertEqual(user._description, '')
self.assertEqual(user._login, 'login')
self.assertEqual(user._pw, 'xyzzy')
member = getAdapter( user, IMember )
self.assertEqual(member.login, 'login')
self.assertEqual(member.realname, 'Real Name')
self.assertEqual(member.email, 'login@example.com')
self.assertEqual(member.password, 'xyzzy')
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestMemberAddView))
return suite
if __name__ == '__main__':
unittest.main()