def process_all_card_data( self, card_data: dict, staged_set: StagedSet, existing_cards: Dict[str, Card], existing_printings: Dict[str, CardPrinting], is_token: bool, ): staged_card = StagedCard(card_data, is_token=is_token) staged_card_face = StagedCardFace(card_data) staged_card_printing = StagedCardPrinting(card_data, staged_set) staged_face_printing = StagedCardFacePrinting(card_data) existing_card = existing_cards.get(staged_card.scryfall_oracle_id) self.process_card(staged_card, existing_card=existing_card) self.process_card_faces(staged_card, staged_card_face, existing_card) self.process_card_printing( staged_card=staged_card, staged_card_face=staged_card_face, staged_card_printing=staged_card_printing, staged_face_printing=staged_face_printing, staged_set=staged_set, existing_printings=existing_printings, ) self.process_card_localisations( card_data=card_data, staged_card_printing=staged_card_printing, staged_face_printing=staged_face_printing, existing_printings=existing_printings, )
def test_get_type(self) -> None: """ Tests that a card with multiple types has the correct type string """ staged_card_face = StagedCardFace({ "name": "test", "types": ["Legendary", "Creature"] }) self.assertEqual(staged_card_face.types, ["Legendary", "Creature"])
def test_colour_weight_heavy(self) -> None: """ Tests that a card with only coloured mana symbols has the correct colour weight """ staged_card_face = StagedCardFace({ "name": "test", "manaCost": "{B}{B}{B}{B}", "convertedManaCost": 4 }) self.assertEqual(4, staged_card_face.colour_weight)
def test_colour_weight_colourless(self) -> None: """ Tests that a colourless card has the correct colour weight """ staged_card_face = StagedCardFace({ "name": "test", "manaCost": "{11}", "convertedManaCost": 11 }) self.assertEqual(0, staged_card_face.colour_weight)
def test_colour_weight(self) -> None: """ Tests the colour weight of a card """ staged_card_face = StagedCardFace({ "name": "test", "manaCost": "{1}{G}{G}", "convertedManaCost": 3 }) self.assertEqual(2, staged_card_face.colour_weight)
def test_token_subtype(self) -> None: """ Tests that a token card has its subtypes parsed correctly """ staged_card_face = StagedCardFace({ "name": "test", "type": "Token Legendary Creature — Monkey" }) self.assertEqual("Token Legendary Creature — Monkey", staged_card_face.type_line)
def process_card_faces( self, staged_card, staged_card_face: StagedCardFace, existing_card: Optional[Card], ) -> None: existing_card_face = (next( face for face in existing_card.faces.all() if face.side == staged_card_face.side) if existing_card else None) face_tuple = (staged_card_face.scryfall_oracle_id, staged_card_face.side) if face_tuple in self.card_faces_parsed: return self.card_faces_parsed.add(face_tuple) if existing_card_face: face_differences = staged_card_face.get_card_face_differences( existing_card_face) if face_differences: self.card_faces_to_update.append( UpdateCardFace( update_mode=UpdateMode.UPDATE, scryfall_oracle_id=staged_card.scryfall_oracle_id, name=staged_card.name, face_name=staged_card_face.name, side=staged_card_face.side, field_data=face_differences, )) else: self.card_faces_to_update.append( UpdateCardFace( update_mode=UpdateMode.CREATE, scryfall_oracle_id=staged_card.scryfall_oracle_id, name=staged_card.name, face_name=staged_card_face.name, side=staged_card_face.side, field_data=staged_card_face.get_field_data(), ))
def test_colour_weight_none(self) -> None: """ Tests that a card without any mana cost has zero colour weight """ staged_card_face = StagedCardFace({"name": "test"}) self.assertEqual(0, staged_card_face.colour_weight)