def test_uuid_creation(mock_card: Dict[str, Any], mock_file_info: Dict[str, Any]) -> None: """ Tests to ensure UUIDs don't regress :param mock_card: :param mock_file_info: :return: """ card = MTGJSONCard(mock_file_info["code"]) card.set_all(mock_card) uuid_new = card.get_uuid() assert uuid_new == "4b560297-2f1e-5f65-b118-289c21bdf887"
def test_uuid_creation( mock_card: Dict[str, Any], mock_file_info: Dict[str, Any] ) -> None: """ Tests to ensure UUIDs don't regress :param mock_card: :param mock_file_info: :return: """ card = MTGJSONCard(mock_file_info["code"]) card.set_all(mock_card) uuid_new = card.get_uuid() assert uuid_new == "4b560297-2f1e-5f65-b118-289c21bdf887"
def build_mtgjson_tokens(sf_tokens: List[Dict[str, Any]], sf_card_face: int = 0) -> List[MTGJSONCard]: """ Convert Scryfall tokens to MTGJSON tokens :param sf_tokens: All tokens in a set :param sf_card_face: Faces of the token index :return: List of MTGJSON tokens """ token_cards: List[MTGJSONCard] = [] for sf_token in sf_tokens: token_card = MTGJSONCard(sf_token["set"]) if "card_faces" in sf_token: token_card.set("names", sf_token["name"].split(" // ")) face_data = sf_token["card_faces"][sf_card_face] # Prevent duplicate UUIDs for split card halves # Remove the last character and replace with the id of the card face token_card.set("scryfallId", sf_token["id"]) token_card.set("scryfallOracleId", sf_token["oracle_id"]) token_card.set("scryfallIllustrationId", face_data.get("illustration_id")) # Recursively parse the other cards within this card too # Only call recursive if it is the first time we see this card object if sf_card_face == 0: for i in range(1, len(sf_token["card_faces"])): LOGGER.info( f"Parsing additional card {sf_token.get('name')} face {i}" ) token_cards += build_mtgjson_tokens([sf_token], i) if "id" not in sf_token.keys(): LOGGER.info( f"Scryfall_ID not found in {sf_token.get('name')}. Discarding {sf_token}" ) continue token_card.set_all({ "name": face_data.get("name"), "type": face_data.get("type_line", "Card"), "text": face_data.get("oracle_text"), "power": face_data.get("power"), "colors": face_data.get("colors"), "colorIdentity": sf_token.get("color_identity"), "toughness": face_data.get("toughness"), "loyalty": face_data.get("loyalty"), "watermark": sf_token.get("watermark"), "layout": "double_faced_token", "side": chr(97 + sf_card_face), "borderColor": face_data.get("border_color"), "artist": face_data.get("artist"), "isOnlineOnly": sf_token.get("digital"), "number": sf_token.get("collector_number"), }) else: token_card.set_all({ "name": sf_token.get("name"), "type": sf_token.get("type_line", "Card"), "text": sf_token.get("oracle_text"), "power": sf_token.get("power"), "colors": sf_token.get("colors"), "colorIdentity": sf_token.get("color_identity"), "toughness": sf_token.get("toughness"), "loyalty": sf_token.get("loyalty"), "watermark": sf_token.get("watermark"), "scryfallId": sf_token["id"], "scryfallOracleId": sf_token.get("oracle_id"), "scryfallIllustrationId": sf_token.get("illustration_id"), "borderColor": sf_token.get("border_color"), "artist": sf_token.get("artist"), "isOnlineOnly": sf_token.get("digital"), "number": sf_token.get("collector_number"), }) if sf_token.get("layout") == "token": token_card.set("layout", "normal") else: token_card.set("layout", sf_token.get("layout")) reverse_related: List[str] = [] if "all_parts" in sf_token: for a_part in sf_token["all_parts"]: if a_part.get("name") != token_card.get("name"): reverse_related.append(a_part.get("name")) token_card.set("reverseRelated", reverse_related) # Add super/sub/types card_types: Tuple[List[str], List[str], List[str]] = scryfall.parse_card_types( token_card.get("type")) token_card.set("supertypes", card_types[0]) token_card.set("types", card_types[1]) token_card.set("subtypes", card_types[2]) # Add brackets around Planeswalker loyalty abilities if "Planeswalker" in token_card.get("types"): token_card.set("text", token_card.get("text"), token_card.cleanup_planeswalker_costs) token_card.set("uuid", token_card.get_uuid()) LOGGER.info( f"Parsed {token_card.get('name')} from {sf_token.get('set')}") token_cards.append(token_card) return token_cards