Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more select API e2e tests #163

Merged
merged 3 commits into from
May 29, 2019
Merged

add more select API e2e tests #163

merged 3 commits into from
May 29, 2019

Conversation

qixu001
Copy link
Contributor

@qixu001 qixu001 commented Mar 4, 2019

No description provided.

@coveralls
Copy link

coveralls commented Mar 4, 2019

Coverage Status

Coverage decreased (-32.1%) to 63.57% when pulling 7e29fab on qixu001:master into 4b1d079 on aliyun:master.

oss2/api.py Outdated
:return: file-like object

:raises: 如果文件不存在,则抛出 :class:`NoSuchKey <oss2.exceptions.NoSuchKey>` ;还可能抛出其他异常
"""
headers = http.CaseInsensitiveDict()
rangeSelect = False
if (headers is None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前的代码中 if 条件判断 没有 括号,这里建议保持风格一致

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

oss2/api.py Outdated
if("Range" in headers):
rangeSelect = True

if (rangeSelect == True and (select_params is None or ('AllowQuotedRecordDelimiter' not in select_params or select_params['AllowQuotedRecordDelimiter'] != False))):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的条件判断是否能通过换行等方式更清晰的展示
另,'AllowQuotedRecordDelimiter' 这个 key 是大小写敏感吗?(从代码里看,是大小写敏感的)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

大小写敏感的,这里的参数会用在Body的XML里,XML是大小写敏感的。为了让用户用起来更舒服,我打算加一个常量类,预定义这些参数名称。

@@ -405,5 +406,32 @@ def test_create_json_meta_with_params2(self, do_request):
except SelectOperationClientError:
print("expected error")

@patch('oss2.Session.do_request')
def test_range_select(self, do_request):
headers = {'Range':[0,9]}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里range的表示 和 上面的 bytes0-1 这种是 兼容的吧?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我把select_object接口改成和get_object一样了,不用header表示range

oss2/api.py Outdated
headers = http.CaseInsensitiveDict()
else:
if("Range" in headers):
rangeSelect = True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是否需要再次 调用 http.CaseInsensitiveDict 以保持统一

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,可以的

@@ -320,7 +323,27 @@ def test_select_csv_object_none_range(self):
content += chunk

self.assertTrue(len(content) > 0)


def test_create_csv_object_meta_invalid_request(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是否能添加个 json 的用例

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个在test_select_json_object.py里有的。test_create_json_meta_with_invalid_parameter, test_create_json_meta_with_invalid_parameter2

@@ -355,11 +376,24 @@ def test_select_csv_object_with_skip_partial_data(self):
try:
for chunk in result:
content += chunk
self.assertFalse("expected error did not occur")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的try 是不是 应该 把 select_object 的调用 包括进来?
另,select_params 的 SkipPartialDataRecord key是 bool 还是 string?或者说 这个用例就是用来测试 string类型的参数的?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里bool和string都是支持的,因为转成XML后都一样了,客户端代码里没有去做判断。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里select_object和put_object一样是不期待有异常抛出的,所以没有放在try里。

content = "test\nabc\n"
self.bucket.put_object(key, content.encode('utf-8'))
select_params = {'AllowQuotedRecordDelimiter':False}
headers = {'Range':'bytes=0-1'}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前 GetObject 接口header中的range是个 数组,表示 start end,现在的select_object接口是否仍然这么做?

headers = {'Range':'bytes=0-1'}
try:
self.bucket.select_object(key, "select * from ossobject", None, None, headers)
self.assertFalse()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里 assertFalse 没有参数?

@@ -50,7 +54,7 @@ def test_select_json_object(self, testCase, sql, input_format):
testCase.assertEqual(result.status, 206, result.request_id)
testCase.assertTrue(len(content) > 0)

if 'SplitRange' not in input_format and 'LineRange' not in input_format:
if 'SplitRange' not in input_format and 'LineRange' not in input_format and not key.endswith('.gz'):
Copy link
Collaborator

@coderall coderall Apr 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里判断 CompressionType是不是好一点?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.

@@ -639,7 +643,8 @@ def get_object(self, key,

def select_object(self, key, sql,
progress_callback=None,
select_params=None
select_params=None,
byte_range=None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是不是考虑再加个header参数,方便后面功能或者头信息的扩展

@coderall coderall merged commit f193666 into aliyun:master May 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants