44
55import pytest
66
7- from tests .lua .conftest import api , assert_error_response , load_fixture
7+ from tests .lua .conftest import (
8+ api ,
9+ assert_error_response ,
10+ assert_gamestate_response ,
11+ load_fixture ,
12+ )
813
914
1015class TestAddEndpoint :
@@ -20,8 +25,9 @@ def test_add_joker(self, client: socket.socket) -> None:
2025 assert gamestate ["state" ] == "SELECTING_HAND"
2126 assert gamestate ["jokers" ]["count" ] == 0
2227 response = api (client , "add" , {"key" : "j_joker" })
23- assert response ["result" ]["jokers" ]["count" ] == 1
24- assert response ["result" ]["jokers" ]["cards" ][0 ]["key" ] == "j_joker"
28+ after = assert_gamestate_response (response )
29+ assert after ["jokers" ]["count" ] == 1
30+ assert after ["jokers" ]["cards" ][0 ]["key" ] == "j_joker"
2531
2632 def test_add_consumable_tarot (self , client : socket .socket ) -> None :
2733 """Test adding a tarot consumable with valid key."""
@@ -33,8 +39,9 @@ def test_add_consumable_tarot(self, client: socket.socket) -> None:
3339 assert gamestate ["state" ] == "SELECTING_HAND"
3440 assert gamestate ["consumables" ]["count" ] == 0
3541 response = api (client , "add" , {"key" : "c_fool" })
36- assert response ["result" ]["consumables" ]["count" ] == 1
37- assert response ["result" ]["consumables" ]["cards" ][0 ]["key" ] == "c_fool"
42+ after = assert_gamestate_response (response )
43+ assert after ["consumables" ]["count" ] == 1
44+ assert after ["consumables" ]["cards" ][0 ]["key" ] == "c_fool"
3845
3946 def test_add_consumable_planet (self , client : socket .socket ) -> None :
4047 """Test adding a planet consumable with valid key."""
@@ -46,8 +53,9 @@ def test_add_consumable_planet(self, client: socket.socket) -> None:
4653 assert gamestate ["state" ] == "SELECTING_HAND"
4754 assert gamestate ["consumables" ]["count" ] == 0
4855 response = api (client , "add" , {"key" : "c_mercury" })
49- assert response ["result" ]["consumables" ]["count" ] == 1
50- assert response ["result" ]["consumables" ]["cards" ][0 ]["key" ] == "c_mercury"
56+ after = assert_gamestate_response (response )
57+ assert after ["consumables" ]["count" ] == 1
58+ assert after ["consumables" ]["cards" ][0 ]["key" ] == "c_mercury"
5159
5260 def test_add_consumable_spectral (self , client : socket .socket ) -> None :
5361 """Test adding a spectral consumable with valid key."""
@@ -59,8 +67,9 @@ def test_add_consumable_spectral(self, client: socket.socket) -> None:
5967 assert gamestate ["state" ] == "SELECTING_HAND"
6068 assert gamestate ["consumables" ]["count" ] == 0
6169 response = api (client , "add" , {"key" : "c_familiar" })
62- assert response ["result" ]["consumables" ]["count" ] == 1
63- assert response ["result" ]["consumables" ]["cards" ][0 ]["key" ] == "c_familiar"
70+ after = assert_gamestate_response (response )
71+ assert after ["consumables" ]["count" ] == 1
72+ assert after ["consumables" ]["cards" ][0 ]["key" ] == "c_familiar"
6473
6574 def test_add_voucher (self , client : socket .socket ) -> None :
6675 """Test adding a voucher with valid key in SHOP state."""
@@ -72,8 +81,9 @@ def test_add_voucher(self, client: socket.socket) -> None:
7281 assert gamestate ["state" ] == "SHOP"
7382 assert gamestate ["vouchers" ]["count" ] == 0
7483 response = api (client , "add" , {"key" : "v_overstock_norm" })
75- assert response ["result" ]["vouchers" ]["count" ] == 1
76- assert response ["result" ]["vouchers" ]["cards" ][0 ]["key" ] == "v_overstock_norm"
84+ after = assert_gamestate_response (response )
85+ assert after ["vouchers" ]["count" ] == 1
86+ assert after ["vouchers" ]["cards" ][0 ]["key" ] == "v_overstock_norm"
7787
7888 def test_add_playing_card (self , client : socket .socket ) -> None :
7989 """Test adding a playing card with valid key."""
@@ -85,8 +95,9 @@ def test_add_playing_card(self, client: socket.socket) -> None:
8595 assert gamestate ["state" ] == "SELECTING_HAND"
8696 assert gamestate ["hand" ]["count" ] == 8
8797 response = api (client , "add" , {"key" : "H_A" })
88- assert response ["result" ]["hand" ]["count" ] == 9
89- assert response ["result" ]["hand" ]["cards" ][8 ]["key" ] == "H_A"
98+ after = assert_gamestate_response (response )
99+ assert after ["hand" ]["count" ] == 9
100+ assert after ["hand" ]["cards" ][8 ]["key" ] == "H_A"
90101
91102 def test_add_no_key_provided (self , client : socket .socket ) -> None :
92103 """Test add endpoint with no key parameter."""
@@ -205,9 +216,10 @@ def test_add_playing_card_with_seal(self, client: socket.socket, seal: str) -> N
205216 assert gamestate ["state" ] == "SELECTING_HAND"
206217 assert gamestate ["hand" ]["count" ] == 8
207218 response = api (client , "add" , {"key" : "H_A" , "seal" : seal })
208- assert response ["result" ]["hand" ]["count" ] == 9
209- assert response ["result" ]["hand" ]["cards" ][8 ]["key" ] == "H_A"
210- assert response ["result" ]["hand" ]["cards" ][8 ]["modifier" ]["seal" ] == seal
219+ after = assert_gamestate_response (response )
220+ assert after ["hand" ]["count" ] == 9
221+ assert after ["hand" ]["cards" ][8 ]["key" ] == "H_A"
222+ assert after ["hand" ]["cards" ][8 ]["modifier" ]["seal" ] == seal
211223
212224 def test_add_playing_card_invalid_seal (self , client : socket .socket ) -> None :
213225 """Test adding a playing card with invalid seal value."""
@@ -258,11 +270,10 @@ def test_add_joker_with_edition(self, client: socket.socket, edition: str) -> No
258270 assert gamestate ["state" ] == "SHOP"
259271 assert gamestate ["jokers" ]["count" ] == 0
260272 response = api (client , "add" , {"key" : "j_joker" , "edition" : edition })
261- assert response ["result" ]["jokers" ]["count" ] == 1
262- assert response ["result" ]["jokers" ]["cards" ][0 ]["key" ] == "j_joker"
263- assert (
264- response ["result" ]["jokers" ]["cards" ][0 ]["modifier" ]["edition" ] == edition
265- )
273+ after = assert_gamestate_response (response )
274+ assert after ["jokers" ]["count" ] == 1
275+ assert after ["jokers" ]["cards" ][0 ]["key" ] == "j_joker"
276+ assert after ["jokers" ]["cards" ][0 ]["modifier" ]["edition" ] == edition
266277
267278 @pytest .mark .parametrize ("edition" , ["HOLO" , "FOIL" , "POLYCHROME" , "NEGATIVE" ])
268279 def test_add_playing_card_with_edition (
@@ -277,9 +288,10 @@ def test_add_playing_card_with_edition(
277288 assert gamestate ["state" ] == "SELECTING_HAND"
278289 assert gamestate ["hand" ]["count" ] == 8
279290 response = api (client , "add" , {"key" : "H_A" , "edition" : edition })
280- assert response ["result" ]["hand" ]["count" ] == 9
281- assert response ["result" ]["hand" ]["cards" ][8 ]["key" ] == "H_A"
282- assert response ["result" ]["hand" ]["cards" ][8 ]["modifier" ]["edition" ] == edition
291+ after = assert_gamestate_response (response )
292+ assert after ["hand" ]["count" ] == 9
293+ assert after ["hand" ]["cards" ][8 ]["key" ] == "H_A"
294+ assert after ["hand" ]["cards" ][8 ]["modifier" ]["edition" ] == edition
283295
284296 def test_add_consumable_with_negative_edition (self , client : socket .socket ) -> None :
285297 """Test adding a consumable with NEGATIVE edition (only valid edition for consumables)."""
@@ -291,12 +303,10 @@ def test_add_consumable_with_negative_edition(self, client: socket.socket) -> No
291303 assert gamestate ["state" ] == "SHOP"
292304 assert gamestate ["consumables" ]["count" ] == 0
293305 response = api (client , "add" , {"key" : "c_fool" , "edition" : "NEGATIVE" })
294- assert response ["result" ]["consumables" ]["count" ] == 1
295- assert response ["result" ]["consumables" ]["cards" ][0 ]["key" ] == "c_fool"
296- assert (
297- response ["result" ]["consumables" ]["cards" ][0 ]["modifier" ]["edition" ]
298- == "NEGATIVE"
299- )
306+ after = assert_gamestate_response (response )
307+ assert after ["consumables" ]["count" ] == 1
308+ assert after ["consumables" ]["cards" ][0 ]["key" ] == "c_fool"
309+ assert after ["consumables" ]["cards" ][0 ]["modifier" ]["edition" ] == "NEGATIVE"
300310
301311 @pytest .mark .parametrize ("edition" , ["HOLO" , "FOIL" , "POLYCHROME" ])
302312 def test_add_consumable_with_non_negative_edition_fails (
@@ -367,12 +377,10 @@ def test_add_playing_card_with_enhancement(
367377 assert gamestate ["state" ] == "SELECTING_HAND"
368378 assert gamestate ["hand" ]["count" ] == 8
369379 response = api (client , "add" , {"key" : "H_A" , "enhancement" : enhancement })
370- assert response ["result" ]["hand" ]["count" ] == 9
371- assert response ["result" ]["hand" ]["cards" ][8 ]["key" ] == "H_A"
372- assert (
373- response ["result" ]["hand" ]["cards" ][8 ]["modifier" ]["enhancement" ]
374- == enhancement
375- )
380+ after = assert_gamestate_response (response )
381+ assert after ["hand" ]["count" ] == 9
382+ assert after ["hand" ]["cards" ][8 ]["key" ] == "H_A"
383+ assert after ["hand" ]["cards" ][8 ]["modifier" ]["enhancement" ] == enhancement
376384
377385 def test_add_playing_card_invalid_enhancement (self , client : socket .socket ) -> None :
378386 """Test adding a playing card with invalid enhancement value."""
@@ -423,9 +431,10 @@ def test_add_joker_with_eternal(self, client: socket.socket) -> None:
423431 assert gamestate ["state" ] == "SHOP"
424432 assert gamestate ["jokers" ]["count" ] == 0
425433 response = api (client , "add" , {"key" : "j_joker" , "eternal" : True })
426- assert response ["result" ]["jokers" ]["count" ] == 1
427- assert response ["result" ]["jokers" ]["cards" ][0 ]["key" ] == "j_joker"
428- assert response ["result" ]["jokers" ]["cards" ][0 ]["modifier" ]["eternal" ] is True
434+ after = assert_gamestate_response (response )
435+ assert after ["jokers" ]["count" ] == 1
436+ assert after ["jokers" ]["cards" ][0 ]["key" ] == "j_joker"
437+ assert after ["jokers" ]["cards" ][0 ]["modifier" ]["eternal" ] is True
429438
430439 @pytest .mark .parametrize ("key" , ["c_fool" , "v_overstock_norm" ])
431440 def test_add_non_joker_with_eternal_fails (
@@ -473,11 +482,10 @@ def test_add_joker_with_perishable(
473482 assert gamestate ["state" ] == "SHOP"
474483 assert gamestate ["jokers" ]["count" ] == 0
475484 response = api (client , "add" , {"key" : "j_joker" , "perishable" : rounds })
476- assert response ["result" ]["jokers" ]["count" ] == 1
477- assert response ["result" ]["jokers" ]["cards" ][0 ]["key" ] == "j_joker"
478- assert (
479- response ["result" ]["jokers" ]["cards" ][0 ]["modifier" ]["perishable" ] == rounds
480- )
485+ after = assert_gamestate_response (response )
486+ assert after ["jokers" ]["count" ] == 1
487+ assert after ["jokers" ]["cards" ][0 ]["key" ] == "j_joker"
488+ assert after ["jokers" ]["cards" ][0 ]["modifier" ]["perishable" ] == rounds
481489
482490 def test_add_joker_with_eternal_and_perishable (self , client : socket .socket ) -> None :
483491 """Test adding a joker with both eternal and perishable stickers."""
@@ -491,10 +499,11 @@ def test_add_joker_with_eternal_and_perishable(self, client: socket.socket) -> N
491499 response = api (
492500 client , "add" , {"key" : "j_joker" , "eternal" : True , "perishable" : 5 }
493501 )
494- assert response ["result" ]["jokers" ]["count" ] == 1
495- assert response ["result" ]["jokers" ]["cards" ][0 ]["key" ] == "j_joker"
496- assert response ["result" ]["jokers" ]["cards" ][0 ]["modifier" ]["eternal" ] is True
497- assert response ["result" ]["jokers" ]["cards" ][0 ]["modifier" ]["perishable" ] == 5
502+ after = assert_gamestate_response (response )
503+ assert after ["jokers" ]["count" ] == 1
504+ assert after ["jokers" ]["cards" ][0 ]["key" ] == "j_joker"
505+ assert after ["jokers" ]["cards" ][0 ]["modifier" ]["eternal" ] is True
506+ assert after ["jokers" ]["cards" ][0 ]["modifier" ]["perishable" ] == 5
498507
499508 @pytest .mark .parametrize ("invalid_value" , [0 , - 1 ])
500509 def test_add_joker_with_perishable_invalid_integer_fails (
@@ -580,9 +589,10 @@ def test_add_joker_with_rental(self, client: socket.socket) -> None:
580589 assert gamestate ["state" ] == "SHOP"
581590 assert gamestate ["jokers" ]["count" ] == 0
582591 response = api (client , "add" , {"key" : "j_joker" , "rental" : True })
583- assert response ["result" ]["jokers" ]["count" ] == 1
584- assert response ["result" ]["jokers" ]["cards" ][0 ]["key" ] == "j_joker"
585- assert response ["result" ]["jokers" ]["cards" ][0 ]["modifier" ]["rental" ] is True
592+ after = assert_gamestate_response (response )
593+ assert after ["jokers" ]["count" ] == 1
594+ assert after ["jokers" ]["cards" ][0 ]["key" ] == "j_joker"
595+ assert after ["jokers" ]["cards" ][0 ]["modifier" ]["rental" ] is True
586596
587597 @pytest .mark .parametrize ("key" , ["c_fool" , "v_overstock_norm" ])
588598 def test_add_non_joker_with_rental_fails (
@@ -614,10 +624,11 @@ def test_add_joker_with_rental_and_eternal(self, client: socket.socket) -> None:
614624 response = api (
615625 client , "add" , {"key" : "j_joker" , "rental" : True , "eternal" : True }
616626 )
617- assert response ["result" ]["jokers" ]["count" ] == 1
618- assert response ["result" ]["jokers" ]["cards" ][0 ]["key" ] == "j_joker"
619- assert response ["result" ]["jokers" ]["cards" ][0 ]["modifier" ]["rental" ] is True
620- assert response ["result" ]["jokers" ]["cards" ][0 ]["modifier" ]["eternal" ] is True
627+ after = assert_gamestate_response (response )
628+ assert after ["jokers" ]["count" ] == 1
629+ assert after ["jokers" ]["cards" ][0 ]["key" ] == "j_joker"
630+ assert after ["jokers" ]["cards" ][0 ]["modifier" ]["rental" ] is True
631+ assert after ["jokers" ]["cards" ][0 ]["modifier" ]["eternal" ] is True
621632
622633 def test_add_playing_card_with_rental_fails (self , client : socket .socket ) -> None :
623634 """Test that rental cannot be applied to playing cards."""
0 commit comments