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

erp5_core_test: pylint for py3

parent a9a4aec0
......@@ -113,7 +113,7 @@ class TestAlarm(AlarmTestCase):
finally:
self.portal.portal_activities.manageClearActivities(keep=0)
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
self.getPortal().portal_skins[skin_folder_id][sense_method_id].ZPythonScript_edit('*args,**kw', 'context.newActiveProcess()')
alarm.activeSense()
......
......@@ -642,7 +642,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
self.assertEqual(['5'],folder_object_list)
if six.PY2:
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)
def test_Collation(self):
......@@ -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) )
self.assertNotEqual(len(result), 0, 'No line found for allowedRolesAndUsers=%r and uid=%i' % (line['allowedRolesAndUsers'], uid))
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*
# be found when searching for his other 'Whatever' role.
......@@ -4067,7 +4067,8 @@ VALUES
def doSomething(self, message_list):
r = []
for m in message_list:
m.result = r.append(m.object.getPath())
r.append(m.object.getPath())
m.result = None
r.sort()
group_method_call_list.append(r)
self.portal.portal_activities.__class__.doSomething = doSomething
......
......@@ -42,59 +42,59 @@ from Products.ERP5Type.tests.utils import DummyTranslationService
from zExceptions import Unauthorized
if 1: # BBB
# Zope 2.12, simulate setting the globalTranslationService with
# zope.i18n utilities
import zope.interface
import zope.component
import Acquisition
global_translation_service = None
from zope.i18n.interfaces import ITranslationDomain, \
IFallbackTranslationDomainFactory
@zope.interface.implementer(ITranslationDomain)
@zope.interface.provider(IFallbackTranslationDomainFactory)
class DummyTranslationDomainFallback(object):
def __init__(self, domain):
self.domain = domain
def translate(self, msgid, mapping=None, *args, **kw):
return global_translation_service.translate(self.domain, msgid, mapping,
*args, **kw)
def setGlobalTranslationService(translation_service):
global global_translation_service # pylint:disable=global-statement
global_translation_service = translation_service
zope.component.provideUtility(DummyTranslationDomainFallback,
provides=IFallbackTranslationDomainFactory)
# 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
# class
sm = zope.component.getSiteManager()
portal = Acquisition.aq_parent(sm)
from zope.interface.interfaces import ComponentLookupError
try:
ui_domain = sm.getUtility(ITranslationDomain, name='ui')
except ComponentLookupError:
pass
else:
# store in a list to avoid acquisition wrapping
portal._save_ui_domain = [ui_domain]
sm.unregisterUtility(provided=ITranslationDomain, name='ui')
def unregister_translation_domain_fallback():
from zope.component.globalregistry import base
base.unregisterUtility(DummyTranslationDomainFallback)
sm = zope.component.getSiteManager()
portal = Acquisition.aq_parent(sm)
ui_domain = getattr(portal, '_save_ui_domain', [None]).pop()
if ui_domain is not None:
# aq_base() to remove acquisition wrapping
ui_domain = Acquisition.aq_base(ui_domain)
sm.registerUtility(ui_domain, ITranslationDomain, 'ui')
del portal._save_ui_domain
# Zope 2.12, simulate setting the globalTranslationService with
# zope.i18n utilities
import zope.interface
import zope.component
import Acquisition
global_translation_service = None
from zope.i18n.interfaces import ITranslationDomain, \
IFallbackTranslationDomainFactory
@zope.interface.implementer(ITranslationDomain)
@zope.interface.provider(IFallbackTranslationDomainFactory)
class DummyTranslationDomainFallback(object):
def __init__(self, domain):
self.domain = domain
def translate(self, msgid, mapping=None, *args, **kw):
return global_translation_service.translate(self.domain, msgid, mapping,
*args, **kw)
def setGlobalTranslationService(translation_service):
global global_translation_service # pylint:disable=global-statement
global_translation_service = translation_service
zope.component.provideUtility(DummyTranslationDomainFallback,
provides=IFallbackTranslationDomainFactory)
# 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
# class
sm = zope.component.getSiteManager()
portal = Acquisition.aq_parent(sm)
from zope.interface.interfaces import ComponentLookupError
try:
ui_domain = sm.getUtility(ITranslationDomain, name='ui')
except ComponentLookupError:
pass
else:
# store in a list to avoid acquisition wrapping
portal._save_ui_domain = [ui_domain]
sm.unregisterUtility(provided=ITranslationDomain, name='ui')
def unregister_translation_domain_fallback():
from zope.component.globalregistry import base
base.unregisterUtility(DummyTranslationDomainFallback)
sm = zope.component.getSiteManager()
portal = Acquisition.aq_parent(sm)
ui_domain = getattr(portal, '_save_ui_domain', [None]).pop()
if ui_domain is not None:
# aq_base() to remove acquisition wrapping
ui_domain = Acquisition.aq_base(ui_domain)
sm.registerUtility(ui_domain, ITranslationDomain, 'ui')
del portal._save_ui_domain
HTTP_OK = 200
HTTP_UNAUTHORIZED = 401
......@@ -599,26 +599,27 @@ class TestERP5Core(ERP5TypeTestCase, ZopeTestCase.Functional):
# now let's simulate a site just migrated from Zope 2.8 that's being
# accessed for the first time:
from Products.ERP5 import ERP5Site
if 1: # BBB
setSite()
# Sites from Zope2.8 don't have a site_manager yet.
del self.portal._components
self.assertIsNotNone(ERP5Site._missing_tools_registered)
ERP5Site._missing_tools_registered = None
self.commit()
# check that we can't get any translation utility
self.assertEqual(queryUtility(ITranslationDomain, 'erp5_ui'), None)
# Now simulate first access. Default behaviour from
# ObjectManager is to raise a ComponentLookupError here:
setSite(self.portal)
self.commit()
self.assertIsNotNone(ERP5Site._missing_tools_registered)
# This should have automatically reconstructed the i18n utility
# registrations:
self.assertEqual(queryUtility(ITranslationDomain, 'erp5_ui'),
erp5_ui_catalog)
self.assertEqual(queryUtility(ITranslationDomain, 'ui'), erp5_ui_catalog)
# BBB
setSite()
# Sites from Zope2.8 don't have a site_manager yet.
del self.portal._components
self.assertIsNotNone(ERP5Site._missing_tools_registered)
ERP5Site._missing_tools_registered = None
self.commit()
# check that we can't get any translation utility
self.assertEqual(queryUtility(ITranslationDomain, 'erp5_ui'), None)
# Now simulate first access. Default behaviour from
# ObjectManager is to raise a ComponentLookupError here:
setSite(self.portal)
self.commit()
self.assertIsNotNone(ERP5Site._missing_tools_registered)
# This should have automatically reconstructed the i18n utility
# registrations:
self.assertEqual(queryUtility(ITranslationDomain, 'erp5_ui'),
erp5_ui_catalog)
self.assertEqual(queryUtility(ITranslationDomain, 'ui'), erp5_ui_catalog)
def test_BasicAuthenticateDesactivated(self):
"""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