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)'
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"})'
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"})'
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`)'
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)"
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)'
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)"
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)"
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}'
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"}'
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]"
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`"
def test_cannot_write_none_identifier(self): string = StringIO() writer = CypherWriter(string) with self.assertRaises(ValueError): writer.write_identifier(None)
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```"
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}'
def test_writing_none_writes_nothing(self): string = StringIO() writer = CypherWriter(string) writer.write(None) written = string.getvalue() assert written == ""
def test_can_write_simple_identifier(self): string = StringIO() writer = CypherWriter(string) writer.write_identifier("foo") written = string.getvalue() assert written == "foo"