Реализовать асинхронную обработку вложений
This commit is contained in:
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Grade-4 black-box check for every promised image variant."""
|
||||
import hashlib
|
||||
|
||||
from client import Client, arguments, check, run
|
||||
from image_probe import jpeg_size
|
||||
|
||||
|
||||
def main():
|
||||
args = arguments('Verify thumbnail, crop and optimized variants')
|
||||
client = Client(args.base_url, args.ca_file)
|
||||
alice, bob, _eve, chat = client.bootstrap()
|
||||
attachment, original = client.attachment(alice, chat)
|
||||
ready = client.wait_ready(bob, attachment)
|
||||
variants = {item['name']: item for item in ready['variants']}
|
||||
check(set(variants) == {'thumbnail', 'crop', 'optimized'}, 'grade-4 variants missing')
|
||||
expected = {
|
||||
'thumbnail': ('image/jpeg', (256, 160)),
|
||||
'crop': ('image/jpeg', (128, 128)),
|
||||
'optimized': ('image/webp', (320, 200)),
|
||||
}
|
||||
for name, (content_type, dimensions) in expected.items():
|
||||
response = client.call(
|
||||
'GET',
|
||||
f'/api/v1/attachments/{ready["id"]}/content?variant={name}',
|
||||
actor=bob,
|
||||
)
|
||||
metadata = variants[name]
|
||||
check(response['headers'].get_content_type() == content_type, name + ': MIME mismatch')
|
||||
check((metadata['width'], metadata['height']) == dimensions, name + ': metadata dimensions')
|
||||
check(len(response['bytes']) == metadata['size_bytes'], name + ': size mismatch')
|
||||
check(hashlib.sha256(response['bytes']).hexdigest() == metadata['sha256'], name + ': hash mismatch')
|
||||
if content_type == 'image/jpeg':
|
||||
check(jpeg_size(response['bytes']) == dimensions, name + ': actual dimensions')
|
||||
else:
|
||||
check(response['bytes'][:4] == b'RIFF' and response['bytes'][8:12] == b'WEBP', 'optimized is not WebP')
|
||||
downloaded = client.call(
|
||||
'GET', f'/api/v1/attachments/{ready["id"]}/content', actor=bob
|
||||
)['bytes']
|
||||
check(downloaded == original, 'original bytes changed')
|
||||
print('PASS: original plus thumbnail/crop/optimized variants are valid')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run(main)
|
||||
Reference in New Issue
Block a user