def testUnknownType(self): with self.assertRaises(LinkParseException): link_from_dict({ "type": "fake-type", "pred": "test-pred", "obj": "test-obj" })
def testTransientResourceLinkType(self): link = link_from_dict({ "type": "transient_resource_link", "pred": "test-pred", "obj": "test-obj" }) self.assertIsInstance(link, TransientResourceLinkLink)
def testTagType(self): link = link_from_dict({ "type": "tag", "pred": "test-pred", "obj": "test-obj" }) self.assertIsInstance(link, TagLink)
def testSimpleType(self): link = link_from_dict({ "type": "simple", "pred": "test-pred", "obj": "test-obj" }) self.assertIsInstance(link, SimpleLink)
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)
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)
def testMissingObj(self): with self.assertRaises(LinkParseException): link_from_dict({"type": "simple", "pred": "test-pred"})
def testMissingPred(self): with self.assertRaises(LinkParseException): link_from_dict({"type": "simple"})
def testMissingType(self): with self.assertRaises(LinkParseException): link_from_dict({})