Commit d0ae2120 authored by Tatuya Kamada's avatar Tatuya Kamada

AccessTab: Fix an accesstab front page caching problem.

Fix a problem that access-tab-front-page wrongly caching old page, for example,
even if a user switching to use 'https' from 'http', old 'http' links are
remaining at the front page.

That was because the key of the CachingMethod which was used for caching the
page was ('user' and 'language').
Now the caching key is ('user', 'language' and 'site_url').
parent 4c84972e
......@@ -192,8 +192,11 @@ def getModuleActionInformationDict(**kw):\n
getModuleActionInformationDict = CachingMethod(getModuleActionInformationDict,\n
id=\'ERP5Site_getModuleActionInformationDict\',\n
cache_factory=\'erp5_ui_long\')\n
\n
# those parameters are only used for the caching key\n
return getModuleActionInformationDict(\n
user = context.portal_membership.getAuthenticatedMember().getId(), \\\n
user = context.portal_membership.getAuthenticatedMember().getId(),\n
server_url = context.REQUEST.SERVER_URL,\n
language = context.Localizer.get_selected_language())\n
</string> </value>
</item>
......
1110
\ No newline at end of file
1111
\ No newline at end of file
##############################################################################
#
# Copyright (c) 2013 Nexedi KK and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import unittest
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
class TestAccessTab(ERP5TypeTestCase):
def getTitle(self):
return "Access Tab Test"
def getBusinessTemplateList(self):
""" return business template list """
return ('erp5_base',)
def afterSetUp(self):
""" AfterSetup """
self.addPreferenceForAccessTab()
self.configureBusinessApplication()
self.tic()
def addPreferenceForAccessTab(self):
""" Add a preference for access tab """
preference_tool = self.portal.portal_preferences
preference = getattr(preference_tool, "access_tab_test_preference", None)
if preference is None:
preference = preference_tool.newContent(id="access_tab_test_preference",
portal_type="Preference")
preference.setPreferredHtmlStyleAccessTab(True)
if preference.getPreferenceState() != "enabled":
preference.enable()
def configureBusinessApplication(self):
""" Configure business_application category on module property.
This is mandatory for access_tab."""
business_application = self.portal.portal_categories.business_application
base = getattr(business_application, 'base', None)
if base is None:
base = self.portal.portal_categories.business_application.newContent(
portal_type='Category',
id='base',
title='base')
self.portal.organisation_module.setBusinessApplicationValue(base)
self.portal.person_module.setBusinessApplicationValue(base)
self.tic()
def enableAccessTab(self):
""" make enable access tab """
portal = self.portal
preference = portal.portal_preferences.access_tab_test_preference
preference.setPreferredHtmlStyleAccessTab(True)
self.tic()
def checkSelectedTabDict(self):
""" Check a script which is used in access tab view """
tab_info = self.portal.ERP5Site_getSelectedTab()
expected_tab_info = {'title': 'Browse',
'renderer': 'ERP5Site_renderViewActionList',
'id': 'browse_tab',
'icon': 'tab_icon/list.png'}
self.assertEquals(tab_info, expected_tab_info)
def checkStatusDict(self):
""" Check a script which is used in access tab view """
status_dict = self.portal.ERP5Site_getConfiguredStatusDict()
expected_status_dict = {'express_mode': 'support_disabled',
'dms_mode': False,
'basic_mode': True}
self.assertEquals(status_dict, expected_status_dict)
def checkInformationDictBasic(self):
""" Check a script which is used in the main part in access tab view """
portal = self.portal
info_dict = portal.ERP5Site_getCategorizedModuleActionInformationDict()
view_list = info_dict['view']
self.assertEquals(len(view_list), 1)
self.assertEquals(len(view_list[0]), 2)
base = view_list[0]
(label, menu_list) = base
self.assertEquals(label, 'base')
self.assertEquals(len(menu_list), 2)
organisation_menu = menu_list[0]
person_menu = menu_list[1]
self.assertEquals(len(organisation_menu), 2)
self.assertEquals(type(organisation_menu), tuple)
self.assertEquals(len(person_menu), 2)
self.assertEquals(type(person_menu), tuple)
(organisation_label, organisation_url) = organisation_menu
(person_label, person_url) = person_menu
self.assertEquals(organisation_label, 'Organisations')
self.assertEquals(person_label, 'Persons')
def addCurrencyModuleIntoAccessTab(self):
""" add currency module into access tab page so that we can
recognise existing cache is not used """
base = self.portal.portal_categories.business_application.base
self.portal.currency_module.setBusinessApplicationValue(base)
self.tic()
def checkInformationDictAfterSwitchingServerUrl(self):
""" Check a script which is used in the main part in access tab view """
# simulate a https access with '127.0.0.1' address
request=self.portal.REQUEST
request.setServerURL(protocol='https', hostname='127.0.0.1')
portal = self.getPortal()
# make sure that existing cache is not used because the server_url is
# different when the view is cached.
info_dict = portal.ERP5Site_getCategorizedModuleActionInformationDict()
view_list = info_dict['view']
self.assertEquals(len(view_list), 1)
self.assertEquals(len(view_list[0]), 2)
base = view_list[0]
(label, menu_list) = base
self.assertEquals(len(menu_list), 3)
currency_menu = menu_list[0]
self.assertEquals(len(currency_menu), 2)
self.assertEquals(type(currency_menu), tuple)
(currency_label, currency_url) = currency_menu
self.assertEquals(currency_label, 'Currencies')
self.assertTrue('https' in currency_url[0][1])
def test_01_testAccessTab(self):
"""
Test the basic functionalities of Access Tab.
[setup]
- enable accesstab flag on a preference
- configure 'business_application' category at module property
[test]
- check access tab is usable
"""
self.enableAccessTab()
self.checkSelectedTabDict()
self.checkStatusDict()
self.checkInformationDictBasic()
def test_02_testAccessTabCacheAfterSwitchingUrl(self):
"""
Check that when access url is changed, exisiting access tab cache is
not used.
The view is cached with CachingMethod by (user, language and server_url)
"""
self.enableAccessTab()
self.checkInformationDictBasic()
self.addCurrencyModuleIntoAccessTab()
self.checkInformationDictAfterSwitchingServerUrl()
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestAccessTab))
return suite
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