Commit 1595f4e4 authored by Jérome Perrin's avatar Jérome Perrin

test: adjust self.publish() tests for Zope4

self.publish() had a bug regarding status code for empty responses on
Zope2 and that bug was fixed in Zope4, this adjust the code to support
both versions.
parent 488306a5
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
from cStringIO import StringIO from cStringIO import StringIO
import binascii import binascii
from httplib import NO_CONTENT
import msgpack import msgpack
import numpy as np import numpy as np
import string import string
...@@ -36,6 +37,14 @@ from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase ...@@ -36,6 +37,14 @@ from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.utils import createZODBPythonScript, removeZODBPythonScript from Products.ERP5Type.tests.utils import createZODBPythonScript, removeZODBPythonScript
from wendelin.bigarray.array_zodb import ZBigArray from wendelin.bigarray.array_zodb import ZBigArray
from App.version_txt import getZopeVersion
if getZopeVersion() < (4, ): # BBB Zope2
# Zope set http status code 204 for empty response, but
# on Zope 2 this is not correctly reflected in ERP5TypeTestCase.publish,
# for such responses the status is set to 200 (but for "real" requests
# it is set to 204, this only affected the testing)
NO_CONTENT = 200
def getRandomString(): def getRandomString():
return 'test_%s' %''.join([random.choice(string.ascii_letters + string.digits) \ return 'test_%s' %''.join([random.choice(string.ascii_letters + string.digits) \
...@@ -97,12 +106,7 @@ class Test(ERP5TypeTestCase): ...@@ -97,12 +106,7 @@ class Test(ERP5TypeTestCase):
publish_kw = dict(user='ERP5TypeTestCase', env=env, publish_kw = dict(user='ERP5TypeTestCase', env=env,
request_method='POST', stdin=StringIO(body)) request_method='POST', stdin=StringIO(body))
response = self.publish(path, **publish_kw) response = self.publish(path, **publish_kw)
# Due to inconsistencies in the Zope framework, self.assertEqual(NO_CONTENT, response.getStatus())
# a normal instance returns 204. As explained at
# http://blog.ploeh.dk/2013/04/30/rest-lesson-learned-avoid-204-responses/
# turning 200 into 204 automatically when the body is empty is questionable.
self.assertEqual(200, response.getStatus())
# at every ingestion if no specialised Data Ingestion exists it is created # at every ingestion if no specialised Data Ingestion exists it is created
# thus it is needed to wait for server side activities to be processed # thus it is needed to wait for server side activities to be processed
self.tic() self.tic()
...@@ -388,7 +392,7 @@ class Test(ERP5TypeTestCase): ...@@ -388,7 +392,7 @@ class Test(ERP5TypeTestCase):
request_method='POST', stdin=StringIO(body)) request_method='POST', stdin=StringIO(body))
response = self.publish(path, **publish_kw) response = self.publish(path, **publish_kw)
self.assertEqual(200, response.getStatus()) self.assertEqual(NO_CONTENT, response.getStatus())
self.tic() self.tic()
......
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