Files
snake-python/tests/test_DashboardStaticAssets.py
daniel156161 f14d780f29
Build and Push Docker Container / build-and-push (push) Successful in 7m53s
feat: add live replays and PostgreSQL maintenance tools
- Stream compact live replay updates across local and clustered dashboards.
- Render responsive snake bodies as SVG paths with aligned custom icons.
- Add cache-busted assets, replay fallback routes, and live-follow playback.
- Support PostgreSQL benchmark sampling and idempotent SQLite migration.
- Add dry-run cleanup for old low-quality PostgreSQL replay payloads.
- Reward safe perimeter lanes and bump Prism to version 1.5.0.
- Add backend, migration, dashboard, and perimeter regression coverage.
2026-08-02 00:50:46 +02:00

52 lines
1.6 KiB
Python

import os
import re
import unittest
from server.Server import Server
REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
class TestDashboardStaticAssets(unittest.IsolatedAsyncioTestCase):
def setUp(self):
self.server = Server(
data_path=REPO_ROOT,
snake_type='PrismBattleSnake',
storage_type='memory',
metrics_backend='memory',
gameplay_db_enabled=False,
)
def _static_url(self):
return self.server.app.jinja_env.globals['static_url']
async def test_static_url_carries_file_mtime(self):
asset = 'js/GameBoard.js'
expected_version = int(os.path.getmtime(
os.path.join(self.server.app.static_folder, asset)
))
async with self.server.app.test_request_context('/dashboard'):
url = self._static_url()(asset)
self.assertEqual(url, f'/files/{asset}?v={expected_version}')
async def test_static_url_tolerates_missing_asset(self):
async with self.server.app.test_request_context('/dashboard'):
url = self._static_url()('js/DoesNotExist.js')
self.assertEqual(url, '/files/js/DoesNotExist.js?v=0')
async def test_dashboard_page_versions_every_static_asset(self):
client = self.server.app.test_client()
response = await client.get('/dashboard')
self.assertEqual(response.status_code, 200)
body = await response.get_data(as_text=True)
references = re.findall(r'(?:href|src)="(/files/[^"]+)"', body)
self.assertTrue(references, 'dashboard page referenced no static assets')
for reference in references:
self.assertRegex(reference, r'\?v=\d+$', f'unversioned static asset: {reference}')
if __name__ == '__main__':
unittest.main()