From abd6428ef9240ff2d43515f6b3c5d7491d1897ff Mon Sep 17 00:00:00 2001 From: Ivan Tyagov <ivan@nexedi.com> Date: Fri, 25 Mar 2011 13:35:46 +0000 Subject: [PATCH] Test redirect to Person object & Preferences for logged in user. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@44623 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/tests/testERP5Web.py | 119 ++++++++++++------------------ 1 file changed, 49 insertions(+), 70 deletions(-) diff --git a/product/ERP5/tests/testERP5Web.py b/product/ERP5/tests/testERP5Web.py index 4ac5b1950a..ced0300413 100644 --- a/product/ERP5/tests/testERP5Web.py +++ b/product/ERP5/tests/testERP5Web.py @@ -30,7 +30,6 @@ import re import unittest - import transaction from AccessControl import Unauthorized from AccessControl.SecurityManagement import newSecurityManager @@ -108,8 +107,7 @@ class TestERP5Web(ERP5TypeTestCase): id = self.website_id, **kw) website.publish() - transaction.commit() - self.tic() + self.stepTic() return website def setupWebSection(self, **kw): @@ -129,8 +127,7 @@ class TestERP5Web(ERP5TypeTestCase): max='', min='') - transaction.commit() - self.tic() + self.stepTic() return websection def setupWebSitePages(self, prefix, suffix=None, version='0.1', @@ -156,8 +153,7 @@ class TestERP5Web(ERP5TypeTestCase): language=language, **kw) webpage.publish() - transaction.commit() - self.tic() + self.stepTic() self.assertEquals(language, webpage.getLanguage()) self.assertEquals(reference, webpage.getReference()) self.assertEquals(version, webpage.getVersion()) @@ -201,12 +197,10 @@ class TestERP5Web(ERP5TypeTestCase): self.portal.portal_transforms.max_sec_in_cache=-1 page = self.web_page_module.newContent(portal_type='Web Page') page.edit(text_content='<p>Hé Hé Hé!</p>') - transaction.commit() - self.tic() + self.stepTic() self.assertEquals('Hé Hé Hé!', page.asText().strip()) page.edit(text_content='<p>Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé!</p>') - transaction.commit() - self.tic() + self.stepTic() self.assertEquals("""Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé Hé!""", page.asText().strip()) @@ -228,8 +222,7 @@ Hé Hé Hé!""", page.asText().strip()) website = portal.web_site_module[self.website_id] website.WebSite_createWebSiteAccount('WebSite_viewRegistrationDialog') - transaction.commit() - self.tic() + self.stepTic() # find person object by reference person = website.ERP5Site_getAuthenticatedMemberPersonValue(kw['reference']) @@ -244,6 +237,21 @@ Hé Hé Hé!""", page.asText().strip()) user = uf.getUserById( kw['reference']) self.assertEquals(str(user), kw['reference']) self.assertEquals(1, user.has_role(('Member', 'Authenticated',))) + self.login(kw['reference']) + self.assertEquals(kw['reference'], str(self.portal.portal_membership.getAuthenticatedMember())) + + # test redirection to person oobject + path = website.absolute_url_path() + '/WebSite_redirectToUserView' + response = self.publish(path, '%s:%s' %(kw['reference'], kw['password'])) + self.assertTrue(person.getRelativeUrl() in response.getHeader("Location")) + + # test redirecting to new Person preference + path = website.absolute_url_path() + '/WebSite_redirectToUserPreference' + response = self.publish(path, '%s:%s' %(kw['reference'], kw['password'])) + self.assertTrue('portal_preferences' in response.getHeader("Location")) + # one preference should be created for user + self.assertEquals(1, self.portal.portal_catalog.countResults(**{'portal_type': 'Preference', + 'owner': kw['reference']})[0][0]) def test_04_WebPageTranslation(self): """ @@ -337,13 +345,11 @@ Hé Hé Hé!""", page.asText().strip()) reference='NXD-DDP', publication_section_list=publication_section_category_id_list[:1]) websection.setAggregateValue(web_page_en) - transaction.commit() - self.tic() + self.stepTic() self.assertEqual(None, websection.getDefaultDocumentValue()) # publish it web_page_en.publish() - transaction.commit() - self.tic() + self.stepTic() self.assertEqual(web_page_en, websection.getDefaultDocumentValue()) # and make sure that the base meta tag which is generated # uses the web section rather than the portal @@ -376,13 +382,11 @@ Hé Hé Hé!""", page.asText().strip()) reference='NXD-DDP-Site', publication_section_list=publication_section_category_id_list[:1]) website.setAggregateValue(web_page_en) - transaction.commit() - self.tic() + self.stepTic() self.assertEqual(None, website.getDefaultDocumentValue()) # publish it web_page_en.publish() - transaction.commit() - self.tic() + self.stepTic() self.assertEqual(web_page_en, website.getDefaultDocumentValue()) # and make sure that the base meta tag which is generated # uses the web site rather than the portal @@ -450,20 +454,17 @@ Hé Hé Hé!""", page.asText().strip()) publication_section_list=publication_section_category_id_list[:1]) web_page.edit(**property_dict[key]) - transaction.commit() - self.tic() + self.stepTic() web_page_list.append(web_page) - transaction.commit() - self.tic() + self.stepTic() # in draft state, no documents should belong to this Web Section self.assertEqual(0, len(websection.getDocumentValueList())) # when published, all web pages should belong to it for web_page in web_page_list: web_page.publish() - transaction.commit() - self.tic() + self.stepTic() # Test for limit parameter self.assertEqual(2, len(websection.getDocumentValueList(limit=2))) @@ -625,8 +626,7 @@ Hé Hé Hé!""", page.asText().strip()) publication_section.newContent(portal_type='Category', id='my_test_category', title='Test') - transaction.commit() - self.tic() + self.stepTic() website = self.setupWebSite() websection = self.setupWebSection( @@ -645,8 +645,7 @@ Hé Hé Hé!""", page.asText().strip()) # We need a default document. websection.setAggregateValue(web_page_list[0]) - transaction.commit() - self.tic() + self.stepTic() # Obtain documens in various ways. default_document = websection.getDefaultDocumentValue() @@ -676,8 +675,7 @@ Hé Hé Hé!""", page.asText().strip()) # First, make sure that we use the default skin selection. portal.changeSkin(ps.getDefaultSkin()) - transaction.commit() - self.tic() + self.stepTic() # Make some skin stuff. if ps._getOb('test_erp5_web', None) is not None: @@ -702,8 +700,7 @@ Hé Hé Hé!""", page.asText().strip()) 'WebSite_test_13_WebSiteSkinSelection', '', 'return "bar"') - transaction.commit() - self.tic() + self.stepTic() path = website.absolute_url_path() + '/WebSite_test_13_WebSiteSkinSelection' request = portal.REQUEST @@ -714,8 +711,7 @@ Hé Hé Hé!""", page.asText().strip()) # With the test skin. website.setSkinSelectionName('Test ERP5 Web') - transaction.commit() - self.tic() + self.stepTic() request['PARENTS'] = [self.app] self.assertEquals(request.traverse(path)(), 'bar') @@ -750,8 +746,7 @@ Hé Hé Hé!""", page.asText().strip()) # Commit transaction def _commit(): portal.portal_caches.clearAllCache() - transaction.commit() - self.tic() + self.stepTic() # By default, as now Web Section is visible, nothing should be returned _commit() @@ -813,8 +808,7 @@ Hé Hé Hé!""", page.asText().strip()) reference='foo', text_content='<b>OK</b>') page.publish() - transaction.commit() - self.tic() + self.stepTic() webpage = self.portal.restrictedTraverse( 'web_site_module/%s/%s' % (website_id, page_ref)) @@ -882,8 +876,7 @@ Hé Hé Hé!""", page.asText().strip()) reference='NXD-Document.Cache', text_content=content) document.publish() - transaction.commit() - self.tic() + self.stepTic() self.assertEquals(document.asText().strip(), 'initial text') # First make sure conversion already exists on the web site @@ -905,8 +898,7 @@ Hé Hé Hé!""", page.asText().strip()) # modified the web_page content document.edit(text_content=new_content) self.assertEquals(document.asText().strip(), 'modified text') - transaction.commit() - self.tic() + self.stepTic() # check the cache doesn't send again the old content # Through the web_site. @@ -945,8 +937,7 @@ Hé Hé Hé!""", page.asText().strip()) reference='NXD-Document.Cache', text_content=content) document.publish() - transaction.commit() - self.tic() + self.stepTic() self.assertEquals(document.asText().strip(), 'initial text') # Make sure document cache keeps converted content even if ID changes @@ -978,8 +969,7 @@ Hé Hé Hé!""", page.asText().strip()) reference='NXD-Document.Cache', text_content=content) document.publish() - transaction.commit() - self.tic() + self.stepTic() self.assertEquals(document.asText().strip(), 'initial text') # Through the web_site. @@ -1000,8 +990,7 @@ Hé Hé Hé!""", page.asText().strip()) self.assertFalse(document.hasConversion(format='txt')) # Make sure cache is regenerated self.assertEquals(web_document.asText().strip(), 'modified text') - transaction.commit() - self.tic() + self.stepTic() # First make sure conversion already exists (since it should # have been generated previously) @@ -1049,8 +1038,7 @@ Hé Hé Hé!""", page.asText().strip()) self.createUserAssignement(user, {}) user = self.createUser('webeditor') self.createUserAssignement(user, {}) - transaction.commit() - self.tic() + self.stepTic() preference_tool = self.getPreferenceTool() isTransitionPossible = self.portal.portal_workflow.isTransitionPossible @@ -1082,8 +1070,7 @@ Hé Hé Hé!""", page.asText().strip()) webeditor_preference.setPreferredHtmlStyleDevelopperMode(False) webeditor_preference.setPreferredHtmlStyleTranslatorMode(True) self.login() - transaction.commit() - self.tic() + self.stepTic() web_site = self.setupWebSite() websection = self.setupWebSection() @@ -1123,8 +1110,7 @@ Hé Hé Hé!""", page.asText().strip()) reference='NXD-Document.Cache', text_content=content) document.publish() - transaction.commit() - self.tic() + self.stepTic() path = website.absolute_url_path() + '/NXD-Document.Cache' # test Different Policy installed by erp5_web # unauthenticated web pages @@ -1190,9 +1176,7 @@ Hé Hé Hé!""", page.asText().strip()) websection = self.setupWebSection() self.assertEquals(websection.getId(), websection.getTitle()) - transaction.commit() - self.tic() - + self.stepTic() response = self.publish('/%s/%s/%s/%s/Base_editAndEditAsWeb' % \ (self.portal.getId(), website.getRelativeUrl(), language, websection.getId()), @@ -1212,8 +1196,7 @@ Hé Hé Hé!""", page.asText().strip()) new_location = response.getHeader('Location') new_location = new_location.split('/', 3)[-1] - transaction.commit() - self.tic() + self.stepTic() response = self.publish(new_location, basic='ERP5TypeTestCase:',) self.assertEquals(HTTP_OK, response.getStatus()) @@ -1221,8 +1204,7 @@ Hé Hé Hé!""", page.asText().strip()) response.getHeader('content-type')) self.assertTrue("Data updated." in response.getBody()) - transaction.commit() - self.tic() + self.stepTic() self.assertEquals('%s_edited' % websection.getId(), websection.getTitle()) self.assertEquals(1, len(self.portal.portal_catalog( @@ -1252,8 +1234,7 @@ Hé Hé Hé!""", page.asText().strip()) self.assertEquals(website.getId(), website.getTitle()) - transaction.commit() - self.tic() + self.stepTic() response = self.publish('/%s/%s/%s/Base_editAndEditAsWeb' % \ (self.portal.getId(), website.getRelativeUrl(), @@ -1274,8 +1255,7 @@ Hé Hé Hé!""", page.asText().strip()) new_location = response.getHeader('Location') new_location = new_location.split('/', 3)[-1] - transaction.commit() - self.tic() + self.stepTic() response = self.publish(new_location, basic='ERP5TypeTestCase:',) self.assertEquals(HTTP_OK, response.getStatus()) @@ -1283,8 +1263,7 @@ Hé Hé Hé!""", page.asText().strip()) response.getHeader('content-type')) self.assertTrue("Data updated." in response.getBody()) - transaction.commit() - self.tic() + self.stepTic() self.assertEquals('%s_edited' % website.getId(), website.getTitle()) self.assertEquals(1, len(self.portal.portal_catalog( -- 2.30.9