Commit 6fd973f0 authored by Jérome Perrin's avatar Jérome Perrin

fixup! core_test: py3

parent 36eb1701
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
# #
############################################################################## ##############################################################################
import io
import unittest import unittest
import os import os
from unittest import skip from unittest import skip
...@@ -1050,14 +1051,12 @@ class TestBase(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -1050,14 +1051,12 @@ class TestBase(ERP5TypeTestCase, ZopeTestCase.Functional):
import Products.ERP5Type import Products.ERP5Type
# tests that members can download files # tests that members can download files
class DummyFile(file): class DummyFile(io.BytesIO):
def __init__(self, filename): filename = 'dummy.txt'
self.filename = os.path.basename(filename) portal = self.portal
file.__init__(self, filename)
portal = self.getPortal()
organisation = portal.organisation_module.newContent(portal_type='Organisation') organisation = portal.organisation_module.newContent(portal_type='Organisation')
file_document = organisation.newContent(portal_type='Embedded File', file_document = organisation.newContent(portal_type='Embedded File',
file=DummyFile(Products.ERP5Type.__file__), file=DummyFile(b"data"),
content_type='text/plain') content_type='text/plain')
# login as a member # login as a member
...@@ -1073,7 +1072,7 @@ class TestBase(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -1073,7 +1072,7 @@ class TestBase(ERP5TypeTestCase, ZopeTestCase.Functional):
self.assertEqual(file_document.getData(), response.body) self.assertEqual(file_document.getData(), response.body)
self.assertEqual('text/plain', self.assertEqual('text/plain',
response.getHeader('content-type').split(';')[0]) response.getHeader('content-type').split(';')[0])
self.assertEqual('attachment; filename="%s"' % os.path.basename(Products.ERP5Type.__file__), self.assertEqual('attachment; filename="dummy.txt"',
response.getHeader('content-disposition')) response.getHeader('content-disposition'))
def test_getTypeBasedMethod(self): def test_getTypeBasedMethod(self):
......
...@@ -26,10 +26,6 @@ ...@@ -26,10 +26,6 @@
# #
############################################################################## ##############################################################################
try:
from ZODB._compat import cPickle
except ImportError: # BBB: ZODB < 4
import six.moves.cPickle
import unittest import unittest
import sys import sys
import mock import mock
...@@ -51,8 +47,11 @@ from AccessControl import Unauthorized ...@@ -51,8 +47,11 @@ from AccessControl import Unauthorized
from AccessControl.ZopeGuards import guarded_getattr, guarded_hasattr from AccessControl.ZopeGuards import guarded_getattr, guarded_hasattr
from Products.ERP5Type.tests.utils import createZODBPythonScript from Products.ERP5Type.tests.utils import createZODBPythonScript
from Products.ERP5Type.tests.utils import removeZODBPythonScript from Products.ERP5Type.tests.utils import removeZODBPythonScript
from Products.ERP5Type import IS_ZOPE2, Permissions from Products.ERP5Type import Permissions
from DateTime import DateTime from DateTime import DateTime
from zodbpickle.pickle import PicklingError
import six
class PropertySheetTestCase(ERP5TypeTestCase): class PropertySheetTestCase(ERP5TypeTestCase):
"""Base test case class for property sheets tests. """Base test case class for property sheets tests.
...@@ -330,7 +329,7 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor): ...@@ -330,7 +329,7 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
portal.person_module._setObject(o.getId(), aq_base(o)) portal.person_module._setObject(o.getId(), aq_base(o))
try: try:
self.commit() self.commit()
except six.moves.cPickle.PicklingError: except PicklingError:
self.abort() self.abort()
else: else:
self.fail("No exception raised when storing explicitly a temp object" self.fail("No exception raised when storing explicitly a temp object"
...@@ -3313,39 +3312,9 @@ def test_suite(): ...@@ -3313,39 +3312,9 @@ def test_suite():
add_tests(suite, ZPublisher.tests.testHTTPRangeSupport) add_tests(suite, ZPublisher.tests.testHTTPRangeSupport)
import ZPublisher.tests.testHTTPRequest import ZPublisher.tests.testHTTPRequest
if IS_ZOPE2: # BBB Zope2
# ERP5 processes requests as utf-8 by default, but we adjust this test assuming that
# default is iso-8859-15
def forceISO885915DefaultRequestCharset(method):
def wrapped(self):
from ZPublisher import HTTPRequest as module
old_encoding = module.default_encoding
module.default_encoding = 'iso-8859-15'
try:
return method(self)
finally:
module.default_encoding = old_encoding
return wrapped
HTTPRequestTests = ZPublisher.tests.testHTTPRequest.HTTPRequestTests
for e in dir(HTTPRequestTests):
if e.startswith('test_'):
setattr(HTTPRequestTests, e, forceISO885915DefaultRequestCharset(getattr(HTTPRequestTests, e)))
add_tests(suite, ZPublisher.tests.testHTTPRequest) add_tests(suite, ZPublisher.tests.testHTTPRequest)
import ZPublisher.tests.testHTTPResponse import ZPublisher.tests.testHTTPResponse
if IS_ZOPE2: # BBB Zope2
# ERP5 forces utf-8 responses by default, but we adjust these tests so that they run
# with iso-8859-15 as default response charset
def forceISO885915DefaultResponseCharset(method):
def wrapped(self):
# here we can use this utility method which clean up at teardown
self._setDefaultEncoding('iso-8859-15')
return method(self)
return wrapped
HTTPResponseTests = ZPublisher.tests.testHTTPResponse.HTTPResponseTests
for e in dir(HTTPResponseTests):
if e.startswith('test_'):
setattr(HTTPResponseTests, e, forceISO885915DefaultResponseCharset(getattr(HTTPResponseTests, e)))
add_tests(suite, ZPublisher.tests.testHTTPResponse) add_tests(suite, ZPublisher.tests.testHTTPResponse)
import ZPublisher.tests.testIterators import ZPublisher.tests.testIterators
...@@ -3354,17 +3323,12 @@ def test_suite(): ...@@ -3354,17 +3323,12 @@ def test_suite():
import ZPublisher.tests.testPostTraversal import ZPublisher.tests.testPostTraversal
add_tests(suite, ZPublisher.tests.testPostTraversal) add_tests(suite, ZPublisher.tests.testPostTraversal)
if IS_ZOPE2: # BBB Zope2
import ZPublisher.tests.testPublish # pylint:disable=no-name-in-module,import-error import ZPublisher.tests.testPublish # pylint:disable=no-name-in-module,import-error
add_tests(suite, ZPublisher.tests.testPublish) add_tests(suite, ZPublisher.tests.testPublish)
import ZPublisher.tests.test_Converters import ZPublisher.tests.test_Converters
add_tests(suite, ZPublisher.tests.test_Converters) add_tests(suite, ZPublisher.tests.test_Converters)
if IS_ZOPE2: # BBB Zope2
# XXX don't run test_WSGIPublisher for now because too many failures
pass
else:
import ZPublisher.tests.test_WSGIPublisher import ZPublisher.tests.test_WSGIPublisher
# TestLoadApp tests are confused because running as a live test interfere with # TestLoadApp tests are confused because running as a live test interfere with
# transaction system. Aborting the transaction at beginning of test seems OK. # transaction system. Aborting the transaction at beginning of test seems OK.
...@@ -3378,17 +3342,16 @@ def test_suite(): ...@@ -3378,17 +3342,16 @@ def test_suite():
import ZPublisher.tests.test_mapply import ZPublisher.tests.test_mapply
add_tests(suite, ZPublisher.tests.test_mapply) add_tests(suite, ZPublisher.tests.test_mapply)
if IS_ZOPE2: # BBB Zope2
import ZPublisher.tests.testpubevents # pylint:disable=no-name-in-module,import-error
add_tests(suite, ZPublisher.tests.testpubevents)
else:
import ZPublisher.tests.test_pubevents import ZPublisher.tests.test_pubevents
add_tests(suite, ZPublisher.tests.test_pubevents) add_tests(suite, ZPublisher.tests.test_pubevents)
if IS_ZOPE2: # BBB Zope2
pass
else:
import ZPublisher.tests.test_utils import ZPublisher.tests.test_utils
if six.PY3:
# "fix_properties" does not work with ERP5Type patched properties
expectedFailure(ZPublisher.tests.test_utils.FixPropertiesTests.test_ulines)
expectedFailure(ZPublisher.tests.test_utils.FixPropertiesTests.test_ustring)
expectedFailure(ZPublisher.tests.test_utils.FixPropertiesTests.test_utext)
expectedFailure(ZPublisher.tests.test_utils.FixPropertiesTests.test_utokens)
add_tests(suite, ZPublisher.tests.test_utils) add_tests(suite, ZPublisher.tests.test_utils)
import ZPublisher.tests.test_xmlrpc import ZPublisher.tests.test_xmlrpc
......
...@@ -129,7 +129,7 @@ class TestQueryModule(ERP5TypeTestCase): ...@@ -129,7 +129,7 @@ class TestQueryModule(ERP5TypeTestCase):
mfrom, mto, messageText = last_message mfrom, mto, messageText = last_message
self.assertEqual('owner_user@example.invalid', mfrom) self.assertEqual('owner_user@example.invalid', mfrom)
self.assertEqual(['question_user@example.invalid'], mto) self.assertEqual(['question_user@example.invalid'], mto)
self.assertTrue('Query' in messageText, messageText) self.assertIn(b'Query', messageText)
def test_suite(): def test_suite():
......
...@@ -26,11 +26,7 @@ ...@@ -26,11 +26,7 @@
# #
############################################################################## ##############################################################################
try: from zodbpickle.pickle import PicklingError
from ZODB._compat import cPickle
PicklingError = cPickle.PicklingError
except ImportError: # BBB: ZODB < 4
from six.moves.cPickle import PicklingError
from Acquisition import aq_base from Acquisition import aq_base
from Products.ERP5Type.Accessor.Constant import PropertyGetter as \ from Products.ERP5Type.Accessor.Constant import PropertyGetter as \
PropertyConstantGetter PropertyConstantGetter
......
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