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): ...@@ -179,7 +179,6 @@ class DataArray(BigFile):
ranges = HTTPRangeSupport.parseRange(range) ranges = HTTPRangeSupport.parseRange(range)
array = self.getArray() array = self.getArray()
factor = array.nbytes / array.shape[0]
if if_range is not None: if if_range is not None:
# Only send ranges if the data isn't modified, otherwise send # Only send ranges if the data isn't modified, otherwise send
...@@ -240,9 +239,10 @@ class DataArray(BigFile): ...@@ -240,9 +239,10 @@ class DataArray(BigFile):
RESPONSE.setHeader('Content-Range', RESPONSE.setHeader('Content-Range',
'bytes %d-%d/%d' % (start, end - 1, self.getSize())) 'bytes %d-%d/%d' % (start, end - 1, self.getSize()))
RESPONSE.setStatus(206) # Partial content RESPONSE.setStatus(206) # Partial content
self.log(str((start, end)))
# convert ranges from bytes to array indices # convert array to bytes
RESPONSE.write(array[start/factor:end/factor].tobytes()) data = array[:].view('<b').reshape((-1,))[start:end].tobytes()
RESPONSE.setBody(data, lock=True)
else: else:
boundary = choose_boundary() boundary = choose_boundary()
...@@ -260,6 +260,7 @@ class DataArray(BigFile): ...@@ -260,6 +260,7 @@ class DataArray(BigFile):
# will only accept x-byteranges. # will only accept x-byteranges.
draftprefix = (request_range is not None) and 'x-' or '' draftprefix = (request_range is not None) and 'x-' or ''
self.log(size)
RESPONSE.setHeader('Content-Length', size) RESPONSE.setHeader('Content-Length', size)
RESPONSE.setHeader('Accept-Ranges', 'bytes') RESPONSE.setHeader('Accept-Ranges', 'bytes')
RESPONSE.setHeader('Last-Modified', rfc1123_date(self._data_mtime())) RESPONSE.setHeader('Last-Modified', rfc1123_date(self._data_mtime()))
...@@ -267,17 +268,19 @@ class DataArray(BigFile): ...@@ -267,17 +268,19 @@ class DataArray(BigFile):
'multipart/%sbyteranges; boundary=%s' % ( 'multipart/%sbyteranges; boundary=%s' % (
draftprefix, boundary)) draftprefix, boundary))
RESPONSE.setStatus(206) # Partial content RESPONSE.setStatus(206) # Partial content
data = ''
for start, end in ranges: for start, end in ranges:
RESPONSE.write('\r\n--%s\r\n' % boundary) data = '{data}\r\n--{boundary}\r\n'\
RESPONSE.write('Content-Type: %s\r\n' % 'Content-Type: {content_type}\r\n'\
self.content_type) 'Content-Range: bytes {start:d}-{end:d}/{size:d}\r\n\r\n'\
RESPONSE.write( '{array}'.format(data=data,
'Content-Range: bytes %d-%d/%d\r\n\r\n' % ( boundary=boundary,
start, end - 1, self.getSize())) content_type=self.content_type,
start=start,
# convert ranges from bytes to array indices end=end-1,
RESPONSE.write(array[start/factor:end/factor].tobytes()) size=self.getSize(),
array=array[:].view('<b').reshape((-1,))[start:end].tobytes())
RESPONSE.write('\r\n--%s--\r\n' % boundary)
data = '{}\r\n--{}--\r\n'.format(data, boundary)
RESPONSE.setBody(data, lock=True)
return True return True
\ No newline at end of file
...@@ -46,9 +46,9 @@ ...@@ -46,9 +46,9 @@
<key> <string>text_content_warning_message</string> </key> <key> <string>text_content_warning_message</string> </key>
<value> <value>
<tuple> <tuple>
<string>W:133, 42: Redefining built-in \'format\' (redefined-builtin)</string> <string>W:139, 42: Redefining built-in \'format\' (redefined-builtin)</string>
<string>W:165, 4: Redefining built-in \'range\' (redefined-builtin)</string> <string>W:171, 4: Redefining built-in \'range\' (redefined-builtin)</string>
<string>W:192, 10: No exception type(s) specified (bare-except)</string> <string>W:197, 10: No exception type(s) specified (bare-except)</string>
</tuple> </tuple>
</value> </value>
</item> </item>
...@@ -104,11 +104,13 @@ ...@@ -104,11 +104,13 @@
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -121,7 +123,9 @@ ...@@ -121,7 +123,9 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
</ZopeData> </ZopeData>
...@@ -33,6 +33,10 @@ import numpy as np ...@@ -33,6 +33,10 @@ import numpy as np
import string import string
import random import random
import urllib import urllib
import requests
import StringIO as st
from Products.ERP5Type.Log import log
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) \
...@@ -230,6 +234,18 @@ class Test(ERP5TypeTestCase): ...@@ -230,6 +234,18 @@ class Test(ERP5TypeTestCase):
np.array_equal(data_array.getArraySlice(0,100), \ np.array_equal(data_array.getArraySlice(0,100), \
new_array[: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): def test_04_DataBucket(self):
""" """
Test data bucket Test data bucket
......
...@@ -46,7 +46,8 @@ ...@@ -46,7 +46,8 @@
<key> <string>text_content_warning_message</string> </key> <key> <string>text_content_warning_message</string> </key>
<value> <value>
<tuple> <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> </tuple>
</value> </value>
</item> </item>
...@@ -102,11 +103,13 @@ ...@@ -102,11 +103,13 @@
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -119,7 +122,9 @@ ...@@ -119,7 +122,9 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
</ZopeData> </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