Exemplo n.º 1
0
    def _get_common_deserialized_components(
            cls,
            data: Dict[str, Optional[str or int or float or bool or
                                     Dict or List or Tuple or Set]]) \
            -> Dict[str, Optional[str or int or float or bool or
                                  Dict or List or Tuple or Set]]:
        """
        Deserializes the common child components of the data dictionary
        :param data: The data to deserialize
        :return: The deserialized dictionary
        """
        deserialized = {
            "media_type":
            MediaType[data["media_type"]],
            "id":
            Id.deserialize(data["id"]),
            "title":
            Title.deserialize(data["title"]),
            "relations":
            list(map(lambda x: Relation.deserialize(x), data["relations"])),
            "releasing_status":
            ReleasingStatus[data["releasing_status"]],
            "cover_url":
            data["cover_url"]
        }

        for date in ["releasing_start", "releasing_end"]:
            date_data = data[date]
            if date_data is not None:
                deserialized[date] = Date.deserialize(date_data)
            else:
                deserialized[date] = None

        return deserialized
Exemplo n.º 2
0
 def test_string_representation(self):
     """
     Tests that the string representation is correct
     :return: None
     """
     title = Title({TitleType.ROMAJI: "SnK", TitleType.ENGLISH: "AoT"})
     representation = str(title)
     serialised = json.loads(representation)
     self.assertEqual(title, title.deserialize(serialised))
Exemplo n.º 3
0
 def test_invalid_deserialization(self):
     """
     Tests that invalid serialized data raises ValueErrors when deserialized
     :return: None
     """
     for data in [
         {"A": 1},
         {"ROMAJI": "Hello"},
         {"ANILIST": "1", "default": "ROMAJI"},
         {"ROMAJI": 1, "default": "ROMAJI"},
         {"ROMAJI": None, "default": "ROMAJI"},
         {"Romaji": "Hello", "default": "ROMAJI"},
         []
     ]:
         try:
             Title.deserialize(data)
             self.fail()
         except (TypeError, ValueError):
             pass
Exemplo n.º 4
0
 def test_deserialization(self):
     """
     Tests deserializing an ID object
     :return: None
     """
     data = {"ROMAJI": "SnK", "ENGLISH": "AoT", "default": "ENGLISH"}
     self.assertEqual(
         Title.deserialize(data),
         Title(
             {TitleType.ROMAJI: "SnK", TitleType.ENGLISH: "AoT"},
             default=TitleType.ENGLISH
         )
     )