Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_can_create_nodes_and_relationship_4(self):
self.graph.delete_all()
with self.graph.begin() as tx:
a = Node()
b = Node()
c = Node()
ab = Relationship(a, "TO", b)
bc = Relationship(b, "TO", c)
ca = Relationship(c, "TO", a)
tx.create(ab | bc | ca)
self.assertEqual(a.graph, self.graph)
self.assertIsNotNone(a.identity)
self.assertEqual(b.graph, self.graph)
self.assertIsNotNone(b.identity)
self.assertEqual(c.graph, self.graph)
self.assertIsNotNone(c.identity)
self.assertEqual(ab.graph, self.graph)
self.assertIsNotNone(ab.identity)
assert ab.start_node == a
assert ab.end_node == b
self.assertEqual(bc.graph, self.graph)
self.assertIsNotNone(bc.identity)
assert bc.start_node == b
assert bc.end_node == c
self.assertEqual(ca.graph, self.graph)
def test_construction_from_no_arguments(self):
with self.assertRaises(TypeError):
_ = Relationship()
def test_can_create_nodes_and_relationship_2(self):
self.graph.delete_all()
with self.graph.begin() as tx:
a = Node("Person", name="Alice")
b = Node("Person", name="Bob")
tx.create(a)
tx.create(b)
r = Relationship(a, "KNOWS", b, since=1999)
tx.create(r)
self.assertEqual(a.graph, self.graph)
self.assertIsNotNone(a.identity)
self.assertEqual(b.graph, self.graph)
self.assertIsNotNone(b.identity)
self.assertEqual(r.graph, self.graph)
self.assertIsNotNone(r.identity)
assert r.start_node == a
assert r.end_node == b
self.assertEqual(len(self.graph.nodes), 2)
self.assertEqual(len(self.graph.relationships), 1)
def test_construction_from_three_arguments(self):
rel = Relationship(alice, "KNOWS", bob)
assert rel.start_node is alice
assert rel.end_node is bob
self.assertIs(type(rel), KNOWS)
def setUp(self):
self.graph.delete_all()
self.alice = Node(name="Alice")
self.bob = Node(name="Bob")
self.carol = Node(name="Carol")
s = (Relationship(self.alice, "LOVES", self.bob) |
Relationship(self.bob, "LOVES", self.alice) |
Relationship(self.alice, "KNOWS", self.bob) |
Relationship(self.bob, "KNOWS", self.alice) |
Relationship(self.bob, "KNOWS", self.carol) |
Relationship(self.carol, "KNOWS", self.bob))
self.graph.create(s)
def setUp(self):
self.graph.delete_all()
self.alice = Node(name="Alice")
self.bob = Node(name="Bob")
self.carol = Node(name="Carol")
s = (Relationship(self.alice, "LOVES", self.bob) |
Relationship(self.bob, "LOVES", self.alice) |
Relationship(self.alice, "KNOWS", self.bob) |
Relationship(self.bob, "KNOWS", self.alice) |
Relationship(self.bob, "KNOWS", self.carol) |
Relationship(self.carol, "KNOWS", self.bob))
self.graph.create(s)
def test_construction_from_two_node_arguments(self):
rel = Relationship(alice, bob)
assert rel.start_node is alice
assert rel.end_node is bob
self.assertEqual(type(rel).__name__, "Relationship")
def setUp(self):
self.graph.delete_all()
self.alice = Node(name="Alice")
self.bob = Node(name="Bob")
self.carol = Node(name="Carol")
s = (Relationship(self.alice, "LOVES", self.bob) |
Relationship(self.bob, "LOVES", self.alice) |
Relationship(self.alice, "KNOWS", self.bob) |
Relationship(self.bob, "KNOWS", self.alice) |
Relationship(self.bob, "KNOWS", self.carol) |
Relationship(self.carol, "KNOWS", self.bob))
self.graph.create(s)
n.append(None)
elif isinstance(value, string_types):
n.append(value)
else:
n.append(Node.cast(value))
num_args = len(n)
if num_args == 0:
raise TypeError("Relationships must specify at least one endpoint")
elif num_args == 1:
# Relationship(a)
n = (n[0], n[0])
elif num_args == 2:
if n[1] is None or isinstance(n[1], string_types):
# Relationship(a, "TO")
self.__class__ = Relationship.type(n[1])
n = (n[0], n[0])
else:
# Relationship(a, b)
n = (n[0], n[1])
elif num_args == 3:
# Relationship(a, "TO", b)
self.__class__ = Relationship.type(n[1])
n = (n[0], n[2])
else:
raise TypeError("Hyperedges not supported")
Entity.__init__(self, (n[0], self, n[1]), properties)
self._stale = set()
def __eq__(self, other):
if self is other:
return True
try:
if any(x is None for x in [self.graph, other.graph, self.identity, other.identity]):
try:
return type(self) is type(other) and list(self.nodes) == list(other.nodes) and dict(self) == dict(other)
except (AttributeError, TypeError):
return False
return issubclass(type(self), Relationship) and issubclass(type(other), Relationship) and self.graph == other.graph and self.identity == other.identity
except (AttributeError, TypeError):
return False