hopefully plugged pipeline fail for FT to assert stock card deck version; 11 new test_models ITs & 12 new test_views ITs in apps.epic.tests

This commit is contained in:
Disco DeDisco
2026-03-25 01:30:18 -04:00
parent 4d52c4f54d
commit c0016418cc
4 changed files with 642 additions and 3 deletions

View File

@@ -6,7 +6,9 @@ from django.urls import reverse
from django.utils import timezone
from apps.lyric.models import Token, User
from apps.epic.models import GateSlot, Room, RoomInvite, TableSeat
from apps.epic.models import (
DeckVariant, GateSlot, Room, RoomInvite, TableSeat, TarotCard,
)
class RoomCreationViewTest(TestCase):
@@ -766,3 +768,192 @@ class ReleaseSlotViewTest(TestCase):
)
self.room.refresh_from_db()
self.assertEqual(self.room.gate_status, Room.GATHERING)
# ── Significator Selection ────────────────────────────────────────────────────
SIG_SEAT_ORDER = ["PC", "NC", "EC", "SC", "AC", "BC"]
def _make_sig_cards(deck):
for suit in ["WANDS", "CUPS", "SWORDS", "PENTACLES"]:
for number, court in [(11, "Maid"), (12, "Jack"), (13, "Queen"), (14, "King")]:
TarotCard.objects.create(
deck_variant=deck, arcana="MINOR", suit=suit, number=number,
name=f"{court} of {suit.capitalize()}",
slug=f"{court.lower()}-of-{suit.lower()}-em",
keywords_upright=[], keywords_reversed=[],
)
TarotCard.objects.create(
deck_variant=deck, arcana="MAJOR", number=0,
name="The Schiz", slug="the-schiz",
keywords_upright=[], keywords_reversed=[],
)
TarotCard.objects.create(
deck_variant=deck, arcana="MAJOR", number=1,
name="Pope 1: Chancellor", slug="pope-1-chancellor",
keywords_upright=[], keywords_reversed=[],
)
def _full_sig_setUp(test_case, role_order=None):
"""Populate test_case with a SIG_SELECT room; return (room, gamers, earthman, card_in_deck)."""
if role_order is None:
role_order = SIG_SEAT_ORDER[:]
earthman = DeckVariant.objects.create(
slug="earthman", name="Earthman Deck", card_count=108, is_default=True
)
_make_sig_cards(earthman)
founder = User.objects.create(email="founder@test.io")
gamers = [founder]
for i in range(2, 7):
gamers.append(User.objects.create(email=f"g{i}@test.io"))
for gamer in gamers:
gamer.equipped_deck = earthman
gamer.save(update_fields=["equipped_deck"])
room = Room.objects.create(name="Sig Room", owner=founder)
for i, (gamer, role) in enumerate(zip(gamers, role_order), start=1):
slot = room.gate_slots.get(slot_number=i)
slot.gamer = gamer
slot.status = GateSlot.FILLED
slot.save()
TableSeat.objects.create(
room=room, gamer=gamer, slot_number=i, role=role, role_revealed=True,
)
room.gate_status = Room.OPEN
room.table_status = Room.SIG_SELECT
room.save()
card_in_deck = TarotCard.objects.get(
deck_variant=earthman, arcana="MINOR", suit="WANDS", number=11
)
test_case.client.force_login(founder)
return room, gamers, earthman, card_in_deck
class SigSelectRenderingTest(TestCase):
"""Gate view at SIG_SELECT renders the Significator deck."""
def setUp(self):
self.room, self.gamers, self.earthman, _ = _full_sig_setUp(self)
self.url = reverse("epic:gatekeeper", kwargs={"room_id": self.room.id})
def test_sig_deck_element_present(self):
response = self.client.get(self.url)
self.assertContains(response, "id_sig_deck")
def test_sig_deck_contains_36_sig_cards(self):
response = self.client.get(self.url)
self.assertEqual(response.content.decode().count('class="sig-card"'), 36)
def test_seats_rendered_in_pc_nc_ec_sc_ac_bc_order(self):
response = self.client.get(self.url)
content = response.content.decode()
positions = {role: content.find(f'data-role="{role}"') for role in SIG_SEAT_ORDER}
# Every role must appear
self.assertTrue(all(pos != -1 for pos in positions.values()))
# Rendered in canonical sequence
ordered = sorted(SIG_SEAT_ORDER, key=lambda r: positions[r])
self.assertEqual(ordered, SIG_SEAT_ORDER)
def test_sig_deck_not_present_during_role_select(self):
self.room.table_status = Room.ROLE_SELECT
self.room.save()
response = self.client.get(self.url)
self.assertNotContains(response, "id_sig_deck")
class SelectSigCardViewTest(TestCase):
"""select_sig view — records choice, enforces turn order, rejects bad input."""
def setUp(self):
self.room, self.gamers, self.earthman, self.card = _full_sig_setUp(self)
# Founder is slot 1, role=PC — active first in canonical order
self.url = reverse("epic:select_sig", kwargs={"room_id": self.room.id})
def _post(self, card_id=None, client=None):
c = client or self.client
return c.post(self.url, data={"card_id": card_id or self.card.id})
def test_select_sig_records_choice_on_active_seat(self):
self._post()
seat = TableSeat.objects.get(room=self.room, role="PC")
self.assertEqual(seat.significator, self.card)
def test_select_sig_returns_200(self):
response = self._post()
self.assertEqual(response.status_code, 200)
def test_select_sig_wrong_turn_makes_no_change(self):
# Gamer 2 is NC — not their turn yet
self.client.force_login(self.gamers[1])
self._post()
seat = TableSeat.objects.get(room=self.room, role="NC")
self.assertIsNone(seat.significator)
def test_select_sig_wrong_turn_returns_403(self):
self.client.force_login(self.gamers[1])
response = self._post()
self.assertEqual(response.status_code, 403)
def test_select_sig_card_not_in_deck_returns_400(self):
# Create a card that is not in the sig deck (e.g. a pip card)
other = TarotCard.objects.create(
deck_variant=self.earthman, arcana="MINOR", suit="WANDS", number=5,
name="Five of Wands", slug="five-of-wands-em",
keywords_upright=[], keywords_reversed=[],
)
response = self._post(card_id=other.id)
self.assertEqual(response.status_code, 400)
def test_select_sig_card_already_taken_returns_409(self):
# Another seat already holds this card as their significator
nc_seat = TableSeat.objects.get(room=self.room, role="NC")
nc_seat.significator = self.card
nc_seat.save()
response = self._post()
self.assertEqual(response.status_code, 409)
def test_select_sig_advances_active_seat_to_nc(self):
self._post()
from apps.epic.models import active_sig_seat
seat = active_sig_seat(self.room)
self.assertEqual(seat.role, "NC")
def test_select_sig_notifies_ws(self):
with patch("apps.epic.views._notify_sig_selected") as mock_notify:
self._post()
mock_notify.assert_called_once_with(self.room.id)
def test_select_sig_requires_login(self):
self.client.logout()
response = self._post()
self.assertEqual(response.status_code, 302)
self.assertIn("/accounts/login/", response.url)
def test_select_sig_wrong_phase_redirects(self):
self.room.table_status = Room.ROLE_SELECT
self.room.save()
response = self._post()
self.assertRedirects(
response, reverse("epic:gatekeeper", args=[self.room.id])
)
def test_select_sig_last_choice_does_not_advance_to_none(self):
"""After all 6 significators chosen, active_sig_seat() is None —
no unhandled AttributeError in the view."""
cards = list(TarotCard.objects.filter(deck_variant=self.earthman, arcana="MINOR"))
seats_in_order = list(
TableSeat.objects.filter(room=self.room).order_by("slot_number")
)
# Assign all but the last (BC) manually
for seat, card in zip(seats_in_order[:-1], cards):
seat.significator = card
seat.save()
# BC gamer POSTs the final choice
bc_seat = TableSeat.objects.get(room=self.room, role="BC")
self.client.force_login(bc_seat.gamer)
last_card = TarotCard.objects.filter(
deck_variant=self.earthman, arcana="MAJOR", number=0
).first()
response = self.client.post(self.url, data={"card_id": last_card.id})
self.assertIn(response.status_code, (200, 302))