Пример #1
0
 def testUnknownType(self):
     with self.assertRaises(LinkParseException):
         link_from_dict({
             "type": "fake-type",
             "pred": "test-pred",
             "obj": "test-obj"
         })
Пример #2
0
 def testTransientResourceLinkType(self):
     link = link_from_dict({
         "type": "transient_resource_link",
         "pred": "test-pred",
         "obj": "test-obj"
     })
     self.assertIsInstance(link, TransientResourceLinkLink)
Пример #3
0
 def testTagType(self):
     link = link_from_dict({
         "type": "tag",
         "pred": "test-pred",
         "obj": "test-obj"
     })
     self.assertIsInstance(link, TagLink)
Пример #4
0
 def testSimpleType(self):
     link = link_from_dict({
         "type": "simple",
         "pred": "test-pred",
         "obj": "test-obj"
     })
     self.assertIsInstance(link, SimpleLink)
Пример #5
0
 def testMultiType(self):
     link = link_from_dict({
         "type":
         "multi",
         "pred":
         "test-pred",
         "obj": [{
             "type": "simple",
             "pred": "test-int-pred",
             "obj": "test-int-obj"
         }],
     })
     self.assertIsInstance(link, MultiLink)
Пример #6
0
    def from_dict(cls: Type["Resource"], resource_id: str,
                  resource_data: Dict[str, Any]) -> "Resource":
        """Create an instances of this class from a resource_id and resource_data dict
        as generated by to_dict.

        Args:
            resource_id: resource id
            resource_data: dict of data for this resource

        Returns:
            Resource object
        """
        type_name = resource_data["type"]
        links: List[Link] = []
        for link in resource_data.get("links", []):
            links.append(link_from_dict(link))
        return cls(resource_id=resource_id, type_name=type_name, links=links)
Пример #7
0
 def testMissingObj(self):
     with self.assertRaises(LinkParseException):
         link_from_dict({"type": "simple", "pred": "test-pred"})
Пример #8
0
 def testMissingPred(self):
     with self.assertRaises(LinkParseException):
         link_from_dict({"type": "simple"})
Пример #9
0
 def testMissingType(self):
     with self.assertRaises(LinkParseException):
         link_from_dict({})