Back to index

plone3  3.1.7
testMemberDataTool.py
Go to the documentation of this file.
00001 #
00002 # MemberDataTool tests
00003 #
00004 
00005 from Products.CMFPlone.tests import PloneTestCase
00006 from Products.CMFPlone.tests import dummy
00007 
00008 from DateTime import DateTime
00009 
00010 from OFS.Image import Image
00011 default_user = PloneTestCase.default_user
00012 
00013 
00014 class TestMemberDataTool(PloneTestCase.PloneTestCase):
00015 
00016     def afterSetUp(self):
00017         self.memberdata = self.portal.portal_memberdata
00018         self.membership = self.portal.portal_membership
00019         self.membership.memberareaCreationFlag = 0
00020         # Don't let default_user disturb results
00021         self.portal.acl_users._doDelUsers([default_user])
00022         # Add some members
00023         self.addMember('fred', 'Fred Flintstone', 'fred@bedrock.com', ['Member', 'Reviewer'], '2002-01-01')
00024         self.addMember('barney', 'Barney Rubble', 'barney@bedrock.com', ['Member'], '2002-01-01')
00025         self.addMember('brubble', 'Bambam Rubble', 'bambam@bambam.net', ['Member'], '2003-12-31')
00026         # MUST reset this
00027         self.memberdata._v_temps = None
00028 
00029     def addMember(self, username, fullname, email, roles, last_login_time):
00030         self.membership.addMember(username, 'secret', roles, [])
00031         member = self.membership.getMemberById(username)
00032         member.setMemberProperties({'fullname': fullname, 'email': email,
00033                                     'last_login_time': DateTime(last_login_time),})
00034 
00035     def testSetPortrait(self):
00036         self.memberdata._setPortrait(Image(id=default_user, file=dummy.File(), title=''), default_user)
00037         self.assertEqual(self.memberdata._getPortrait(default_user).getId(), default_user)
00038         self.assertEqual(self.memberdata._getPortrait(default_user).meta_type, 'Image')
00039 
00040     def testDeletePortrait(self):
00041         self.memberdata._setPortrait(Image(id=default_user, file=dummy.File(), title=''), default_user)
00042         self.memberdata._deletePortrait(default_user)
00043         self.assertEqual(self.memberdata._getPortrait(default_user), None)
00044 
00045     def testPruneMemberDataContents(self):
00046         # Only test what is not already tested elswhere
00047         self.memberdata._setPortrait(Image(id=default_user, file=dummy.File(), title=''), default_user)
00048         self.memberdata._setPortrait(Image(id=default_user, file=dummy.File(), title=''), 'dummy')
00049         self.memberdata.pruneMemberDataContents()
00050         self.assertEqual(len(self.memberdata.portraits.objectIds()), 1)
00051 
00052     def testFulltextMemberSearch(self):
00053         # Search for a user by id, name, email, ...
00054         search = self.memberdata.searchFulltextForMembers
00055         self.assertEqual(len(search('')), 3)
00056         self.assertEqual(len(search('rubble')), 2)
00057         self.assertEqual(len(search('stone')), 1)
00058         self.assertEqual(len(search('bambam.net')), 1)
00059         self.assertEqual(len(search('bedrock.com')), 2)
00060         self.assertEqual(len(search('brubble')), 1)
00061 
00062 
00063 def test_suite():
00064     from unittest import TestSuite, makeSuite
00065     suite = TestSuite()
00066     suite.addTest(makeSuite(TestMemberDataTool))
00067     return suite