319 lines
14 KiB
Python
319 lines
14 KiB
Python
|
|
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 ────────────────────────────────────────────────────
|
|||
|
|
#
|
|||
|
|
# After all 6 roles are revealed the room enters SIG_SELECT. A 36-card
|
|||
|
|
# Significator deck appears at the table centre; gamers pick in seat order
|
|||
|
|
# (PC → NC → EC → SC → AC → BC). Selected cards are removed from the shared
|
|||
|
|
# pile in real time via WebSocket, exactly as role selection works.
|
|||
|
|
#
|
|||
|
|
# Deck composition (18 unique cards × 2 — one from levity, one from gravity):
|
|||
|
|
# SC / AC (Shepherd / Alchemist) → M/J/Q/K of Swords & Cups (16 cards)
|
|||
|
|
# PC / BC (Player / Builder) → M/J/Q/K of Wands & Pentacles (16 cards)
|
|||
|
|
# NC / EC (Narrator / Economist) → The Schiz (0) + Chancellor (1) ( 4 cards)
|
|||
|
|
#
|
|||
|
|
# Levity pile: SC, PC, NC contributions. Gravity pile: AC, BC, EC contributions.
|
|||
|
|
# Cards retain the contributor's deck card-back — up to 6 distinct backs active.
|
|||
|
|
#
|
|||
|
|
# ─────────────────────────────────────────────────────────────────────────────
|
|||
|
|
|
|||
|
|
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"}
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
# ------------------------------------------------------------------ #
|
|||
|
|
# Test S1 — Significator deck of 36 cards appears at table centre #
|
|||
|
|
# ------------------------------------------------------------------ #
|
|||
|
|
|
|||
|
|
def test_sig_deck_appears_with_36_cards_after_all_roles_revealed(self):
|
|||
|
|
founder, _ = User.objects.get_or_create(email="founder@test.io")
|
|||
|
|
room = Room.objects.create(name="Sig Deck Test", owner=founder)
|
|||
|
|
_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)
|
|||
|
|
|
|||
|
|
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)
|
|||
|
|
|
|||
|
|
# Significator deck is visible at the table centre
|
|||
|
|
sig_deck = self.wait_for(
|
|||
|
|
lambda: self.browser.find_element(By.ID, "id_sig_deck")
|
|||
|
|
)
|
|||
|
|
self.assertTrue(sig_deck.is_displayed())
|
|||
|
|
|
|||
|
|
# It contains exactly 36 cards
|
|||
|
|
cards = self.browser.find_elements(By.CSS_SELECTOR, "#id_sig_deck .sig-card")
|
|||
|
|
self.assertEqual(len(cards), 36)
|
|||
|
|
|
|||
|
|
# ------------------------------------------------------------------ #
|
|||
|
|
# Test S2 — Seats reorder to canonical role sequence at SIG_SELECT #
|
|||
|
|
# ------------------------------------------------------------------ #
|
|||
|
|
|
|||
|
|
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)
|
|||
|
|
|
|||
|
|
# ------------------------------------------------------------------ #
|
|||
|
|
# Test S3 — First seat (PC) can select a significator; deck shrinks #
|
|||
|
|
# ------------------------------------------------------------------ #
|
|||
|
|
|
|||
|
|
def test_first_seat_pc_can_select_significator_and_deck_shrinks(self):
|
|||
|
|
founder, _ = User.objects.get_or_create(email="founder@test.io")
|
|||
|
|
room = Room.objects.create(name="PC Select Test", owner=founder)
|
|||
|
|
# Founder is assigned PC (slot 1 → first in canonical order → active)
|
|||
|
|
_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=["PC", "NC", "EC", "SC", "AC", "BC"])
|
|||
|
|
|
|||
|
|
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)
|
|||
|
|
|
|||
|
|
# 36-card sig deck is present and the founder's seat is active
|
|||
|
|
self.wait_for(
|
|||
|
|
lambda: self.browser.find_element(By.CSS_SELECTOR, "#id_sig_deck .sig-card")
|
|||
|
|
)
|
|||
|
|
self.wait_for(
|
|||
|
|
lambda: self.browser.find_element(
|
|||
|
|
By.CSS_SELECTOR, ".table-seat.active[data-role='PC']"
|
|||
|
|
)
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
# Click the first card in the significator deck to select it
|
|||
|
|
first_card = self.browser.find_element(
|
|||
|
|
By.CSS_SELECTOR, "#id_sig_deck .sig-card"
|
|||
|
|
)
|
|||
|
|
first_card.click()
|
|||
|
|
self.confirm_guard()
|
|||
|
|
|
|||
|
|
# Deck now has 35 cards — one pile copy of the selected card removed
|
|||
|
|
self.wait_for(
|
|||
|
|
lambda: self.assertEqual(
|
|||
|
|
len(self.browser.find_elements(By.CSS_SELECTOR, "#id_sig_deck .sig-card")),
|
|||
|
|
35,
|
|||
|
|
)
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
# Founder's significator appears in their inventory
|
|||
|
|
self.wait_for(
|
|||
|
|
lambda: self.browser.find_element(
|
|||
|
|
By.CSS_SELECTOR, "#id_inv_sig_card .card"
|
|||
|
|
)
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
# Active seat advances to NC
|
|||
|
|
self.wait_for(
|
|||
|
|
lambda: self.browser.find_element(
|
|||
|
|
By.CSS_SELECTOR, ".table-seat.active[data-role='NC']"
|
|||
|
|
)
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
# ------------------------------------------------------------------ #
|
|||
|
|
# Test S4 — Ineligible seat cannot interact with sig deck #
|
|||
|
|
# ------------------------------------------------------------------ #
|
|||
|
|
|
|||
|
|
def test_non_active_seat_cannot_select_significator(self):
|
|||
|
|
founder, _ = User.objects.get_or_create(email="founder@test.io")
|
|||
|
|
room = Room.objects.create(name="Ineligible Sig Test", owner=founder)
|
|||
|
|
# Founder is NC (second in canonical order) — not first
|
|||
|
|
_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=["NC", "PC", "EC", "SC", "AC", "BC"])
|
|||
|
|
|
|||
|
|
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"))
|
|||
|
|
|
|||
|
|
# Click a sig card — it must not trigger a selection (deck stays at 36)
|
|||
|
|
self.browser.find_element(By.CSS_SELECTOR, "#id_sig_deck .sig-card").click()
|
|||
|
|
self.wait_for(
|
|||
|
|
lambda: self.assertEqual(
|
|||
|
|
len(self.browser.find_elements(By.CSS_SELECTOR, "#id_sig_deck .sig-card")),
|
|||
|
|
36,
|
|||
|
|
)
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
|
|||
|
|
@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
|
|||
|
|
|
|||
|
|
# ------------------------------------------------------------------ #
|
|||
|
|
# Test S5 — Selected sig card disappears for watching gamer (WS) #
|
|||
|
|
# ------------------------------------------------------------------ #
|
|||
|
|
|
|||
|
|
def test_selected_sig_card_removed_from_deck_for_other_gamers(self):
|
|||
|
|
founder, _ = User.objects.get_or_create(email="founder@test.io")
|
|||
|
|
User.objects.get_or_create(email="watcher@test.io")
|
|||
|
|
room = Room.objects.create(name="Sig WS Test", owner=founder)
|
|||
|
|
_fill_room_via_orm(room, [
|
|||
|
|
"founder@test.io", "watcher@test.io", "bud@test.io",
|
|||
|
|
"pal@test.io", "dude@test.io", "bro@test.io",
|
|||
|
|
])
|
|||
|
|
# Founder is PC (active first); watcher is NC (second)
|
|||
|
|
_assign_all_roles(room, role_order=["PC", "NC", "EC", "SC", "AC", "BC"])
|
|||
|
|
room_url = f"{self.live_server_url}/gameboard/room/{room.id}/gate/"
|
|||
|
|
|
|||
|
|
# Watcher loads room, sees 36 cards
|
|||
|
|
self.create_pre_authenticated_session("watcher@test.io")
|
|||
|
|
self.browser.get(room_url)
|
|||
|
|
self.wait_for(
|
|||
|
|
lambda: self.assertEqual(
|
|||
|
|
len(self.browser.find_elements(By.CSS_SELECTOR, "#id_sig_deck .sig-card")),
|
|||
|
|
36,
|
|||
|
|
)
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
# Founder picks a significator in second browser
|
|||
|
|
self.browser2 = self._make_browser2("founder@test.io")
|
|||
|
|
try:
|
|||
|
|
self.browser2.get(room_url)
|
|||
|
|
self.wait_for(lambda: self.browser2.find_element(
|
|||
|
|
By.CSS_SELECTOR, ".table-seat.active[data-role='PC']"
|
|||
|
|
))
|
|||
|
|
self.browser2.find_element(
|
|||
|
|
By.CSS_SELECTOR, "#id_sig_deck .sig-card"
|
|||
|
|
).click()
|
|||
|
|
self.confirm_guard(browser=self.browser2)
|
|||
|
|
|
|||
|
|
# Watcher's deck shrinks to 35 without a page reload
|
|||
|
|
self.wait_for(
|
|||
|
|
lambda: self.assertEqual(
|
|||
|
|
len(self.browser.find_elements(
|
|||
|
|
By.CSS_SELECTOR, "#id_sig_deck .sig-card"
|
|||
|
|
)),
|
|||
|
|
35,
|
|||
|
|
)
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
# Active seat advances to NC in both browsers
|
|||
|
|
self.wait_for(lambda: self.browser.find_element(
|
|||
|
|
By.CSS_SELECTOR, ".table-seat.active[data-role='NC']"
|
|||
|
|
))
|
|||
|
|
self.wait_for(lambda: self.browser2.find_element(
|
|||
|
|
By.CSS_SELECTOR, ".table-seat.active[data-role='NC']"
|
|||
|
|
))
|
|||
|
|
finally:
|
|||
|
|
self.browser2.quit()
|