Commit 35447649 authored by Ekaterina's avatar Ekaterina

erp5_wendelin: fix byte size of data array and add test

parent f27a9a0b
......@@ -179,7 +179,6 @@ class DataArray(BigFile):
ranges = HTTPRangeSupport.parseRange(range)
array = self.getArray()
factor = array.nbytes / array.shape[0]
if if_range is not None:
# Only send ranges if the data isn't modified, otherwise send
......@@ -240,9 +239,10 @@ class DataArray(BigFile):
RESPONSE.setHeader('Content-Range',
'bytes %d-%d/%d' % (start, end - 1, self.getSize()))
RESPONSE.setStatus(206) # Partial content
# convert ranges from bytes to array indices
RESPONSE.write(array[start/factor:end/factor].tobytes())
self.log(str((start, end)))
# convert array to bytes
data = array[:].view('<b').reshape((-1,))[start:end].tobytes()
RESPONSE.setBody(data, lock=True)
else:
boundary = choose_boundary()
......@@ -260,6 +260,7 @@ class DataArray(BigFile):
# will only accept x-byteranges.
draftprefix = (request_range is not None) and 'x-' or ''
self.log(size)
RESPONSE.setHeader('Content-Length', size)
RESPONSE.setHeader('Accept-Ranges', 'bytes')
RESPONSE.setHeader('Last-Modified', rfc1123_date(self._data_mtime()))
......@@ -267,17 +268,19 @@ class DataArray(BigFile):
'multipart/%sbyteranges; boundary=%s' % (
draftprefix, boundary))
RESPONSE.setStatus(206) # Partial content
data = ''
for start, end in ranges:
RESPONSE.write('\r\n--%s\r\n' % boundary)
RESPONSE.write('Content-Type: %s\r\n' %
self.content_type)
RESPONSE.write(
'Content-Range: bytes %d-%d/%d\r\n\r\n' % (
start, end - 1, self.getSize()))
# convert ranges from bytes to array indices
RESPONSE.write(array[start/factor:end/factor].tobytes())
RESPONSE.write('\r\n--%s--\r\n' % boundary)
data = '{data}\r\n--{boundary}\r\n'\
'Content-Type: {content_type}\r\n'\
'Content-Range: bytes {start:d}-{end:d}/{size:d}\r\n\r\n'\
'{array}'.format(data=data,
boundary=boundary,
content_type=self.content_type,
start=start,
end=end-1,
size=self.getSize(),
array=array[:].view('<b').reshape((-1,))[start:end].tobytes())
data = '{}\r\n--{}--\r\n'.format(data, boundary)
RESPONSE.setBody(data, lock=True)
return True
\ No newline at end of file
......@@ -46,9 +46,9 @@
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple>
<string>W:133, 42: Redefining built-in \'format\' (redefined-builtin)</string>
<string>W:165, 4: Redefining built-in \'range\' (redefined-builtin)</string>
<string>W:192, 10: No exception type(s) specified (bare-except)</string>
<string>W:139, 42: Redefining built-in \'format\' (redefined-builtin)</string>
<string>W:171, 4: Redefining built-in \'range\' (redefined-builtin)</string>
<string>W:197, 10: No exception type(s) specified (bare-except)</string>
</tuple>
</value>
</item>
......@@ -104,11 +104,13 @@
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -121,7 +123,9 @@
</item>
</dictionary>
</list>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -33,6 +33,10 @@ import numpy as np
import string
import random
import urllib
import requests
import StringIO as st
from Products.ERP5Type.Log import log
def getRandomString():
return 'test_%s' %''.join([random.choice(string.ascii_letters + string.digits) \
......@@ -230,6 +234,18 @@ class Test(ERP5TypeTestCase):
np.array_equal(data_array.getArraySlice(0,100), \
new_array[:100]))
# test get array by request if exists and chech that length is correct
data_arrays = self.portal.data_array_module.objectValues()
spectrum_array = [o for o in data_arrays if o.getTitle() == 'pydata-spectrum2']
if len(spectrum_array) == 1:
spectrum_array_id = spectrum_array[0].getId()
headers = {'Range': 'bytes=0-'}
url = 'https://softinst127199.host.vifib.net/erp5/web_site_module/pydata_runner/hateoas/data_array_module/' + spectrum_array_id
response = requests.get(url, auth=('zope', 'aybvtnkf'), headers=headers)
response_string = st.StringIO()
response_string.write(response.content)
self.assertEquals(response_string.len, spectrum_array[0].getSize())
def test_04_DataBucket(self):
"""
Test data bucket
......
......@@ -46,7 +46,8 @@
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple>
<string>W: 63, 35: Unused variable \'data_product\' (unused-variable)</string>
<string>W: 67, 35: Unused variable \'data_product\' (unused-variable)</string>
<string>W: 39, 0: Unused log imported from Products.ERP5Type.Log (unused-import)</string>
</tuple>
</value>
</item>
......@@ -102,11 +103,13 @@
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -119,7 +122,9 @@
</item>
</dictionary>
</list>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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