def test_remote_rel_changes_can_be_pulled(self): batch = Batch(self.graph) a = batch.create_node() b = batch.create_node() ab = batch.create_rel(a, b, "KNOWS") result = batch.submit() alice = next(result) bob = next(result) alice_bob = next(result) local = Rel("KNOWS") local.bind(self.graph, id=alice_bob._id) local.pull() assert local.type == alice_bob.type assert local.properties == alice_bob.properties
def test_local_rel_changes_can_be_pushed(self): batch = Batch(self.graph) a = batch.create_node() b = batch.create_node() ab = batch.create_rel(a, b, "KNOWS") result = batch.submit() alice = next(result) bob = next(result) alice_bob = next(result) local = Rel("KNOWS", since=1999) local.bind(self.graph, id=alice_bob._id) local.push() remote = Batch.single(self.graph, Batch.get_rel, local._id) assert remote.type == local.type assert remote.properties == local.properties
def test_rel_type(self): rel = Rel("KNOWS") assert rel.type == "KNOWS"
def test_unequal_rels(self): rel_1 = Rel("KNOWS", since=1999) rel_2 = Rel("KNOWS", since=2000) assert rel_1 != rel_2
def test_equal_rels(self): rel_1 = Rel("KNOWS", since=1999) rel_2 = Rel("KNOWS", since=1999) assert rel_1 == rel_2
def test_can_represent_rel_with_type_and_properties(self): rel = Rel("KNOWS", since=1999) string = repr(rel) assert string == '-[:KNOWS {"since":1999}]->'
def test_can_represent_rel_with_type(self): rel = Rel("KNOWS") string = repr(rel) assert string == '-[:KNOWS]->'
def test_can_construct_rel_with_type_and_properties(self): rel = Rel("KNOWS", since=1999) assert rel.type == "KNOWS" assert rel.properties == {"since": 1999}
def test_can_construct_rel_with_type(self): rel = Rel("KNOWS") assert rel.type == "KNOWS" assert rel.properties == {}
def test_casting_string_and_dict_will_return_rel_with_properties(self): type = "KNOWS" properties = {"since": 1999} casted = Rel.cast((type, properties)) assert casted == Rel(type, **properties)
def test_casting_string_will_return_rel_with_type(self): type = "KNOWS" casted = Rel.cast(type) assert casted == Rel(type)
def test_casting_rel_will_return_same(self): rel = Rel("KNOWS", since=1999) casted = Rel.cast(rel) assert casted is rel
def test_can_hydrate_rel_with_type_and_properties(self): hydrated = yaml.load( '!Rel {"type":"KNOWS","properties":{"since":1999}}') assert hydrated == Rel("KNOWS", since=1999) assert not hydrated.bound
def test_can_hydrate_rel_with_type(self): hydrated = yaml.load('!Rel {"type":"KNOWS"}') assert hydrated == Rel("KNOWS") assert not hydrated.bound