Back to index

plone3  3.1.7
Public Member Functions
PlonePAS.tests.test_properties.PropertiesTest Class Reference
Inheritance diagram for PlonePAS.tests.test_properties.PropertiesTest:
Inheritance graph
[legend]
Collaboration diagram for PlonePAS.tests.test_properties.PropertiesTest:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_user_properties
def test_group_properties
def test_schema_for_mutable_property_provider

Detailed Description

Definition at line 29 of file test_properties.py.


Member Function Documentation

Definition at line 100 of file test_properties.py.

00100 
00101     def test_group_properties(self):
00102         gt = getToolByName(self.portal, 'portal_groups')
00103         gd = getToolByName(self.portal, 'portal_groupdata')
00104 
00105         self.loginAsPortalOwner()
00106 
00107         # Create a new Group
00108         gt.addGroup('group1', ['Reviewer'], [],
00109                      {'email': 'group1@host.com',
00110                       'title': 'Group #1'})
00111         group = gt.getGroupById('group1')
00112         self.failIf(group is None)
00113 
00114         # Assert group doesn't have the property yet
00115         self.failIf(group.hasProperty('karma'))
00116 
00117         # Add new property
00118         gd.manage_addProperty('karma', 20, 'int')
00119 
00120         # get group again to re-create with new groupdata schema
00121         group = gt.getGroupById('group1')
00122 
00123         # Assert group has the property now
00124         self.failUnless(group.hasProperty('karma'))
00125 
00126         # Get the property, should have the default value
00127         got = group.getProperty('karma', None)
00128         expected = 20
00129 
00130         self.assertEquals(got, expected)
00131 
00132         # Set some group properties
00133         group.setGroupProperties({'karma':30, 'title':'Group #1 Is Cool',
00134                                   'email':'group1@anotherhost.qa'})
00135 
00136         # Check the properties have been set
00137         got = group.getProperty('karma', None)
00138         expected = 30
00139         self.assertEquals(got, expected)
00140 
00141         got = group.getProperty('title', None)
00142         expected = 'Group #1 Is Cool'
00143         self.assertEquals(got, expected)
00144 
00145         got = group.getProperty('email', None)
00146         expected = 'group1@anotherhost.qa'
00147         self.assertEquals(got, expected)
00148 
00149         # Delete the property
00150         gd.manage_delProperties(ids=('karma',))
00151 
00152         # get group again to re-create with new groupdata schema
00153         group = gt.getGroupById('group1')
00154 
00155         # Assert property is gone
00156         self.failIf(group.hasProperty('karma'))
00157 
00158         # Get the property, should return default (None)
00159         got = group.getProperty('karma', None)
00160         expected = None
00161         self.assertEquals(got, expected)
00162 
00163         # Other properties should still be there.
00164         got = group.getProperty('title', None)
00165         expected = 'Group #1 Is Cool'
00166         self.assertEquals(got, expected)
00167 
00168         got = group.getProperty('email', None)
00169         expected = 'group1@anotherhost.qa'
00170         self.assertEquals(got, expected)
00171 

Here is the call graph for this function:

Add a schema to a ZODBMutablePropertyProvider.

Definition at line 172 of file test_properties.py.

00172 
00173     def test_schema_for_mutable_property_provider(self):
00174         """Add a schema to a ZODBMutablePropertyProvider.
00175         """
00176 
00177         # Schema is list of tuples with name, type (string), value.
00178         # From the types it seems only 'lines' is handled differently.
00179         address_schema = [
00180             ('addresses', 'lines', ['Here', 'There']),
00181             ('city', 'str', 'Somewhere'),
00182             ('telephone', 'int', 1234567),
00183             ]
00184 
00185         # This used to give a ValueError, so we just check that it
00186         # does not.
00187         provider = ZODBMutablePropertyProvider(
00188             'address_plugin', "Address Plugin", schema=address_schema)
00189 
00190         # When this test passes, we are happy already, but let's add a
00191         # few more basic tests.
00192 
00193         # Create a new Member
00194         mt = getToolByName(self.portal, 'portal_membership')
00195         mt.addMember('user1', 'u1', ['Member'], [],
00196                      {'email': 'user1@host.com',
00197                       'fullname': 'User #1'})
00198         member = mt.getMemberById('user1')
00199         sheet = provider.getPropertiesForUser(member)
00200         self.assertEqual(
00201             sheet.propertyIds(), ['addresses', 'city', 'telephone'])
00202         self.assertEqual(sheet.propertyInfo('city'), 
00203                          {'type': 'str', 'id': 'city', 'mode': ''})
00204         self.assertEqual(sheet.getProperty('addresses'), ('Here', 'There'))
00205  

Here is the call graph for this function:

Definition at line 31 of file test_properties.py.

00031 
00032     def test_user_properties(self):
00033         mt = getToolByName(self.portal, 'portal_membership')
00034         md = getToolByName(self.portal, 'portal_memberdata')
00035 
00036         # Create a new Member
00037         mt.addMember('user1', 'u1', ['Member'], [],
00038                      {'email': 'user1@host.com',
00039                       'fullname': 'User #1'})
00040         member = mt.getMemberById('user1')
00041         self.failIf(member is None)
00042 
00043         # Assert user doesn't have the property yet
00044         self.failIf(member.hasProperty('age'))
00045 
00046         # Add new property
00047         md.manage_addProperty('age', 20, 'int')
00048 
00049         # Assert user has the property now
00050         self.failUnless(member.hasProperty('age'))
00051 
00052         # Get the property, should have the default value
00053         got = member.getProperty('age', None)
00054         expected = 20
00055         self.assertEquals(got, expected)
00056 
00057         # get a handle on the member
00058         member = mt.getMemberById('user1')
00059 
00060         # Set some member properties. Needs to be logged in as the user.
00061         self.login('user1')
00062         member.setMemberProperties({'age':30, 'fullname':'User #1 Is Cool',
00063                                     'email':'user1@anotherhost.qa'})
00064 
00065         # Check the properties have been set
00066         got = member.getProperty('age', None)
00067         expected = 30
00068         self.assertEquals(got, expected)
00069 
00070         got = member.getProperty('fullname', None)
00071         expected = 'User #1 Is Cool'
00072         self.assertEquals(got, expected)
00073 
00074         got = member.getProperty('email', None)
00075         expected = 'user1@anotherhost.qa'
00076         self.assertEquals(got, expected)
00077 
00078         # Delete the property
00079         md.manage_delProperties(ids=('age',))
00080 
00081         # re-get the member to reflect the new memberdata schema
00082         member = mt.getMemberById('user1')
00083 
00084         # Assert property is gone
00085         self.failIf(member.hasProperty('age'))
00086 
00087         # Get the property, should return default (None)
00088         got = member.getProperty('age', None)
00089         expected = None
00090         self.assertEquals(got, expected)
00091 
00092         # Other properties should still be there.
00093         got = member.getProperty('fullname', None)
00094         expected = 'User #1 Is Cool'
00095         self.assertEquals(got, expected)
00096 
00097         got = member.getProperty('email', None)
00098         expected = 'user1@anotherhost.qa'
00099         self.assertEquals(got, expected)

Here is the call graph for this function:


The documentation for this class was generated from the following file: