def test_missing_entries(self): """ Tests that missing title entries are replaced with None. :return: None """ title = Title({TitleType.ROMAJI: "Shingeki no Kyojin"}) self.assertEqual(title.get(TitleType.ROMAJI), "Shingeki no Kyojin") self.assertEqual(title.get(TitleType.ENGLISH), None) self.assertEqual(title.get(TitleType.JAPANESE), None)
def test_title_construction(self): """ Tests constructing the title :return: None """ title = Title({ TitleType.ROMAJI: "Shingeki no Kyojin", TitleType.ENGLISH: "Attack on Titan", TitleType.JAPANESE: "進撃の巨人" }) # Default = ROMAJI self.assertEqual(title.get(), "Shingeki no Kyojin") self.assertEqual(title.get(TitleType.ENGLISH), "Attack on Titan") self.assertEqual(title.get(TitleType.ROMAJI), "Shingeki no Kyojin") self.assertEqual(title.get(TitleType.JAPANESE), "進撃の巨人")
def test_setting_titles(self): """ Tests manually setting title values :return: None """ title = Title({TitleType.ROMAJI: "Shingeki no Kyojin"}) self.assertEqual(title.get(TitleType.ROMAJI), "Shingeki no Kyojin") self.assertEqual(title.get(TitleType.ENGLISH), None) self.assertEqual(title.get(TitleType.JAPANESE), None) title.set("Attack on Titan", TitleType.ENGLISH) title.set("進撃の巨人", TitleType.JAPANESE) self.assertEqual(title.get(TitleType.ENGLISH), "Attack on Titan") self.assertEqual(title.get(TitleType.ROMAJI), "Shingeki no Kyojin") self.assertEqual(title.get(TitleType.JAPANESE), "進撃の巨人") title.set("AAAAA", TitleType.ROMAJI) self.assertEqual(title.get(), "AAAAA")
def __generate_media_data(media_type: MediaType, data: Dict[str, Any]) -> MediaData: """ Generates an MediaData object from a GraphQL result :param media_type: The media type to generate :param data: The data to convert into an AnimeData object :return: The generated AnimeData object """ _id = Id({ IdType.ANILIST: data["id"], IdType.MYANIMELIST: data["idMal"] }) title = Title({ TitleType.ROMAJI: data["title"]["romaji"], TitleType.ENGLISH: data["title"]["english"], TitleType.JAPANESE: data["title"]["native"], }) if title.get(TitleType.ENGLISH) is None: title.set(title.get(TitleType.ROMAJI), TitleType.ENGLISH) relations = [] for relation in data["relations"]["edges"]: dest_id = Id({ IdType.ANILIST: relation["node"]["id"], IdType.MYANIMELIST: relation["node"]["idMal"] }) dest_media_type = media_type rel_type = RelationType[relation["relationType"]] if rel_type == RelationType.ADAPTATION: if media_type == MediaType.ANIME: dest_media_type = MediaType.MANGA else: dest_media_type = MediaType.ANIME relations.append( Relation(_id, media_type, dest_id, dest_media_type, rel_type).serialize()) releasing_status = \ data["status"].replace("NOT_YET_RELEASED", "NOT_RELEASED") serialized = { "media_type": media_type.name, "id": _id.serialize(), "title": title.serialize(), "relations": relations, "releasing_status": releasing_status, "cover_url": data["coverImage"]["large"], "episode_count": data["episodes"], "episode_duration": data["duration"], "chapter_count": data["episodes"], "volume_count": data["episodes"] } for api_key, dict_key in { "startDate": "releasing_start", "endDate": "releasing_end" }.items(): try: serialized[dict_key] = Date(data[api_key]["year"], data[api_key]["month"], data[api_key]["day"]).serialize() except (TypeError, ValueError): serialized[dict_key] = None return MediaData.deserialize(serialized)