Files
dtf-system/tests/site_video_test.py
Cauê Faleiros 21858b5764 feat: a video on several products, sound and expand on the floating player, upright vertical video, looping cards at the foot of the home (Rodada 5, D7)
site_videos.products (the old product column is kept and copied); one
floating video per product checks the overlap and names it. The floating
player starts muted, with a sound button that says its state and an
expand button to the large player. A vertical video stands upright on
the floating and the large player. The home's videos move to its foot as
muted looping cards that play only on screen, not at all with reduced
motion, and open the large player.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 16:09:52 -03:00

110 lines
5.7 KiB
Python

"""Published site videos retain their file and expose same-origin captions.
Run against the local stack with an internal S3 public endpoint:
SITE_BASE_URL=http://site SITE_HOST_HEADER=localhost python -m tests.site_video_test
"""
from urllib.request import Request, urlopen
from app.core import db
from app.runtime import storage
from tests.smoke_test import BASE, Client, with_host, wait_scan
VIDEO = b'\x00\x00\x00\x18ftypisom\x00\x00\x00\x00isomiso2'
CAPTIONS = b'WEBVTT\n\n00:00:00.000 --> 00:00:01.000\nTeste de legenda.\n'
def upload(operator, name, content):
start = operator.call('/operator/site-videos/uploads', {'name': name, 'size': len(content)})
uid = start['id']
url = operator.call(f'/operator/uploads/{uid}/parts/1', {})['url']
with urlopen(Request(url, data=content, method='PUT'), timeout=30) as response:
assert response.status == 200
operator.call(f'/operator/uploads/{uid}/complete', {})
wait_scan(operator, uid, operator=True)
return uid
def run():
client = Client()
client.call('/session')
with db.connect() as c:
assert not c.execute("SELECT 1 FROM dtf_local.site_videos WHERE id='sala'").fetchone(), \
'The isolated test catalog entry is already configured'
ids = []
keys = []
try:
client.call('/operator/site-videos/sala', {'enabled': True}, expected=401)
operator = client.operator_client or Client()
# Client.call(operator=True) signs in and forwards to its own client.
client.call('/operator/site-videos', operator=True)
operator = client.operator_client
video = upload(operator, 'LOCAL-VIDEO.mp4', VIDEO)
captions = upload(operator, 'LOCAL-VIDEO.vtt', CAPTIONS)
ids = [video, captions]
operator.call('/operator/site-videos/sala', {'upload_id': video,
'captions_id': captions, 'product': 'file', 'enabled': True})
published = client.call('/site/videos')['videos']
entry = next(row for row in published if row['id'] == 'sala')
assert entry['product'] == 'file'
assert entry['products'] == ['file'], entry
assert entry['captions'] == '/api/site/videos/sala/captions'
# The same video can appear on more than one product; duplicates are
# dropped and the order follows the product catalog.
operator.call('/operator/site-videos/sala', {'upload_id': video,
'captions_id': captions, 'products': ['uv', 'file', 'uv'], 'enabled': True})
entry = next(row for row in client.call('/site/videos')['videos'] if row['id'] == 'sala')
assert entry['products'] == ['file', 'uv'], entry
assert entry['product'] == 'file', entry
# One floating video per product: a second one is refused before any
# copy, naming the video and the product in conflict (DTF-WEB-G).
refused = operator.call('/operator/site-videos/png', {'upload_id': video,
'products': ['uv'], 'enabled': True}, expected=409)
assert 'A sala às 3 da manhã' in refused['detail'], refused
assert 'Artes avulsas · UV' in refused['detail'], refused
# The old single `product` still works and is refused the same way.
refused = operator.call('/operator/site-videos/png', {'upload_id': video,
'product': 'file', 'enabled': True}, expected=409)
assert 'A sala às 3 da manhã' in refused['detail'], refused
with db.connect() as c:
assert not c.execute("SELECT 1 FROM dtf_local.site_videos WHERE id='png'").fetchone()
with urlopen(entry['src'], timeout=30) as response:
assert response.read() == VIDEO
with urlopen(Request(BASE + entry['captions'], headers=with_host()), timeout=30) as response:
assert response.headers['Content-Type'].startswith('text/vtt')
assert response.read() == CAPTIONS
operator.call('/operator/site-videos/sala', {'upload_id': video,
'captions_id': captions, 'product': 'file', 'enabled': False})
assert not any(row['id'] == 'sala' for row in client.call('/site/videos')['videos'])
# Captions are optional (front 8.4): the video alone is published. The
# published VTT copy stops being referenced, so keep it for cleanup.
with db.connect() as c:
old = c.execute("SELECT captions_key FROM dtf_local.site_videos WHERE id='sala'").fetchone()
if old and old['captions_key']:
keys.append(old['captions_key'])
operator.call('/operator/site-videos/sala', {'upload_id': video,
'product': 'file', 'enabled': True})
entry = next(row for row in client.call('/site/videos')['videos'] if row['id'] == 'sala')
assert entry['captions'] is None, entry
client.call('/site/videos/sala/captions', expected=404)
operator.call('/operator/site-videos/sala', {'upload_id': video,
'product': 'file', 'enabled': False})
assert not any(row['id'] == 'sala' for row in client.call('/site/videos')['videos'])
print('PASS: Gestão publishes a scanned video with signed media, with or without captions;'
' hiding removes it from the Site')
finally:
with db.connect() as c:
row = c.execute("DELETE FROM dtf_local.site_videos WHERE id='sala' RETURNING video_key,captions_key").fetchone()
if row:
keys.extend(key for key in row.values() if key)
if ids:
sources = c.execute('DELETE FROM dtf_local.uploads WHERE id=ANY(%s) RETURNING object_key',
(ids,)).fetchall()
keys.extend(row['object_key'] for row in sources)
for key in keys:
storage.client.delete_object(Bucket=storage.bucket, Key=key)
if __name__ == '__main__':
run()