[CMF-checkins] SVN: CMF/trunk/CMFDefault/ - added basic unit tests
for mailPassword() and registeredNotify()
Yvo Schubbe
y.2006_ at wcm-solutions.de
Thu Oct 12 14:21:27 EDT 2006
Log message for revision 70607:
- added basic unit tests for mailPassword() and registeredNotify()
- removed ignored return value
Changed:
U CMF/trunk/CMFDefault/RegistrationTool.py
A CMF/trunk/CMFDefault/tests/RegistrationTool.txt
U CMF/trunk/CMFDefault/tests/test_RegistrationTool.py
-=-
Modified: CMF/trunk/CMFDefault/RegistrationTool.py
===================================================================
--- CMF/trunk/CMFDefault/RegistrationTool.py 2006-10-12 12:30:11 UTC (rev 70606)
+++ CMF/trunk/CMFDefault/RegistrationTool.py 2006-10-12 18:21:26 UTC (rev 70607)
@@ -183,8 +183,6 @@
host = self.MailHost
host.send( mail_text )
- return self.mail_password_response( self, self.REQUEST )
-
security.declareProtected(ManagePortal, 'editMember')
def editMember( self
, member_id
Added: CMF/trunk/CMFDefault/tests/RegistrationTool.txt
===================================================================
--- CMF/trunk/CMFDefault/tests/RegistrationTool.txt 2006-10-12 12:30:11 UTC (rev 70606)
+++ CMF/trunk/CMFDefault/tests/RegistrationTool.txt 2006-10-12 18:21:26 UTC (rev 70607)
@@ -0,0 +1,48 @@
+RegistrationTool
+
+ First we need some dummy code::
+
+ >>> class Member:
+ ... def __repr__(self): return 'foo'
+ ... def getProperty(self, id): return 'foo at example.org'
+ ... def getPassword(self): return 'secret'
+
+ >>> class MembershipTool:
+ ... def getMemberById(self, id): return Member()
+
+ >>> class MailHost:
+ ... def send(self, messageText): self.lastMessage = messageText
+
+ >>> def password_email(**kw):
+ ... return 'Reminder: %(member)s, %(password)s' % kw
+
+ >>> def mail_password_response(*args):
+ ... return 'done'
+
+ >>> def registered_email(**kw):
+ ... return 'Welcome: %(member)s, %(password)s, %(email)s' % kw
+
+ Now we can set up a RegistrationTool with dummy context::
+
+ >>> from Products.CMFDefault.RegistrationTool import RegistrationTool
+ >>> rtool = RegistrationTool()
+ >>> rtool.MailHost = MailHost()
+ >>> rtool.portal_membership = MembershipTool()
+ >>> rtool.password_email = password_email
+ >>> rtool.mail_password_response = mail_password_response
+ >>> rtool.registered_email = registered_email
+
+ mailPassword sends a password reminder and returns a response page::
+
+ >>> rtool.mailPassword('foo', None)
+ 'done'
+
+ >>> rtool.MailHost.lastMessage
+ 'Reminder: foo, secret'
+
+ registeredNotify sends a welcome message::
+
+ >>> rtool.registeredNotify('foo')
+
+ >>> rtool.MailHost.lastMessage
+ 'Welcome: foo, secret, foo at example.org'
Property changes on: CMF/trunk/CMFDefault/tests/RegistrationTool.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: CMF/trunk/CMFDefault/tests/test_RegistrationTool.py
===================================================================
--- CMF/trunk/CMFDefault/tests/test_RegistrationTool.py 2006-10-12 12:30:11 UTC (rev 70606)
+++ CMF/trunk/CMFDefault/tests/test_RegistrationTool.py 2006-10-12 18:21:26 UTC (rev 70607)
@@ -18,6 +18,8 @@
import unittest
import Testing
+from zope.testing import doctest
+
from Products.CMFCore.tests.base.testcase import RequestTest
@@ -137,6 +139,8 @@
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(RegistrationToolTests),
+ doctest.DocFileSuite('RegistrationTool.txt',
+ optionflags=doctest.NORMALIZE_WHITESPACE),
))
if __name__ == '__main__':
More information about the CMF-checkins
mailing list