def test_add_object(): el = Jelm() el.add_object({"type": "node", "id": "n1"}) el.add_object(Node(id="n2")) el.add_object({"type": "edge", "source": "n1", "target": "n2"}) el.add_object(Node(id="n3", attributes={"priority": "low"})) with pytest.raises(ValueError): el.add_object({"no": "type"}) with pytest.raises(ValueError): el.add_object({"type": "wrong"}) with pytest.raises(ValueError): el.add_object(10) el.add_edge("n3", "n2") el.add_node("n4", {"order": "latest"}) assert len(set([type(o) for o in el.objects])) > 1 assert isinstance(el.objects[0], Node) assert isinstance(el.objects[2], Edge)
def add_jelm_nodes_to_instance(self, el: Jelm): record_atts = self.attributes.copy() if not self.teach_jelm_cls.is_edge: for add_edge_dic in self.teach_jelm_cls.additional_edges: attid = add_edge_dic["attid"] try: record_atts.pop(attid) except KeyError as e: pass el.add_node( id=self.jelm_id, attributes={ "pk": self.django_id, "model": self.model_name, **record_atts, }, )