summaryrefslogtreecommitdiff
path: root/tests/test_graph_utils/test_node.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_graph_utils/test_node.py')
-rw-r--r--tests/test_graph_utils/test_node.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/test_graph_utils/test_node.py b/tests/test_graph_utils/test_node.py
new file mode 100644
index 0000000..faf8ab6
--- /dev/null
+++ b/tests/test_graph_utils/test_node.py
@@ -0,0 +1,52 @@
+import pytest
+
+from redis.commands.graph import node
+
+
+@pytest.fixture
+def fixture():
+ no_args = node.Node()
+ no_props = node.Node(node_id=1, alias="alias", label="l")
+ props_only = node.Node(properties={"a": "a", "b": 10})
+ no_label = node.Node(node_id=1, alias="alias", properties={"a": "a"})
+ multi_label = node.Node(node_id=1, alias="alias", label=["l", "ll"])
+ return no_args, no_props, props_only, no_label, multi_label
+
+
+@pytest.mark.redismod
+def test_toString(fixture):
+ no_args, no_props, props_only, no_label, multi_label = fixture
+ assert no_args.toString() == ""
+ assert no_props.toString() == ""
+ assert props_only.toString() == '{a:"a",b:10}'
+ assert no_label.toString() == '{a:"a"}'
+ assert multi_label.toString() == ""
+
+
+@pytest.mark.redismod
+def test_stringify(fixture):
+ no_args, no_props, props_only, no_label, multi_label = fixture
+ assert str(no_args) == "()"
+ assert str(no_props) == "(alias:l)"
+ assert str(props_only) == '({a:"a",b:10})'
+ assert str(no_label) == '(alias{a:"a"})'
+ assert str(multi_label) == "(alias:l:ll)"
+
+
+@pytest.mark.redismod
+def test_comparision(fixture):
+ no_args, no_props, props_only, no_label, multi_label = fixture
+
+ assert node.Node() == node.Node()
+ assert node.Node(node_id=1) == node.Node(node_id=1)
+ assert node.Node(node_id=1) != node.Node(node_id=2)
+ assert node.Node(node_id=1, alias="a") == node.Node(node_id=1, alias="b")
+ assert node.Node(node_id=1, alias="a") == node.Node(node_id=1, alias="a")
+ assert node.Node(node_id=1, label="a") == node.Node(node_id=1, label="a")
+ assert node.Node(node_id=1, label="a") != node.Node(node_id=1, label="b")
+ assert node.Node(node_id=1, alias="a", label="l") == node.Node(
+ node_id=1, alias="a", label="l"
+ )
+ assert node.Node(alias="a", label="l") != node.Node(alias="a", label="l1")
+ assert node.Node(properties={"a": 10}) == node.Node(properties={"a": 10})
+ assert node.Node() != node.Node(properties={"a": 10})