[Erp5-report] r35517 jerome - /erp5/trunk/products/ERP5/tests/testTemplate.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri May 21 13:26:17 CEST 2010
Author: jerome
Date: Fri May 21 13:26:10 2010
New Revision: 35517
URL: http://svn.erp5.org?rev=35517&view=rev
Log:
test new features from 34467, and update test accordingly.
Modified:
erp5/trunk/products/ERP5/tests/testTemplate.py
Modified: erp5/trunk/products/ERP5/tests/testTemplate.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testTemplate.py?rev=35517&r1=35516&r2=35517&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testTemplate.py [utf8] (original)
+++ erp5/trunk/products/ERP5/tests/testTemplate.py [utf8] Fri May 21 13:26:10 2010
@@ -187,6 +187,79 @@
# created preference is reused to store template
self.assertEquals('enabled', user_preference.getPreferenceState())
self.assertEqual(len(user_preference.objectIds()), 1)
+
+ def test_TemplateCreatePreferenceWithExistingNonAuthorizedPreference(self):
+ # When there is an active preference, but without add permission in that
+ # preference, another preference is created when making a template
+ self.createUserAndLogin(self.id())
+ unauthorized_preference = self.portal.portal_preferences.newContent(
+ portal_type='Preference')
+ unauthorized_preference.enable()
+ # it's not authorized to add content in this preference
+ unauthorized_preference.manage_permission('Add portal content', (), acquire=0)
+ preference_id_list = list(self.portal.portal_preferences.objectIds())
+
+ transaction.commit()
+ self.tic()
+
+ document = self.portal.foo_module.newContent(portal_type='Foo')
+ transaction.commit()
+ self.tic()
+
+ document.Base_makeTemplateFromDocument(form_id=None)
+ transaction.commit()
+ self.tic()
+
+ # this preference was not used
+ self.assertEqual(len(unauthorized_preference.objectIds()), 0)
+
+ # a new preference is created
+ new_preference_id_list = list(self.portal.portal_preferences.objectIds())
+ self.assertEqual(len(preference_id_list) + 1, len(new_preference_id_list))
+ preference_id = [x for x in new_preference_id_list if x not in
+ preference_id_list][0]
+ preference = self.portal.portal_preferences._getOb(preference_id)
+ self.assertEquals('Preference', preference.getPortalType())
+ self.assertEquals('enabled', preference.getPreferenceState())
+
+ self.assertEqual(len(preference.objectIds()), 1)
+
+ def test_TemplateCreateWithSameTitleUpdateExisting(self):
+ # When we create a template with the same title as an existing template, it
+ # replaces the existing one.
+ self.createUserAndLogin(self.id())
+ user_preference = self.portal.portal_preferences.newContent(
+ portal_type='Preference')
+ user_preference.setPriority(Priority.USER)
+ user_preference.enable()
+ transaction.commit()
+ self.tic()
+
+ document = self.portal.foo_module.newContent(portal_type='Foo',
+ title='template',
+ description='First document')
+ transaction.commit()
+ self.tic()
+
+ document.Base_makeTemplateFromDocument(form_id=None)
+ transaction.commit()
+ self.tic()
+
+ self.assertEqual(len(user_preference.objectIds()), 1)
+ self.assertEqual(user_preference.objectValues()[0].getDescription(),
+ 'First document')
+
+ other_document = self.portal.foo_module.newContent(
+ portal_type='Foo',
+ title='template',
+ description="Another document")
+ other_document.Base_makeTemplateFromDocument(form_id=None)
+ transaction.commit()
+ self.tic()
+ self.assertEqual(len(user_preference.objectIds()), 1)
+ self.assertEqual(user_preference.objectValues()[0].getDescription(),
+ 'Another document')
+
def test_TemplateCreatePreferenceWithSystemPreferenceEnabled(self):
# TODO: This test *might* be removed if it is good to trust
@@ -240,7 +313,6 @@
preference_id = [x for x in new_preference_id_list if x not in
preference_id_list][0]
preference = self.portal.portal_preferences._getOb(preference_id)
-
self.assertEquals('Preference', preference.getPortalType())
self.assertEquals('Document Template Container', preference.getTitle())
self.assertEquals(Priority.USER, preference.getPriority())
@@ -280,10 +352,7 @@
preference = self.portal.portal_preferences._getOb(preference_id)
self.assertEquals('Preference', preference.getPortalType())
- self.assertEquals('Document Template Container', preference.getTitle())
- self.assertEquals(Priority.USER, preference.getPriority())
self.assertEquals('enabled', preference.getPreferenceState())
-
self.assertEqual(len(preference.objectIds()), 2)
def _testTemplateNotIndexable(self, document):
@@ -315,6 +384,10 @@
self.assertEquals(0,
len(self.portal.portal_catalog(uid=template_line.getUid())))
+ # change the title, because creating another template with same title will
+ # replace the first one
+ document.setTitle('%sb' % document.getTitle())
+
# and this is still true if you create two templates from the same document
# #929
document.Base_makeTemplateFromDocument(form_id=None)
More information about the Erp5-report
mailing list