diff options
author | Matthias Baumgartner <dev@igsor.net> | 2022-12-18 14:16:40 +0100 |
---|---|---|
committer | Matthias Baumgartner <dev@igsor.net> | 2022-12-18 14:16:40 +0100 |
commit | 8ed8dbb4010a9a75cf6e61d185327825fe783776 (patch) | |
tree | b7bd1921d092584535630e571872835b7401411a | |
parent | a5ce14c8bbd55f4a078ceea9384cda56bf42a18b (diff) | |
download | bsfs-8ed8dbb4010a9a75cf6e61d185327825fe783776.tar.gz bsfs-8ed8dbb4010a9a75cf6e61d185327825fe783776.tar.bz2 bsfs-8ed8dbb4010a9a75cf6e61d185327825fe783776.zip |
Graph.node interface
-rw-r--r-- | bsfs/graph/graph.py | 11 | ||||
-rw-r--r-- | test/graph/test_graph.py | 10 |
2 files changed, 21 insertions, 0 deletions
diff --git a/bsfs/graph/graph.py b/bsfs/graph/graph.py index 87f7a31..b7b9f1c 100644 --- a/bsfs/graph/graph.py +++ b/bsfs/graph/graph.py @@ -99,4 +99,15 @@ class Graph(): # NOTE: Nodes constructor materializes guids. return _nodes.Nodes(self._backend, self._user, type_, guids) + def node(self, node_type: URI, guid: URI) -> _nodes.Nodes: + """Return node *guid* of type *node_type* as a `bsfs.graph.Nodes` instance. + + Note that the *guids* need not to exist (however, the *node_type* has + to be part of the schema). An inexistent guid will be created (using + *node_type*) once some data is assigned to them. + + """ + type_ = self.schema.node(node_type) + return _nodes.Nodes(self._backend, self._user, type_, {guid}) + ## EOF ## diff --git a/test/graph/test_graph.py b/test/graph/test_graph.py index f8e107d..33cf6aa 100644 --- a/test/graph/test_graph.py +++ b/test/graph/test_graph.py @@ -74,6 +74,16 @@ class TestGraph(unittest.TestCase): self.assertEqual(graph.schema, self.backend.schema) self.assertRaises(AttributeError, setattr, graph, 'schema', None) + def test_node(self): + graph = Graph(self.backend, self.user) + guid = URI('http://example.com/me/entity#1234') + # returns a Nodes instance + self.assertEqual( + graph.node(ns.bsfs.Entity, guid), + Nodes(self.backend, self.user, graph.schema.node(ns.bsfs.Entity), {guid})) + # node_type must be in the schema + self.assertRaises(KeyError, graph.node, ns.bsfs.Invalid, guid) + def test_nodes(self): graph = Graph(self.backend, self.user) guids = {URI('http://example.com/me/entity#1234'), URI('http://example.com/me/entity#4321')} |