forked from mtusi2026/mtusi2026lab5
45 lines
1.9 KiB
Python
45 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
"""queued → processing → ready через остановку worker’а."""
|
|
import time, sys
|
|
from pathlib import Path
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
from tests.client import Client, check
|
|
from student_tests.common import upload, wait_status, docker, ok, fail
|
|
|
|
def main():
|
|
c = Client()
|
|
a, b, e, ch = c.bootstrap()
|
|
content = Path('tests/fixtures/sample.png').read_bytes()
|
|
|
|
docker('pause', 'worker')
|
|
try:
|
|
att = upload(c, a, ch, content)
|
|
check(att['status'] == 'queued', 'expected queued after upload')
|
|
ok('upload -> queued')
|
|
# Не должно перейти в processing, пока worker на паузе.
|
|
time.sleep(3)
|
|
att = c.call('GET', '/api/v1/attachments/' + att['id'], actor=a, schema='Attachment')['json']
|
|
check(att['status'] == 'queued', 'worker paused but status changed to %s' % att['status'])
|
|
ok('status stays queued while worker paused')
|
|
finally:
|
|
docker('unpause', 'worker')
|
|
|
|
att = wait_status(c, a, att['id'], 'ready', seconds=90)
|
|
names = {v['name'] for v in att['variants']}
|
|
# original в variants[] нет по контракту OpenAPI — он в object_key/оригинальном файле.
|
|
check(names == {'thumbnail', 'crop', 'optimized'},
|
|
'variants mismatch: %s' % names)
|
|
ok('ready with thumbnail/crop/optimized (original available via ?variant=original)')
|
|
|
|
# original доступен отдельно — проверим, что эндпоинт отвечает 200.
|
|
r = c.call('GET',
|
|
'/api/v1/attachments/' + att['id'] + '/content?variant=original',
|
|
200, actor=a)
|
|
check(len(r['bytes']) > 0, 'original empty')
|
|
ok('original served via ?variant=original (%d bytes)' % len(r['bytes']))
|
|
|
|
if __name__ == '__main__':
|
|
try:
|
|
main()
|
|
except Exception as exc:
|
|
fail(str(exc)) |