Beispiel #1
0
 def test_can_write_relationship_with_name(self):
     r = Relationship(Node(name="Fred"), "LIVES WITH", Node(name="Wilma"))
     string = StringIO()
     writer = CypherWriter(string)
     writer.write_relationship(r, name="fred_wilma")
     written = string.getvalue()
     assert written == '(fred)-[fred_wilma:`LIVES WITH`]->(wilma)'
Beispiel #2
0
 def test_can_write_node_with_labels_and_properties(self):
     node = Node("Dark Brown", "Chicken", name="Gertrude", age=3)
     string = StringIO()
     writer = CypherWriter(string)
     writer.write(node)
     written = string.getvalue()
     assert written == '(gertrude:Chicken:`Dark Brown` {age:3,name:"Gertrude"})'
Beispiel #3
0
 def test_can_write_node_with_properties(self):
     node = Node(name="Gertrude", age=3)
     string = StringIO()
     writer = CypherWriter(string)
     writer.write(node)
     written = string.getvalue()
     assert written == '(gertrude {age:3,name:"Gertrude"})'
Beispiel #4
0
 def test_can_write_node_with_labels(self):
     node = Node("Dark Brown", "Chicken")
     node.__name__ = "a"
     string = StringIO()
     writer = CypherWriter(string)
     writer.write(node)
     written = string.getvalue()
     assert written == '(a:Chicken:`Dark Brown`)'
Beispiel #5
0
 def test_can_write_simple_node(self):
     node = Node()
     node.__name__ = "a"
     string = StringIO()
     writer = CypherWriter(string)
     writer.write(node)
     written = string.getvalue()
     assert written == "(a)"
Beispiel #6
0
 def test_can_write_relationship_with_properties(self):
     r = Relationship(Node(name="Fred"), ("LIVES WITH", {
         "place": "Bedrock"
     }), Node(name="Wilma"))
     string = StringIO()
     writer = CypherWriter(string)
     writer.write(r)
     written = string.getvalue()
     assert written == '(fred)-[:`LIVES WITH` {place:"Bedrock"}]->(wilma)'
Beispiel #7
0
 def test_can_write_simple_path(self):
     alice, bob, carol, dave = Node(name="Alice"), Node(name="Bob"), \
                               Node(name="Carol"), Node(name="Dave")
     path = Path(alice, "LOVES", bob, Relationship(carol, "HATES", bob),
                 carol, "KNOWS", dave)
     string = StringIO()
     writer = CypherWriter(string)
     writer.write(path)
     written = string.getvalue()
     assert written == "(alice)-[:LOVES]->(bob)<-[:HATES]-(carol)-[:KNOWS]->(dave)"
Beispiel #8
0
 def test_can_write_simple_relationship(self):
     a = Node()
     b = Node()
     r = Relationship(a, "KNOWS", b)
     a.__name__ = "a"
     b.__name__ = "b"
     string = StringIO()
     writer = CypherWriter(string)
     writer.write(r)
     written = string.getvalue()
     assert written == "(a)-[:KNOWS]->(b)"
Beispiel #9
0
 def test_maps_do_not_contain_private_entries(self):
     string = StringIO()
     writer = CypherWriter(string)
     writer.write({"visible": True, "_visible": False})
     written = string.getvalue()
     assert written == '{visible:true}'
Beispiel #10
0
 def test_can_write_mapping(self):
     string = StringIO()
     writer = CypherWriter(string)
     writer.write({"one": "eins", "two": "zwei", "three": "drei"})
     written = string.getvalue()
     assert written == '{one:"eins",three:"drei",two:"zwei"}'
Beispiel #11
0
 def test_can_write_array(self):
     string = StringIO()
     writer = CypherWriter(string)
     writer.write([1, 1, 2, 3, 5, 8, 13])
     written = string.getvalue()
     assert written == "[1,1,2,3,5,8,13]"
Beispiel #12
0
 def test_can_write_identifier_with_odd_chars(self):
     string = StringIO()
     writer = CypherWriter(string)
     writer.write_identifier("foo bar")
     written = string.getvalue()
     assert written == "`foo bar`"
Beispiel #13
0
 def test_cannot_write_none_identifier(self):
     string = StringIO()
     writer = CypherWriter(string)
     with self.assertRaises(ValueError):
         writer.write_identifier(None)
Beispiel #14
0
 def test_can_write_identifier_containing_back_ticks(self):
     string = StringIO()
     writer = CypherWriter(string)
     writer.write_identifier("foo `bar`")
     written = string.getvalue()
     assert written == "`foo ``bar```"
Beispiel #15
0
 def test_maps_can_contain_private_entries_if_enabled(self):
     string = StringIO()
     writer = CypherWriter(string)
     writer.write_map({"visible": True, "_visible": True}, private=True)
     written = string.getvalue()
     assert written == '{_visible:true,visible:true}'
Beispiel #16
0
 def test_writing_none_writes_nothing(self):
     string = StringIO()
     writer = CypherWriter(string)
     writer.write(None)
     written = string.getvalue()
     assert written == ""
Beispiel #17
0
 def test_can_write_simple_identifier(self):
     string = StringIO()
     writer = CypherWriter(string)
     writer.write_identifier("foo")
     written = string.getvalue()
     assert written == "foo"