Back to index

plone3  3.1.7
test_join.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ Unit tests for adding members.
00014 
00015 $Id: test_join.py 73035 2007-03-07 16:41:03Z jens $
00016 """
00017 
00018 import unittest
00019 from Testing import ZopeTestCase
00020 
00021 from zope.app.component.hooks import setSite
00022 
00023 from Products.CMFDefault.testing import FunctionalLayer
00024 
00025 
00026 class MembershipTests(ZopeTestCase.FunctionalTestCase):
00027 
00028     layer = FunctionalLayer
00029 
00030     def afterSetUp(self):
00031         setSite(self.app.site)
00032 
00033     def test_join( self ):
00034         site = self.app.site
00035         member_id = 'test_user'
00036 
00037         site.portal_registration.addMember( member_id
00038                                           , 'zzyyzz'
00039                                           , properties={ 'username': member_id
00040                                                        , 'email' : 'foo@bar.com'
00041                                                        }
00042                                           )
00043         u = site.acl_users.getUser(member_id)
00044         self.failUnless(u)
00045 
00046     def test_join_memberproperties(self):
00047         # Make sure the member data wrapper carries correct properties
00048         # after joining
00049         site = self.app.site
00050         member_id = 'test_user'
00051 
00052         site.portal_registration.addMember( member_id
00053                                           , 'zzyyzz'
00054                                           , properties={ 'username': member_id
00055                                                        , 'email' : 'foo@bar.com'
00056                                                        }
00057                                           )
00058 
00059         m = site.portal_membership.getMemberById('test_user')
00060         self.assertEqual(m.getProperty('email'), 'foo@bar.com')
00061         self.assertEqual(m.getMemberId(), member_id)
00062         self.assertEqual(m.getRoles(), ('Member', 'Authenticated'))
00063 
00064     def test_join_without_email( self ):
00065         site = self.app.site
00066 
00067         self.assertRaises(ValueError,
00068                           site.portal_registration.addMember,
00069                           'test_user',
00070                           'zzyyzz',
00071                           properties={'username':'test_user', 'email': ''}
00072                           )
00073 
00074     def test_join_with_variable_id_policies( self ):
00075         site = self.app.site
00076         member_id = 'test.user'
00077 
00078         # Test with the default policy: Names with "." should fail
00079         self.assertRaises(ValueError,
00080                           site.portal_registration.addMember,
00081                           member_id,
00082                           'zzyyzz',
00083                           properties={ 'username':'Test User'
00084                                      , 'email': 'foo@bar.com'
00085                                      }
00086                           )
00087 
00088         # Now change the policy to allow "."
00089         new_pattern = "^[A-Za-z][A-Za-z0-9_\.]*$"
00090         site.portal_registration.manage_editIDPattern(new_pattern)
00091         site.portal_registration.addMember( member_id
00092                                           , 'zzyyzz'
00093                                           , properties={ 'username': 'TestUser2'
00094                                                        , 'email' : 'foo@bar.com'
00095                                                        }
00096                                           )
00097         u = site.acl_users.getUser(member_id)
00098         self.failUnless(u)
00099 
00100 
00101 def test_suite():
00102     return unittest.TestSuite((
00103         unittest.makeSuite(MembershipTests),
00104         ))
00105 
00106 if __name__ == '__main__':
00107     from Products.CMFCore.testing import run
00108     run(test_suite())