-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add idle-time fop support and get fop status
- Loading branch information
Showing
8 changed files
with
206 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import pytest | ||
|
||
|
||
from qiniu import PersistentFop, op_save | ||
|
||
|
||
persistent_id = None | ||
|
||
|
||
class TestPersistentFop: | ||
def test_pfop_execute(self, qn_auth): | ||
pfop = PersistentFop(qn_auth, 'testres', 'sdktest') | ||
op = op_save('avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240', 'pythonsdk', 'pfoptest') | ||
ops = [ | ||
op | ||
] | ||
ret, resp = pfop.execute('sintel_trailer.mp4', ops, 1) | ||
assert resp.status_code == 200, resp | ||
assert ret['persistentId'] is not None, resp | ||
global persistent_id | ||
persistent_id = ret['persistentId'] | ||
|
||
def test_pfop_get_status(self, qn_auth): | ||
assert persistent_id is not None | ||
pfop = PersistentFop(qn_auth, 'testres', 'sdktest') | ||
ret, resp = pfop.get_status(persistent_id) | ||
assert resp.status_code == 200, resp | ||
assert ret is not None, resp | ||
|
||
def test_pfop_idle_time_task(self, set_conf_default, qn_auth): | ||
persistence_key = 'python-sdk-pfop-test/test-pfop-by-api' | ||
|
||
key = 'sintel_trailer.mp4' | ||
pfop = PersistentFop(qn_auth, 'testres') | ||
ops = [ | ||
op_save( | ||
op='avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240', | ||
bucket='pythonsdk', | ||
key=persistence_key | ||
) | ||
] | ||
ret, resp = pfop.execute(key, ops, force=1, persistent_type=1) | ||
assert resp.status_code == 200, resp | ||
assert 'persistentId' in ret, resp | ||
|
||
ret, resp = pfop.get_status(ret['persistentId']) | ||
assert resp.status_code == 200, resp | ||
assert ret['type'] == 1, resp | ||
assert ret['creationDate'] is not None, resp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
tests/cases/test_services/test_storage/test_upload_pfop.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import pytest | ||
|
||
import qiniu | ||
|
||
|
||
KB = 1024 | ||
MB = 1024 * KB | ||
GB = 1024 * MB | ||
|
||
|
||
# set a bucket lifecycle manually to delete prefix `test-pfop`! | ||
# or this test will continue to occupy bucket space. | ||
class TestPersistentFopByUpload: | ||
@pytest.mark.parametrize('temp_file', [10 * MB], indirect=True) | ||
@pytest.mark.parametrize('persistent_type', [None, 0, 1]) | ||
def test_pfop_with_upload( | ||
self, | ||
set_conf_default, | ||
qn_auth, | ||
bucket_name, | ||
temp_file, | ||
persistent_type | ||
): | ||
key = 'test-pfop-upload-file' | ||
persistent_key = '_'.join([ | ||
'test-pfop-by-upload', | ||
'type', | ||
str(persistent_type) | ||
]) | ||
persistent_ops = ';'.join([ | ||
qiniu.op_save( | ||
op='avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240', | ||
bucket=bucket_name, | ||
key=persistent_key | ||
) | ||
]) | ||
|
||
upload_policy = { | ||
'persistentOps': persistent_ops | ||
} | ||
|
||
if persistent_type is not None: | ||
upload_policy['persistentType'] = persistent_type | ||
|
||
token = qn_auth.upload_token( | ||
bucket_name, | ||
key, | ||
policy=upload_policy | ||
) | ||
ret, resp = qiniu.put_file( | ||
token, | ||
key, | ||
temp_file.path, | ||
check_crc=True | ||
) | ||
|
||
assert ret is not None, resp | ||
assert ret['key'] == key, resp | ||
assert 'persistentId' in ret, resp | ||
|
||
pfop = qiniu.PersistentFop(qn_auth, bucket_name) | ||
ret, resp = pfop.get_status(ret['persistentId']) | ||
assert resp.status_code == 200, resp | ||
if persistent_type == 1: | ||
assert ret['type'] == 1, resp | ||
assert ret['creationDate'] is not None, resp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters