feat: implement game-like LU trainer and companion map
This commit is contained in:
1 parent
87d5a6720f
commit
74c8504d52
21 files changed
+1160
-14
No files matched your search
@@ -0,0 +1,49 @@
|
||||
"""Standalone LU trainer routing must work without any game/session store."""
|
||||
import http.client
|
||||
import threading
|
||||
import unittest
|
||||
|
||||
from app.main import BelkiHTTPServer, Handler
|
||||
|
||||
|
||||
class TrainerRoutesTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.server = BelkiHTTPServer(('127.0.0.1', 0), Handler)
|
||||
cls.worker = threading.Thread(target=cls.server.serve_forever, daemon=True)
|
||||
cls.worker.start()
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.server.shutdown()
|
||||
cls.server.server_close()
|
||||
cls.worker.join()
|
||||
|
||||
def get(self, path):
|
||||
connection = http.client.HTTPConnection('127.0.0.1', self.server.server_port, timeout=5)
|
||||
try:
|
||||
connection.request('GET', path)
|
||||
response = connection.getresponse()
|
||||
return response.status, response.getheader('Content-Type'), response.read()
|
||||
finally:
|
||||
connection.close()
|
||||
|
||||
def test_page_aliases_return_the_same_trainer(self):
|
||||
pages = [self.get(path) for path in ['/lu-trainer', '/lu-trainer/', '/lu-trainer.html']]
|
||||
for status, content_type, content in pages:
|
||||
self.assertEqual(status, 200)
|
||||
self.assertEqual(content_type, 'text/html')
|
||||
self.assertIn('Тренажёр ЛУ'.encode(), content)
|
||||
self.assertEqual(pages[0][2], pages[1][2])
|
||||
|
||||
def test_assets_have_browser_compatible_mime_types(self):
|
||||
for asset, media_type in [('engine.js', 'javascript'), ('ui.js', 'javascript'), ('style.css', 'text/css'), ('assets/forest.webp', 'image/webp'), ('assets/cat.png', 'image/png')]:
|
||||
with self.subTest(asset=asset):
|
||||
status, content_type, content = self.get('/lu-trainer/' + asset)
|
||||
self.assertEqual(status, 200)
|
||||
self.assertIn(media_type, content_type)
|
||||
self.assertGreater(len(content), 0)
|
||||
|
||||
def test_missing_and_escaping_assets_are_not_served(self):
|
||||
for path in ['/lu-trainer/missing.js', '/lu-trainer/%2e%2e/%2e%2e/project-info.txt']:
|
||||
self.assertEqual(self.get(path)[0], 404)
|
||||
Reference in new issue
Block a user