Commit b8aee3f3 authored by Jérome Perrin's avatar Jérome Perrin

erp5_core_test: pylint for py3

parent 4e5886c9
...@@ -113,7 +113,7 @@ class TestAlarm(AlarmTestCase): ...@@ -113,7 +113,7 @@ class TestAlarm(AlarmTestCase):
finally: finally:
self.portal.portal_activities.manageClearActivities(keep=0) self.portal.portal_activities.manageClearActivities(keep=0)
else: else:
raise Exception('Tic did not raise though activity was supposed to fail') self.fail('Tic did not raise though activity was supposed to fail')
# Make the sense method succeed and leave a trace # Make the sense method succeed and leave a trace
self.getPortal().portal_skins[skin_folder_id][sense_method_id].ZPythonScript_edit('*args,**kw', 'context.newActiveProcess()') self.getPortal().portal_skins[skin_folder_id][sense_method_id].ZPythonScript_edit('*args,**kw', 'context.newActiveProcess()')
alarm.activeSense() alarm.activeSense()
......
...@@ -642,7 +642,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor): ...@@ -642,7 +642,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
self.assertEqual(['5'],folder_object_list) self.assertEqual(['5'],folder_object_list)
if six.PY2: if six.PY2:
folder_object_list = [x.getObject().getId() for x in folder_object_list = [x.getObject().getId() for x in
person_module.searchFolder(title=unicode(title, 'utf-8'))] person_module.searchFolder(title=six.text_type(title, 'utf-8'))]
self.assertEqual(['5'],folder_object_list) self.assertEqual(['5'],folder_object_list)
def test_Collation(self): def test_Collation(self):
...@@ -2167,7 +2167,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor): ...@@ -2167,7 +2167,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
result = query('SELECT * FROM roles_and_users WHERE allowedRolesAndUsers LIKE "%s:%%" AND uid = %i' % (line['allowedRolesAndUsers'], uid) ) result = query('SELECT * FROM roles_and_users WHERE allowedRolesAndUsers LIKE "%s:%%" AND uid = %i' % (line['allowedRolesAndUsers'], uid) )
self.assertNotEqual(len(result), 0, 'No line found for allowedRolesAndUsers=%r and uid=%i' % (line['allowedRolesAndUsers'], uid)) self.assertNotEqual(len(result), 0, 'No line found for allowedRolesAndUsers=%r and uid=%i' % (line['allowedRolesAndUsers'], uid))
else: else:
raise Exception('Malformed allowedRolesAndUsers value: %(allowedRolesAndUsers)r' % line) raise ValueError('Malformed allowedRolesAndUsers value: %(allowedRolesAndUsers)r' % line)
# Check that object that 'bar' can view because of 'Author' role can *not* # Check that object that 'bar' can view because of 'Author' role can *not*
# be found when searching for his other 'Whatever' role. # be found when searching for his other 'Whatever' role.
...@@ -4067,7 +4067,8 @@ VALUES ...@@ -4067,7 +4067,8 @@ VALUES
def doSomething(self, message_list): def doSomething(self, message_list):
r = [] r = []
for m in message_list: for m in message_list:
m.result = r.append(m.object.getPath()) r.append(m.object.getPath())
m.result = None
r.sort() r.sort()
group_method_call_list.append(r) group_method_call_list.append(r)
self.portal.portal_activities.__class__.doSomething = doSomething self.portal.portal_activities.__class__.doSomething = doSomething
......
...@@ -42,59 +42,59 @@ from Products.ERP5Type.tests.utils import DummyTranslationService ...@@ -42,59 +42,59 @@ from Products.ERP5Type.tests.utils import DummyTranslationService
from zExceptions import Unauthorized from zExceptions import Unauthorized
if 1: # BBB # Zope 2.12, simulate setting the globalTranslationService with
# Zope 2.12, simulate setting the globalTranslationService with # zope.i18n utilities
# zope.i18n utilities import zope.interface
import zope.interface import zope.component
import zope.component import Acquisition
import Acquisition
global_translation_service = None
global_translation_service = None
from zope.i18n.interfaces import ITranslationDomain, \
from zope.i18n.interfaces import ITranslationDomain, \ IFallbackTranslationDomainFactory
IFallbackTranslationDomainFactory @zope.interface.implementer(ITranslationDomain)
@zope.interface.implementer(ITranslationDomain) @zope.interface.provider(IFallbackTranslationDomainFactory)
@zope.interface.provider(IFallbackTranslationDomainFactory) class DummyTranslationDomainFallback(object):
class DummyTranslationDomainFallback(object):
def __init__(self, domain):
def __init__(self, domain): self.domain = domain
self.domain = domain
def translate(self, msgid, mapping=None, *args, **kw):
def translate(self, msgid, mapping=None, *args, **kw): return global_translation_service.translate(self.domain, msgid, mapping,
return global_translation_service.translate(self.domain, msgid, mapping, *args, **kw)
*args, **kw)
def setGlobalTranslationService(translation_service):
def setGlobalTranslationService(translation_service): global global_translation_service # pylint:disable=global-statement
global global_translation_service # pylint:disable=global-statement global_translation_service = translation_service
global_translation_service = translation_service zope.component.provideUtility(DummyTranslationDomainFallback,
zope.component.provideUtility(DummyTranslationDomainFallback, provides=IFallbackTranslationDomainFactory)
provides=IFallbackTranslationDomainFactory) # disable translation for the 'ui' domain so it can use the fallback above.
# disable translation for the 'ui' domain so it can use the fallback above. # Save it on a portal attribute since we don't have access to the test
# Save it on a portal attribute since we don't have access to the test # class
# class sm = zope.component.getSiteManager()
sm = zope.component.getSiteManager() portal = Acquisition.aq_parent(sm)
portal = Acquisition.aq_parent(sm) from zope.interface.interfaces import ComponentLookupError
from zope.interface.interfaces import ComponentLookupError try:
try: ui_domain = sm.getUtility(ITranslationDomain, name='ui')
ui_domain = sm.getUtility(ITranslationDomain, name='ui') except ComponentLookupError:
except ComponentLookupError: pass
pass else:
else: # store in a list to avoid acquisition wrapping
# store in a list to avoid acquisition wrapping portal._save_ui_domain = [ui_domain]
portal._save_ui_domain = [ui_domain] sm.unregisterUtility(provided=ITranslationDomain, name='ui')
sm.unregisterUtility(provided=ITranslationDomain, name='ui')
def unregister_translation_domain_fallback():
def unregister_translation_domain_fallback(): from zope.component.globalregistry import base
from zope.component.globalregistry import base base.unregisterUtility(DummyTranslationDomainFallback)
base.unregisterUtility(DummyTranslationDomainFallback) sm = zope.component.getSiteManager()
sm = zope.component.getSiteManager() portal = Acquisition.aq_parent(sm)
portal = Acquisition.aq_parent(sm) ui_domain = getattr(portal, '_save_ui_domain', [None]).pop()
ui_domain = getattr(portal, '_save_ui_domain', [None]).pop() if ui_domain is not None:
if ui_domain is not None: # aq_base() to remove acquisition wrapping
# aq_base() to remove acquisition wrapping ui_domain = Acquisition.aq_base(ui_domain)
ui_domain = Acquisition.aq_base(ui_domain) sm.registerUtility(ui_domain, ITranslationDomain, 'ui')
sm.registerUtility(ui_domain, ITranslationDomain, 'ui') del portal._save_ui_domain
del portal._save_ui_domain
HTTP_OK = 200 HTTP_OK = 200
HTTP_UNAUTHORIZED = 401 HTTP_UNAUTHORIZED = 401
...@@ -599,26 +599,27 @@ class TestERP5Core(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -599,26 +599,27 @@ class TestERP5Core(ERP5TypeTestCase, ZopeTestCase.Functional):
# now let's simulate a site just migrated from Zope 2.8 that's being # now let's simulate a site just migrated from Zope 2.8 that's being
# accessed for the first time: # accessed for the first time:
from Products.ERP5 import ERP5Site from Products.ERP5 import ERP5Site
if 1: # BBB
setSite() # BBB
# Sites from Zope2.8 don't have a site_manager yet. setSite()
del self.portal._components # Sites from Zope2.8 don't have a site_manager yet.
self.assertIsNotNone(ERP5Site._missing_tools_registered) del self.portal._components
ERP5Site._missing_tools_registered = None self.assertIsNotNone(ERP5Site._missing_tools_registered)
self.commit() ERP5Site._missing_tools_registered = None
# check that we can't get any translation utility self.commit()
self.assertEqual(queryUtility(ITranslationDomain, 'erp5_ui'), None) # check that we can't get any translation utility
# Now simulate first access. Default behaviour from self.assertEqual(queryUtility(ITranslationDomain, 'erp5_ui'), None)
# ObjectManager is to raise a ComponentLookupError here: # Now simulate first access. Default behaviour from
# ObjectManager is to raise a ComponentLookupError here:
setSite(self.portal)
self.commit() setSite(self.portal)
self.assertIsNotNone(ERP5Site._missing_tools_registered) self.commit()
# This should have automatically reconstructed the i18n utility self.assertIsNotNone(ERP5Site._missing_tools_registered)
# registrations: # This should have automatically reconstructed the i18n utility
self.assertEqual(queryUtility(ITranslationDomain, 'erp5_ui'), # registrations:
erp5_ui_catalog) self.assertEqual(queryUtility(ITranslationDomain, 'erp5_ui'),
self.assertEqual(queryUtility(ITranslationDomain, 'ui'), erp5_ui_catalog) erp5_ui_catalog)
self.assertEqual(queryUtility(ITranslationDomain, 'ui'), erp5_ui_catalog)
def test_BasicAuthenticateDesactivated(self): def test_BasicAuthenticateDesactivated(self):
"""Make sure Unauthorized error does not lead to Basic auth popup in browser""" """Make sure Unauthorized error does not lead to Basic auth popup in browser"""
......
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