forked from mtusi2026/mtusi2026lab4
feat: restricted S3 credentials, orphan reconciler, upload limits (grade 4)
This commit is contained in:
Executable
+35
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Single binary upload for failure drills; asserts the expected status code."""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'tests'))
|
||||
from client import Client, arguments, check, run
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def main():
|
||||
def configure(p):
|
||||
p.add_argument('--expect', type=int, default=201)
|
||||
p.add_argument('--file', default=str(ROOT / 'scripts/fixtures/sample.jpg'))
|
||||
p.add_argument('--content-type', default='image/jpeg')
|
||||
|
||||
args = arguments('Single upload used by compensation drills; creates synthetic data', configure)
|
||||
source = Path(args.file)
|
||||
check(source.is_file(), 'file not found: ' + str(source))
|
||||
content = source.read_bytes()
|
||||
|
||||
c = Client()
|
||||
alice, _, _, chat = c.bootstrap()
|
||||
response = c.call('POST', '/api/v1/chats/' + chat['id'] + '/attachments?filename=' + source.name,
|
||||
args.expect, actor=alice, raw=content,
|
||||
headers={'Content-Type': args.content_type}, schema='Attachment')
|
||||
print(f'status={response["status"]}')
|
||||
if response['status'] == 201:
|
||||
attachment = response['json']
|
||||
print(f"attachment={attachment['id']} size={attachment['size_bytes']}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run(main)
|
||||
Reference in New Issue
Block a user