2026-03-25 11:03:53 -04:00
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
from django.conf import settings as django_settings
|
|
|
|
|
from django.test import tag
|
|
|
|
|
from selenium import webdriver
|
|
|
|
|
from selenium.webdriver.common.by import By
|
|
|
|
|
|
|
|
|
|
from .base import FunctionalTest, ChannelsFunctionalTest
|
|
|
|
|
from .management.commands.create_session import create_pre_authenticated_session
|
|
|
|
|
from apps.applets.models import Applet
|
|
|
|
|
from apps.epic.models import DeckVariant, Room, TableSeat, TarotCard
|
|
|
|
|
from apps.lyric.models import User
|
|
|
|
|
|
|
|
|
|
from .test_room_role_select import _fill_room_via_orm
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ── Significator Selection ────────────────────────────────────────────────────
|
|
|
|
|
#
|
2026-04-05 23:44:54 -04:00
|
|
|
# After all 6 roles are revealed the room enters SIG_SELECT. Two parallel
|
|
|
|
|
# 18-card overlays appear (levity: PC/NC/SC; gravity: BC/EC/AC). Each polarity
|
|
|
|
|
# group picks simultaneously — no sequential turn order.
|
2026-03-25 11:03:53 -04:00
|
|
|
#
|
|
|
|
|
# ─────────────────────────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
SIG_SEAT_ORDER = ["PC", "NC", "EC", "SC", "AC", "BC"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _assign_all_roles(room, role_order=None):
|
|
|
|
|
"""Assign roles to all slots, reveal them, and advance to SIG_SELECT.
|
|
|
|
|
Also ensures all gamers have an equipped_deck (required for sig_deck_cards)."""
|
|
|
|
|
if role_order is None:
|
|
|
|
|
role_order = SIG_SEAT_ORDER[:]
|
|
|
|
|
earthman, _ = DeckVariant.objects.get_or_create(
|
|
|
|
|
slug="earthman",
|
|
|
|
|
defaults={"name": "Earthman Deck", "card_count": 108, "is_default": True},
|
|
|
|
|
)
|
|
|
|
|
# Seed the 18 sig deck cards (migration data is flushed in TransactionTestCase FTs)
|
|
|
|
|
_NAME = {11: "Maid", 12: "Jack", 13: "Queen", 14: "King"}
|
|
|
|
|
for suit in ("WANDS", "PENTACLES", "SWORDS", "CUPS"):
|
|
|
|
|
for number in (11, 12, 13, 14):
|
|
|
|
|
TarotCard.objects.get_or_create(
|
|
|
|
|
deck_variant=earthman,
|
|
|
|
|
slug=f"{_NAME[number].lower()}-of-{suit.lower()}-em",
|
|
|
|
|
defaults={"arcana": "MINOR", "suit": suit, "number": number,
|
|
|
|
|
"name": f"{_NAME[number]} of {suit.capitalize()}"},
|
|
|
|
|
)
|
|
|
|
|
for number, name, slug in [
|
|
|
|
|
(0, "The Schiz", "the-schiz-em"),
|
|
|
|
|
(1, "Pope 1: Chancellor", "pope-1-chancellor-em"),
|
|
|
|
|
]:
|
|
|
|
|
TarotCard.objects.get_or_create(
|
|
|
|
|
deck_variant=earthman,
|
|
|
|
|
slug=slug,
|
|
|
|
|
defaults={"arcana": "MAJOR", "number": number, "name": name},
|
|
|
|
|
)
|
|
|
|
|
for slot in room.gate_slots.order_by("slot_number"):
|
|
|
|
|
if slot.gamer and not slot.gamer.equipped_deck:
|
|
|
|
|
slot.gamer.equipped_deck = earthman
|
|
|
|
|
slot.gamer.save(update_fields=["equipped_deck"])
|
|
|
|
|
TableSeat.objects.update_or_create(
|
|
|
|
|
room=room,
|
|
|
|
|
slot_number=slot.slot_number,
|
|
|
|
|
defaults={
|
|
|
|
|
"gamer": slot.gamer,
|
|
|
|
|
"role": role_order[slot.slot_number - 1],
|
|
|
|
|
"role_revealed": True,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
room.table_status = Room.SIG_SELECT
|
|
|
|
|
room.save()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SigSelectTest(FunctionalTest):
|
|
|
|
|
"""Significator Selection — non-WebSocket tests."""
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
super().setUp()
|
|
|
|
|
Applet.objects.get_or_create(
|
|
|
|
|
slug="new-game", defaults={"name": "New Game", "context": "gameboard"}
|
|
|
|
|
)
|
|
|
|
|
Applet.objects.get_or_create(
|
|
|
|
|
slug="my-games", defaults={"name": "My Games", "context": "gameboard"}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------ #
|
2026-04-05 23:44:54 -04:00
|
|
|
# Test S1 — Seats reorder to canonical role sequence at SIG_SELECT #
|
2026-03-25 11:03:53 -04:00
|
|
|
# ------------------------------------------------------------------ #
|
|
|
|
|
|
|
|
|
|
def test_seats_display_in_pc_nc_ec_sc_ac_bc_order_after_reveal(self):
|
|
|
|
|
"""Slots were filled in arbitrary token-drop order; after roles are
|
|
|
|
|
revealed the seat portraits must appear in PC→NC→EC→SC→AC→BC order."""
|
|
|
|
|
founder, _ = User.objects.get_or_create(email="founder@test.io")
|
|
|
|
|
room = Room.objects.create(name="Seat Order Test", owner=founder)
|
|
|
|
|
# Assign roles in reverse of canonical order so the reordering is visible
|
|
|
|
|
_fill_room_via_orm(room, [
|
|
|
|
|
"founder@test.io", "amigo@test.io", "bud@test.io",
|
|
|
|
|
"pal@test.io", "dude@test.io", "bro@test.io",
|
|
|
|
|
])
|
|
|
|
|
_assign_all_roles(room, role_order=["BC", "AC", "SC", "EC", "NC", "PC"])
|
|
|
|
|
|
|
|
|
|
self.create_pre_authenticated_session("founder@test.io")
|
|
|
|
|
room_url = f"{self.live_server_url}/gameboard/room/{room.id}/gate/"
|
|
|
|
|
self.browser.get(room_url)
|
|
|
|
|
|
|
|
|
|
self.wait_for(lambda: self.browser.find_element(By.ID, "id_sig_deck"))
|
|
|
|
|
|
|
|
|
|
seats = self.browser.find_elements(By.CSS_SELECTOR, ".table-seat[data-role]")
|
|
|
|
|
self.assertEqual(len(seats), 6)
|
|
|
|
|
roles_in_order = [s.get_attribute("data-role") for s in seats]
|
|
|
|
|
self.assertEqual(roles_in_order, SIG_SEAT_ORDER)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@tag("channels")
|
|
|
|
|
class SigSelectChannelsTest(ChannelsFunctionalTest):
|
|
|
|
|
"""Significator Selection — WebSocket tests."""
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
super().setUp()
|
|
|
|
|
Applet.objects.get_or_create(
|
|
|
|
|
slug="new-game", defaults={"name": "New Game", "context": "gameboard"}
|
|
|
|
|
)
|
|
|
|
|
Applet.objects.get_or_create(
|
|
|
|
|
slug="my-games", defaults={"name": "My Games", "context": "gameboard"}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def _make_browser2(self, email):
|
|
|
|
|
session_key = create_pre_authenticated_session(email)
|
|
|
|
|
options = webdriver.FirefoxOptions()
|
|
|
|
|
if os.environ.get("HEADLESS"):
|
|
|
|
|
options.add_argument("--headless")
|
|
|
|
|
b = webdriver.Firefox(options=options)
|
|
|
|
|
b.get(self.live_server_url + "/404_no_such_url/")
|
|
|
|
|
b.add_cookie(dict(
|
|
|
|
|
name=django_settings.SESSION_COOKIE_NAME,
|
|
|
|
|
value=session_key,
|
|
|
|
|
path="/",
|
|
|
|
|
))
|
|
|
|
|
return b
|
|
|
|
|
|