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
     """
     source = Id({IdType.MYANIMELIST: 1})
     dest = Id({IdType.MYANIMELIST: 2})
     relation = Relation(source, MediaType.ANIME, dest, MediaType.ANIME,
                         RelationType.SEQUEL)
     representation = str(relation)
     serialised = json.loads(representation)
     self.assertEqual(relation, Relation.deserialize(serialised))
Exemplo n.º 3
0
 def test_deserialization(self):
     """
     Tests deserializing an ID object
     :return: None
     """
     source = Id({IdType.MYANIMELIST: 1})
     dest = Id({IdType.MYANIMELIST: 2})
     data = {
         "source": source.serialize(),
         "source_type": "ANIME",
         "dest": dest.serialize(),
         "dest_type": "MANGA",
         "type": "SEQUEL"
     }
     self.assertEqual(
         Relation.deserialize(data),
         Relation(source, MediaType.ANIME, dest, MediaType.MANGA,
                  RelationType.SEQUEL))
Exemplo n.º 4
0
 def test_invalid_deserialization(self):
     """
     Tests that invalid serialized data raises ValueErrors when deserialized
     :return: None
     """
     source = Id({IdType.MYANIMELIST: 1}).serialize()
     dest = Id({IdType.MYANIMELIST: 2}).serialize()
     for data in [{
             "source": source,
             "dest": dest,
             "type": "Sequel",
             "source_type": "ANIME",
             "dest_type": "MANGA"
     }, {
             "source": source,
             "dest": None,
             "type": "SEQUEL",
             "source_type": "ANIME",
             "dest_type": "MANGA"
     }, {
             "source": None,
             "dest": dest,
             "type": "SEQUEL",
             "source_type": "ANIME",
             "dest_type": "MANGA"
     }, {
             "source": source,
             "dest": dest,
             "source_type": "ANIME",
             "dest_type": "MANGA"
     }, {
             "source": source,
             "type": "SEQUEL",
             "source_type": "ANIME",
             "dest_type": "MANGA"
     }, {
             "dest": dest,
             "type": "SEQUEL",
             "source_type": "ANIME",
             "dest_type": "MANGA"
     }, {
             "source": 1,
             "dest": dest,
             "type": "Sequel",
             "source_type": "ANIME",
             "dest_type": "MANGA"
     }, {
             "source": source,
             "dest": 2,
             "type": "Sequel",
             "source_type": "ANIME",
             "dest_type": "MANGA"
     }, {
             "source": source,
             "dest": dest,
             "type": "Sequel"
     }, []]:
         try:
             Relation.deserialize(data)
             self.fail()
         except (ValueError, TypeError):
             pass