Commit 14f26ca0 authored by Nicolas Dumazet's avatar Nicolas Dumazet

Fix descendants of PropertySheetTestCase:

* use beforeTearDown instead of tearDown
* pay attention to abort() ordering so that no parent or
  subclass calls can invalidate necessary changes from tearDown logic
* use unique names for property sheets to get independant fixtures.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43099 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 59359459
......@@ -58,10 +58,10 @@ class TestPreferences(PropertySheetTestCase):
self.createPreferences()
def beforeTearDown(self):
transaction.abort()
portal_preferences = self.getPreferenceTool()
portal_preferences.manage_delObjects(list(portal_preferences.objectIds()))
transaction.commit()
self.tic()
super(TestPreferences, self).beforeTearDown()
def createPreferences(self):
""" create some preferences objects """
......@@ -560,7 +560,8 @@ class TestPreferences(PropertySheetTestCase):
self.assertEqual(system_pref, preference_tool.getActiveSystemPreference())
def test_boolean_accessor(self):
self._addProperty('Preference', 'DummyPreference',
self._addProperty('Preference',
'test_boolean_accessor Preference',
portal_type='Standard Property',
property_id='dummy',
preference=True,
......@@ -584,7 +585,8 @@ class TestPreferences(PropertySheetTestCase):
write_permission = 'Modify portal content'
read_permission = 'Manage portal'
self._addProperty('Preference', 'DummyPreference',
self._addProperty('Preference',
'test_property_sheet_security_on_permission Preference',
property_id='preferred_toto',
portal_type='Standard Property',
preference=1,
......@@ -633,7 +635,8 @@ class TestPreferences(PropertySheetTestCase):
default_preference_string = 'Default Name'
normal_preference_string = 'Normal Preference'
system_preference_string = 'System Preference'
self._addProperty('Preference', 'DummySystemPreference',
self._addProperty('Preference',
'test_system_preference_value_prefererred Preference',
portal_type='Standard Property',
property_id='dummystring',
property_default='python: "%s"' % default_preference_string,
......@@ -667,7 +670,8 @@ class TestPreferences(PropertySheetTestCase):
default_preference_string = 'Default Name'
normal_preference_string = 'Normal Preference'
system_preference_string = 'System Preference'
self._addProperty('Preference', 'DummySystemPreference',
self._addProperty('Preference',
'test_system_preference_value_prefererred_clear_cache_disabled Preference',
portal_type='Standard Property',
property_id='dummystring',
property_default='python: "%s"' % default_preference_string,
......
......@@ -72,8 +72,7 @@ class TestConstraint(PropertySheetTestCase):
transaction.abort()
module = self.portal.organisation_module
module.manage_delObjects(list(module.objectIds()))
transaction.commit()
self.tic()
super(TestConstraint, self).beforeTearDown()
def createCategories(self):
"""
......
......@@ -27,7 +27,6 @@
##############################################################################
import cPickle
import md5
import unittest
import sys
......@@ -42,7 +41,6 @@ from Products.ERP5Type.tests.utils import LogInterceptor
from Products.CMFCore.WorkflowCore import WorkflowException
from Products.ERP5Type.Accessor.Constant import PropertyGetter as ConstantGetter
from Products.ERP5Type.tests.utils import installRealClassTool
from Products.ERP5Type.Utils import removeLocalPropertySheet
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl import getSecurityManager
from AccessControl import Unauthorized
......@@ -64,9 +62,8 @@ class PropertySheetTestCase(ERP5TypeTestCase):
super(PropertySheetTestCase,self).setUp()
installRealClassTool(self.getPortal())
def tearDown(self):
def beforeTearDown(self):
"""Clean up """
transaction.abort()
ttool = self.getTypesTool()
# remove all property sheet we added to type informations
for ti_name, psheet_list in self._added_property_sheets.items():
......@@ -81,7 +78,8 @@ class PropertySheetTestCase(ERP5TypeTestCase):
# but in the other hand, if isolates the test "just in case"
ttool.resetDynamicDocumentsOnceAtTransactionBoundary()
transaction.commit()
super(PropertySheetTestCase, self).tearDown()
self.tic()
super(PropertySheetTestCase, self).beforeTearDown()
def _addProperty(self, portal_type_name, property_sheet_id,
property_id=None,
......@@ -145,8 +143,7 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
self.getTypesTool().getTypeInfo('Person').acquire_local_roles = self.person_acquire_local_roles
self.portal.portal_caches.clearAllCache()
transaction.commit()
self.tic()
super(TestERP5Type, self).beforeTearDown()
def loginWithNoRole(self):
uf = self.portal.acl_users
......@@ -828,7 +825,9 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
"""Tests that the default value is returned correctly when a default
value is defined using the property sheet.
"""
self._addProperty('Person', 'Person_dummy_ps_prop', 'dummy_ps_prop',
self._addProperty('Person',
'test_15b_DefaultValueDefinedOnPropertySheet',
'dummy_ps_prop',
elementary_type='string',
portal_type='Standard Property',
property_default='python: "ps_default"')
......@@ -860,7 +859,9 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
"""Tests that the default value is returned correctly when a default
value is defined using the property sheet, on list accesors.
"""
self._addProperty('Person', 'Person_dummy_ps_prop', 'dummy_ps_prop',
self._addProperty('Person',
'test_15b_ListAccessorsDefaultValueDefinedOnPropertySheet',
'dummy_ps_prop',
elementary_type='lines',
portal_type='Standard Property',
property_default='python: [1,2,3]')
......@@ -905,7 +906,9 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
def test_16_SimpleStringAccessor(self):
"""Tests a simple string accessor.
This is also a way to test _addProperty method """
self._addProperty('Person', 'Person_dummy_ps_prop', 'dummy_ps_prop',
self._addProperty('Person',
'test_16_SimpleStringAccessor',
'dummy_ps_prop',
elementary_type='string',
portal_type='Standard Property')
person = self.getPersonModule().newContent(id='1', portal_type='Person')
......@@ -1008,7 +1011,9 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
# For testing purposes, we add a default_organisation inside a person,
# and we add code to generate a 'default_organisation_title' property on
# this person that will returns the organisation title.
self._addProperty('Person', 'Person_organisation', 'organisation',
self._addProperty('Person',
'test_18_SimpleContentAccessor',
'organisation',
**self.DEFAULT_ORGANISATION_TITLE_PROP)
person = self.getPersonModule().newContent(id='1', portal_type='Person')
self.assertTrue(hasattr(person, 'getDefaultOrganisationTitle'))
......@@ -1070,7 +1075,9 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
# This is test is very similar to test_18_SimpleContentAccessor, but we
# use reference instead of title, because Reference accessors are
# generated.
self._addProperty('Person', 'Person_organisation', 'organisation',
self._addProperty('Person',
'test_18_SimpleContentAccessorWithGeneratedAccessor',
'organisation',
**self.DEFAULT_ORGANISATION_TITLE_PROP)
person = self.getPersonModule().newContent(id='1', portal_type='Person')
self.assertTrue(hasattr(person, 'getDefaultOrganisationReference'))
......@@ -1128,7 +1135,9 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
that may have the same id, using same scenario as test_18
Note that we only test Setter for now.
"""
self._addProperty('Person', 'Person_organisation', 'organisation',
self._addProperty('Person',
'test_18b_ContentAccessorWithIdClash',
'organisation',
**self.DEFAULT_ORGANISATION_TITLE_PROP)
person = self.getPersonModule().newContent(id='1', portal_type='Person')
another_person = self.getPersonModule().newContent(
......@@ -1170,7 +1179,9 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
# defined, then we will acquire the default organisation title of the
# `destination` person. This is a stupid example, but it works with
# objects we have in our testing environnement
self._addProperty('Person', 'Person_organisation', 'organisation',
self._addProperty('Person',
'test_19_AcquiredContentAccessor',
'organisation',
**self.DEFAULT_ORGANISATION_TITLE_ACQUIRED_PROP)
# add destination base category to Person TI
person_ti = self.getTypesTool().getTypeInfo('Person')
......@@ -1202,7 +1213,9 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
that may have the same id, using same scenario as test_19
Note that we only test Setter for now.
"""
self._addProperty('Person', 'Person_organisation', 'organisation',
self._addProperty('Person',
'test_19b_AcquiredContentAccessorWithIdClash',
'organisation',
**self.DEFAULT_ORGANISATION_TITLE_ACQUIRED_PROP)
# add destination base category to Person TI
person_ti = self.getTypesTool().getTypeInfo('Person')
......@@ -1245,10 +1258,14 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
We check in particular that getDefault[Property] and
setDefault[Property] are working correctly
"""
self._addProperty('Person', 'Person_lang', 'available_language',
self._addProperty('Person',
'test_19c_AcquiredTokensAccessor_Person',
'available_language',
commit=False,
**self.DEFAULT_LANGUAGE_PROP)
self._addProperty('Email', 'Email_lang', 'available_language',
self._addProperty('Email',
'test_19c_AcquiredTokensAccessor_Email',
'available_language',
**self.DEFAULT_LANGUAGE_PROP)
# Category setters (list, set, default)
......@@ -1281,7 +1298,9 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
setDefault[Property] are working correctly
This test focus on acquisition_mask_value parameter
"""
self._addProperty('Person', 'Person_19c2', 'subordination_organisation_reference',
self._addProperty('Person',
'test_19c2_AcquiredStringAccessor',
'subordination_organisation_reference',
**self.SUBORDINATION_ORGANISATION_REFERENCE)
person = self.getPersonModule().newContent(portal_type='Person')
......@@ -1327,7 +1346,9 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
setDefault[Property] are working correctly
This test focus on acquisition_mask_value parameter
"""
self._addProperty('Person', 'Person_19c3', 'subordination_organisation_source_reference',
self._addProperty('Person',
'test_19c3_AcquiredStringAccessor',
'subordination_organisation_source_reference',
**self.SUBORDINATION_ORGANISATION_SOURCE_REFERENCE)
person = self.getPersonModule().newContent(portal_type='Person')
......@@ -1381,12 +1402,17 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
Boolean accessors generate both an getPropertyName and an isPropertyName
Check in particular that both behave the same way regarding acquisition
"""
self._addProperty('Person', 'Person_19d', 'name_included_in_address',
self._addProperty('Person',
'test_19d_AcquiredBooleanAccessor_Person',
'name_included_in_address',
commit=False,
portal_type='Standard Property',
property_default="python: True",
elementary_type="boolean")
self._addProperty('Email', 'Email_19d', 'name_included_in_address',
self._addProperty('Email',
'test_19d_AcquiredBooleanAccessor_Email',
'name_included_in_address',
'name_included_in_address',
content_acquired_property_id=('name_included_in_address', ),
acquisition_base_category=( 'parent', ),
acquisition_portal_type="python: ( 'Person', )",
......@@ -1814,7 +1840,9 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
"""Test 'has' Accessor.
This accessor returns true if the property is set on the document.
"""
self._addProperty('Person', 'Person_foobar', 'foo_bar',
self._addProperty('Person',
'test_26_hasAccessors',
'foo_bar',
elementary_type='string',
portal_type='Standard Property')
obj = self.getPersonModule().newContent(portal_type='Person')
......@@ -2193,7 +2221,9 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
region_category.restrictedTraverse, "beta")
# Define the acquired property
self._addProperty('Person', 'Person_test_unaccessible', 'wrapped_region_title',
self._addProperty('Person',
'Person_test_unaccessible',
'wrapped_region_title',
portal_type='Acquired Property',
elementary_type='lines',
description='The title of the region',
......@@ -2282,7 +2312,7 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
logged_errors[0].getMessage())
def test_list_accessors(self):
self._addProperty('Person', 'Person_dummy', 'dummy',
self._addProperty('Person', 'test_list_accessors', 'dummy',
elementary_type='lines',
portal_type='Standard Property')
module = self.getPersonModule()
......@@ -2310,7 +2340,9 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
self.assertEquals(person.getDummySet(), ['value'])
def test_translated_accessors(self):
self._addProperty('Person', 'Person_dummy', 'dummy',
self._addProperty('Person',
'test_translated_accessors',
'dummy',
elementary_type='string',
translatable=1,
translation_domain='erp5_ui',
......@@ -2546,7 +2578,9 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
def test_DefaultSecurityOnAccessors(self):
# Test accessors are protected correctly
self._addProperty('Person', 'Person_foobar', 'foo_bar',
self._addProperty('Person',
'test_DefaultSecurityOnAccessors',
'foo_bar',
elementary_type='string',
portal_type='Standard Property')
obj = self.getPersonModule().newContent(portal_type='Person')
......@@ -2567,7 +2601,9 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
def test_DefaultSecurityOnListAccessors(self):
# Test list accessors are protected correctly
self._addProperty('Person', 'Person_foobar', 'foo_bar',
self._addProperty('Person',
'test_DefaultSecurityOnListAccessors',
'foo_bar',
elementary_type='lines',
portal_type='Standard Property')
obj = self.getPersonModule().newContent(portal_type='Person')
......@@ -2624,7 +2660,9 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
def test_PropertySheetSecurityOnAccessors(self):
# Test accessors are protected correctly when you specify the permission
# in the property sheet.
self._addProperty('Person', 'Person_foobar', 'foo_bar',
self._addProperty('Person',
'test_PropertySheetSecurityOnAccessors',
'foo_bar',
elementary_type='string',
write_permission='Set own password',
read_permission='Manage users',
......@@ -2643,7 +2681,9 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
self.assertFalse(guarded_hasattr(obj, 'getFooBar'))
def test_edit(self):
self._addProperty('Person', 'Person_foobar', 'foo_bar',
self._addProperty('Person',
'test_edit',
'foo_bar',
elementary_type='string',
write_permission='Set own password',
read_permission='Manage users',
......@@ -2724,7 +2764,9 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
Check that we can use setPropertyList and getPropertyList
on a mono valued property
"""
self._addProperty('Person', 'Person_foobar', 'foo_bar',
self._addProperty('Person',
'testPropertyListWithMonoValuedProperty',
'foo_bar',
elementary_type='string',
portal_type='Standard Property')
person = self.getPersonModule().newContent(portal_type='Person')
......@@ -2750,11 +2792,15 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
Check that we can use setPropertyList and getPropertyList
on a mono valued acquired property
"""
self._addProperty('Person', 'Person_foobar', 'foo_bar',
self._addProperty('Person',
'testPropertyListOnMonoValuedAcquiredProperty_Person',
'foo_bar',
commit=False,
elementary_type='string',
portal_type='Standard Property')
self._addProperty('Email', 'Email_foobar', 'foo_bar',
self._addProperty('Email',
'testPropertyListOnMonoValuedAcquiredProperty_Email',
'foo_bar',
elementary_type='string',
portal_type='Acquired Property',
content_acquired_property_id=('description', ),
......@@ -2780,7 +2826,9 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
Check that we can use setPropertyList and getPropertyList
on a multi valued property
"""
self._addProperty('Person', 'Person_foobar', 'foo_bar',
self._addProperty('Person',
'testPropertyListWithMultiValuedProperty',
'foo_bar',
elementary_type='lines',
portal_type='Standard Property')
person = self.getPersonModule().newContent(portal_type='Person')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment