Django Channels role-select sprint: turn_changed, roles_revealed, role_select_start consumer handlers; WS URL changed from room_slug to room_id UUID; TableSeat model - room, gamer, slot_number, role, role_revealed, seat_position fields; Room.table_status field with ROLE_SELECT, SIG_SELECT, IN_GAME choices; migration 0006_table_status_and_table_seat; pick_roles and select_role views; _role_select_context helper; _notify_turn_changed, _notify_roles_revealed, _notify_role_select_start notifiers; all gate-mutation views now call _notify_gate_update; ChannelsFunctionalTest base class with serve_static, screenshot, dump helpers; SQLite TEST NAME set to file path for ChannelsLiveServerTestCase; InMemoryChannelLayer added to test CHANNEL_LAYERS settings; FT 5 and FT 6 now passing - active seat arc and turn advance via WS, no page refresh; room.js, gatekeeper.js, role-select.js added to apps/epic/static; applets.js, game-kit.js, dashboard.js, wallet.js relocated to app-scoped static dirs; room.html: hex table, table-seat arcs, card-stack, inventory panel, role-card hand, WS scripts; _room.scss: room-shell flex layout, .table-hex polygon clip-path, .table-seat and .seat-card-arc, .card-stack eligible/ineligible states, .card flip animation, .inv-role-card stacked hand, .role-select-backdrop; gear btn and room menu always position: fixed; 375 tests, 0 skipped
This commit is contained in:
@@ -4,6 +4,7 @@ import time
|
||||
from datetime import datetime
|
||||
from django.conf import settings
|
||||
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
|
||||
from channels.testing import ChannelsLiveServerTestCase
|
||||
from pathlib import Path
|
||||
from selenium import webdriver
|
||||
from selenium.common.exceptions import WebDriverException
|
||||
@@ -122,3 +123,81 @@ class FunctionalTest(StaticLiveServerTestCase):
|
||||
lambda: self.browser.find_element(By.CSS_SELECTOR, "input[name=email]"),
|
||||
navbar = self.browser.find_element(By.CSS_SELECTOR, ".navbar")
|
||||
self.assertNotIn(email, navbar.text)
|
||||
|
||||
|
||||
class ChannelsFunctionalTest(ChannelsLiveServerTestCase):
|
||||
"""Like FunctionalTest but backed by daphne so WebSocket connections work."""
|
||||
serve_static = True
|
||||
|
||||
def setUp(self):
|
||||
options = webdriver.FirefoxOptions()
|
||||
headless = os.environ.get("HEADLESS")
|
||||
if headless:
|
||||
options.add_argument("--headless")
|
||||
self.browser = webdriver.Firefox(options=options)
|
||||
if headless:
|
||||
self.browser.set_window_size(1366, 900)
|
||||
self.test_server = os.environ.get("TEST_SERVER")
|
||||
if self.test_server:
|
||||
self.live_server_url = 'http://' + self.test_server
|
||||
reset_database(self.test_server)
|
||||
Applet.objects.get_or_create(slug="new-note", defaults={"name": "New Note"})
|
||||
|
||||
def tearDown(self):
|
||||
if self._test_has_failed():
|
||||
if not SCREEN_DUMP_LOCATION.exists():
|
||||
SCREEN_DUMP_LOCATION.mkdir(parents=True)
|
||||
self.take_screenshot()
|
||||
self.dump_html()
|
||||
self.browser.quit()
|
||||
super().tearDown()
|
||||
|
||||
def _test_has_failed(self):
|
||||
return any(
|
||||
failure[0] == self
|
||||
for failure in self._outcome.result.failures + self._outcome.result.errors
|
||||
)
|
||||
|
||||
def take_screenshot(self):
|
||||
path = SCREEN_DUMP_LOCATION / self._get_filename("png")
|
||||
print("screendumping to", path)
|
||||
self.browser.get_screenshot_as_file(str(path))
|
||||
|
||||
def dump_html(self):
|
||||
path = SCREEN_DUMP_LOCATION / self._get_filename("html")
|
||||
print("dumping page html to", path)
|
||||
path.write_text(self.browser.page_source, encoding="utf-8")
|
||||
|
||||
def _get_filename(self, extension):
|
||||
timestamp = datetime.now().isoformat().replace(":", ".")
|
||||
return (
|
||||
f"{self.__class__.__name__}.{self._testMethodName}-{timestamp}.{extension}"
|
||||
)
|
||||
|
||||
@wait
|
||||
def wait_for(self, fn):
|
||||
return fn()
|
||||
|
||||
def wait_for_slow(self, fn, timeout=30):
|
||||
start_time = time.time()
|
||||
while True:
|
||||
try:
|
||||
return fn()
|
||||
except (AssertionError, WebDriverException) as e:
|
||||
if time.time() - start_time > timeout:
|
||||
raise e
|
||||
time.sleep(0.5)
|
||||
|
||||
def create_pre_authenticated_session(self, email):
|
||||
if self.test_server:
|
||||
session_key = create_session_on_server(self.test_server, email)
|
||||
else:
|
||||
session_key = create_pre_authenticated_session(email)
|
||||
self.browser.get(self.live_server_url + "/404_no_such_url/")
|
||||
self.browser.add_cookie(
|
||||
dict(
|
||||
name=settings.SESSION_COOKIE_NAME,
|
||||
value=session_key,
|
||||
path="/",
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user