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

@@ -5,7 +5,10 @@ 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, debit_token, select_token
from apps.epic.models import (
DeckVariant, GateSlot, Room, RoomInvite, TableSeat, TarotCard,
debit_token, select_token, sig_deck_cards, sig_seat_order, active_sig_seat,
)
class RoomCreationTest(TestCase):
@@ -214,3 +217,168 @@ class RoomInviteTest(TestCase):
Q(invites__invitee_email=friend.email, invites__status=RoomInvite.PENDING)
).distinct()
self.assertIn(self.room, rooms)
# ── Significator deck helpers ─────────────────────────────────────────────────
SIG_SEAT_ORDER = ["PC", "NC", "EC", "SC", "AC", "BC"]
def _make_sig_cards(deck):
"""Create the 18 unique TarotCard types used in the Significator 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_room(name="Sig Room", role_order=None):
"""Return (room, gamers, earthman) with all 6 seats filled, roles assigned,
table_status=SIG_SELECT, and every gamer's equipped_deck set to Earthman."""
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)
owner = User.objects.create(email="founder@sig.io")
gamers = [owner]
for i in range(2, 7):
gamers.append(User.objects.create(email=f"g{i}@sig.io"))
for gamer in gamers:
gamer.equipped_deck = earthman
gamer.save(update_fields=["equipped_deck"])
room = Room.objects.create(name=name, owner=owner)
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.table_status = Room.SIG_SELECT
room.save()
return room, gamers, earthman
class SigDeckCompositionTest(TestCase):
"""sig_deck_cards(room) returns exactly 36 cards with correct suit/arcana split."""
def setUp(self):
self.room, self.gamers, self.earthman = _full_sig_room()
def test_sig_deck_returns_36_cards(self):
cards = sig_deck_cards(self.room)
self.assertEqual(len(cards), 36)
def test_sc_ac_contribute_court_cards_of_swords_and_cups(self):
cards = sig_deck_cards(self.room)
sc_ac = [c for c in cards if c.suit in ("SWORDS", "CUPS")]
# M/J/Q/K × 2 suits × 2 roles = 16
self.assertEqual(len(sc_ac), 16)
self.assertTrue(all(c.number in (11, 12, 13, 14) for c in sc_ac))
def test_pc_bc_contribute_court_cards_of_wands_and_pentacles(self):
cards = sig_deck_cards(self.room)
pc_bc = [c for c in cards if c.suit in ("WANDS", "PENTACLES")]
self.assertEqual(len(pc_bc), 16)
self.assertTrue(all(c.number in (11, 12, 13, 14) for c in pc_bc))
def test_nc_ec_contribute_schiz_and_chancellor(self):
cards = sig_deck_cards(self.room)
major = [c for c in cards if c.arcana == "MAJOR"]
self.assertEqual(len(major), 4)
self.assertEqual(sorted(c.number for c in major), [0, 0, 1, 1])
def test_each_card_appears_twice_once_per_pile(self):
"""18 unique card specs × 2 (levity + gravity) = 36 total."""
cards = sig_deck_cards(self.room)
slugs = [c.slug for c in cards]
unique_slugs = set(slugs)
self.assertEqual(len(unique_slugs), 18)
self.assertTrue(all(slugs.count(s) == 2 for s in unique_slugs))
class SigSeatOrderTest(TestCase):
"""sig_seat_order() and active_sig_seat() return seats in PC→NC→EC→SC→AC→BC order."""
def setUp(self):
# Assign roles in reverse of canonical order to prove reordering works
self.room, self.gamers, _ = _full_sig_room(
name="Order Room",
role_order=["BC", "AC", "SC", "EC", "NC", "PC"],
)
def test_sig_seat_order_returns_canonical_role_sequence(self):
seats = sig_seat_order(self.room)
self.assertEqual([s.role for s in seats], SIG_SEAT_ORDER)
def test_active_sig_seat_is_first_seat_without_significator(self):
seat = active_sig_seat(self.room)
self.assertEqual(seat.role, "PC")
def test_active_sig_seat_advances_after_significator_set(self):
pc_seat = TableSeat.objects.get(room=self.room, role="PC")
earthman = DeckVariant.objects.get(slug="earthman")
card = TarotCard.objects.filter(deck_variant=earthman, arcana="MINOR").first()
pc_seat.significator = card
pc_seat.save()
seat = active_sig_seat(self.room)
self.assertEqual(seat.role, "NC")
def test_active_sig_seat_is_none_when_all_chosen(self):
earthman = DeckVariant.objects.get(slug="earthman")
cards = list(TarotCard.objects.filter(deck_variant=earthman))
for i, seat in enumerate(TableSeat.objects.filter(room=self.room)):
seat.significator = cards[i]
seat.save()
self.assertIsNone(active_sig_seat(self.room))
class SigCardFieldTest(TestCase):
"""TableSeat.significator FK to TarotCard — default null, assignable."""
def setUp(self):
earthman = DeckVariant.objects.create(
slug="earthman", name="Earthman Deck", card_count=108, is_default=True
)
self.card = TarotCard.objects.create(
deck_variant=earthman, arcana="MINOR", suit="WANDS", number=11,
name="Maid of Wands", slug="maid-of-wands-em",
keywords_upright=[], keywords_reversed=[],
)
owner = User.objects.create(email="owner@test.io")
room = Room.objects.create(name="Field Test", owner=owner)
self.seat = TableSeat.objects.create(room=room, gamer=owner, slot_number=1, role="PC")
def test_significator_defaults_to_none(self):
self.assertIsNone(self.seat.significator)
def test_significator_can_be_assigned(self):
self.seat.significator = self.card
self.seat.save()
self.seat.refresh_from_db()
self.assertEqual(self.seat.significator, self.card)
def test_significator_nullable_on_delete(self):
self.seat.significator = self.card
self.seat.save()
self.card.delete()
self.seat.refresh_from_db()
self.assertIsNone(self.seat.significator)

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))