def test_can_push_property_updates_on_new_object(self): # given films_acted_in = self.new_keanu_acted_in() self.graph.pull(films_acted_in) # when bill_and_ted = Film("Bill & Ted's Excellent Adventure") films_acted_in.update(bill_and_ted, good=True) self.graph.push(films_acted_in) # then del films_acted_in self.graph.node_cache.clear() self.graph.relationship_cache.clear() films_acted_in = self.new_keanu_acted_in() self.graph.pull(films_acted_in) film_titles = set(film.title for film in films_acted_in) self.assertEqual( film_titles, { "The Devil's Advocate", 'The Matrix Reloaded', "Something's Gotta Give", 'The Matrix', 'The Replacements', 'The Matrix Revolutions', 'Johnny Mnemonic', "Bill & Ted's Excellent Adventure" }) # and good = films_acted_in.get(bill_and_ted, "good") self.assertTrue(good)
def test_does_not_contain_object(movie_repo): # given filmography = movie_repo.get(Person, "Keanu Reeves").acted_in # then bill_and_ted = Film("Bill & Ted's Excellent Adventure") assert bill_and_ted not in filmography
def test_contains_object(movie_repo): # given filmography = movie_repo.get(Person, "Keanu Reeves").acted_in # then matrix_reloaded = Film.match(movie_repo, "The Matrix Reloaded").first() assert matrix_reloaded in filmography
def test_can_push_property_updates_on_new_object(movie_repo): # given filmography = movie_repo.get(Person, "Keanu Reeves").acted_in # when bill_and_ted = Film("Bill & Ted's Excellent Adventure") filmography.add(bill_and_ted, good=True) movie_repo.save(filmography) # then del filmography movie_repo.graph.node_cache.clear() movie_repo.graph.relationship_cache.clear() filmography = movie_repo.get(Person, "Keanu Reeves").acted_in movie_repo.reload(filmography) film_titles = set(film.title for film in filmography) assert film_titles == { "The Devil's Advocate", 'The Matrix Reloaded', "Something's Gotta Give", 'The Matrix', 'The Replacements', 'The Matrix Revolutions', 'Johnny Mnemonic', "Bill & Ted's Excellent Adventure" } # and good = filmography.get(bill_and_ted, "good") assert good
def test_does_not_contain_object(self): # given films_acted_in = self.new_keanu_acted_in() self.graph.pull(films_acted_in) # then bill_and_ted = Film("Bill & Ted's Excellent Adventure") self.assertNotIn(bill_and_ted, films_acted_in)
def test_contains_object(self): # given films_acted_in = self.new_keanu_acted_in() self.graph.pull(films_acted_in) # then matrix_reloaded = Film.match(self.graph, "The Matrix Reloaded").first() self.assertIn(matrix_reloaded, films_acted_in)
def test_does_not_contain_object(self): # given films_acted_in = self.new_keanu_acted_in() films_acted_in.__db_pull__(self.graph) # then bill_and_ted = Film("Bill & Ted's Excellent Adventure") assert bill_and_ted not in films_acted_in
def test_contains_object(self): # given films_acted_in = self.new_keanu_acted_in() films_acted_in.__db_pull__(self.graph) # then matrix_reloaded = Film.select(self.graph, "The Matrix Reloaded").first() assert matrix_reloaded in films_acted_in
def test_can_get_relationship_property(movie_repo): # given filmography = movie_repo.get(Person, "Keanu Reeves").acted_in matrix_reloaded = Film('The Matrix Reloaded') # then roles = filmography.get(matrix_reloaded, "roles") assert roles == ["Neo"]
def test_can_get_relationship_property_from_default(movie_repo): # given filmography = movie_repo.get(Person, "Keanu Reeves").acted_in matrix_reloaded = Film('The Matrix Reloaded') # then foo = filmography.get(matrix_reloaded, "foo", "bar") assert foo == "bar"
def test_can_get_relationship_property_from_default_and_unknown_object(movie_repo): # given filmography = movie_repo.get(Person, "Keanu Reeves").acted_in bill_and_ted = Film("Bill & Ted's Excellent Adventure") # then foo = filmography.get(bill_and_ted, "foo", "bar") assert foo == "bar"
def test_can_get_relationship_property_from_default_and_unknown_object(self): # given films_acted_in = self.new_keanu_acted_in() films_acted_in.__db_pull__(self.graph) bill_and_ted = Film("Bill & Ted's Excellent Adventure") # then foo = films_acted_in.get(bill_and_ted, "foo", "bar") assert foo == "bar"
def test_can_get_relationship_property_from_default(self): # given films_acted_in = self.new_keanu_acted_in() films_acted_in.__db_pull__(self.graph) matrix_reloaded = Film('The Matrix Reloaded') # then foo = films_acted_in.get(matrix_reloaded, "foo", "bar") assert foo == "bar"
def test_can_get_relationship_property(self): # given films_acted_in = self.new_keanu_acted_in() films_acted_in.__db_pull__(self.graph) matrix_reloaded = Film('The Matrix Reloaded') # then roles = films_acted_in.get(matrix_reloaded, "roles") assert roles == ["Neo"]
def test_can_add_object(self): films_acted_in = self.new_keanu_acted_in() films_acted_in.__db_pull__(self.graph) bill_and_ted = Film("Bill & Ted's Excellent Adventure") films_acted_in.add(bill_and_ted) film_titles = set(film.title for film in films_acted_in) assert film_titles == {"The Devil's Advocate", 'The Matrix Reloaded', "Something's Gotta Give", 'The Matrix', 'The Replacements', 'The Matrix Revolutions', 'Johnny Mnemonic', "Bill & Ted's Excellent Adventure"}
def test_can_get_relationship_property_from_default(self): # given films_acted_in = self.new_keanu_acted_in() self.graph.pull(films_acted_in) matrix_reloaded = Film('The Matrix Reloaded') # then foo = films_acted_in.get(matrix_reloaded, "foo", "bar") self.assertEqual(foo, "bar")
def test_can_get_relationship_property(self): # given films_acted_in = self.new_keanu_acted_in() self.graph.pull(films_acted_in) matrix_reloaded = Film('The Matrix Reloaded') # then roles = films_acted_in.get(matrix_reloaded, "roles") self.assertEqual(roles, ["Neo"])
def test_can_add_object(movie_repo): filmography = movie_repo.get(Person, "Keanu Reeves").acted_in bill_and_ted = Film("Bill & Ted's Excellent Adventure") filmography.add(bill_and_ted) film_titles = set(film.title for film in filmography) assert film_titles == {"The Devil's Advocate", 'The Matrix Reloaded', "Something's Gotta Give", 'The Matrix', 'The Replacements', 'The Matrix Revolutions', 'Johnny Mnemonic', "Bill & Ted's Excellent Adventure"}
def test_can_add_property_to_existing_relationship(movie_repo): keanu = movie_repo.get(Person, "Keanu Reeves") johnny_mnemonic = Film.match(movie_repo, "Johnny Mnemonic").first() keanu.acted_in.add(johnny_mnemonic, foo="bar") movie_repo.save(keanu) node_id = keanu.__node__.identity johnny_foo = movie_repo.graph.evaluate("MATCH (a:Person)-[ab:ACTED_IN]->(b) " "WHERE id(a) = $x AND b.title = 'Johnny Mnemonic' " "RETURN ab.foo", x=node_id) assert johnny_foo == "bar"
def test_can_add_property_to_existing_relationship(self): keanu = Person.select(self.graph, "Keanu Reeves").first() johnny_mnemonic = Film.select(self.graph, "Johnny Mnemonic").first() keanu.acted_in.add(johnny_mnemonic, foo="bar") self.graph.push(keanu) remote_node = remote(keanu.__ogm__.node) johnny_foo = self.graph.evaluate("MATCH (a:Person)-[ab:ACTED_IN]->(b) " "WHERE id(a) = {x} AND b.title = 'Johnny Mnemonic' " "RETURN ab.foo", x=remote_node._id) assert johnny_foo == "bar"
def test_can_add_related_object_with_properties_and_push(self): keanu = Person.select(self.graph, "Keanu Reeves").first() bill_and_ted = Film("Bill & Ted's Excellent Adventure") keanu.acted_in.add(bill_and_ted, roles=['Ted "Theodore" Logan']) self.graph.push(keanu) remote_node = remote(keanu.__ogm__.node) films = {title: roles for title, roles in self.graph.run("MATCH (a:Person)-[ab:ACTED_IN]->(b) " "WHERE id(a) = {x} " "RETURN b.title, ab.roles", x=remote_node._id)} bill_and_ted_roles = films["Bill & Ted's Excellent Adventure"] assert bill_and_ted_roles == ['Ted "Theodore" Logan']
def test_can_remove_related_object_and_push(self): keanu = Person.select(self.graph, "Keanu Reeves").first() johnny_mnemonic = Film.select(self.graph, "Johnny Mnemonic").first() keanu.acted_in.remove(johnny_mnemonic) self.graph.push(keanu) remote_node = remote(keanu.__ogm__.node) film_titles = set(title for title, in self.graph.run("MATCH (a:Person)-[:ACTED_IN]->(b) " "WHERE id(a) = {x} " "RETURN b.title", x=remote_node._id)) assert film_titles == {"The Devil's Advocate", 'The Matrix Reloaded', "Something's Gotta Give", 'The Matrix', 'The Replacements', 'The Matrix Revolutions'}
def test_can_remove_related_object_and_push(movie_repo): keanu = movie_repo.get(Person, "Keanu Reeves") johnny_mnemonic = Film.match(movie_repo, "Johnny Mnemonic").first() keanu.acted_in.remove(johnny_mnemonic) movie_repo.save(keanu) node_id = keanu.__node__.identity film_titles = set(title for title, in movie_repo.graph.run("MATCH (a:Person)-[:ACTED_IN]->(b) " "WHERE id(a) = $x " "RETURN b.title", x=node_id)) assert film_titles == {"The Devil's Advocate", 'The Matrix Reloaded', "Something's Gotta Give", 'The Matrix', 'The Replacements', 'The Matrix Revolutions'}
def test_can_add_related_object_with_properties_and_push(movie_repo): keanu = movie_repo.get(Person, "Keanu Reeves") bill_and_ted = Film("Bill & Ted's Excellent Adventure") keanu.acted_in.add(bill_and_ted, roles=['Ted "Theodore" Logan']) movie_repo.save(keanu) node_id = keanu.__node__.identity films = {title: roles for title, roles in movie_repo.graph.run("MATCH (a:Person)-[ab:ACTED_IN]->(b) " "WHERE id(a) = $x " "RETURN b.title, ab.roles", x=node_id)} bill_and_ted_roles = films["Bill & Ted's Excellent Adventure"] assert bill_and_ted_roles == ['Ted "Theodore" Logan']
def test_can_add_property_to_existing_relationship(self): keanu = Person.match(self.graph, "Keanu Reeves").first() johnny_mnemonic = Film.match(self.graph, "Johnny Mnemonic").first() keanu.acted_in.add(johnny_mnemonic, foo="bar") self.graph.push(keanu) node_id = keanu.__node__.identity johnny_foo = self.graph.evaluate( "MATCH (a:Person)-[ab:ACTED_IN]->(b) " "WHERE id(a) = {x} AND b.title = 'Johnny Mnemonic' " "RETURN ab.foo", x=node_id) self.assertEqual(johnny_foo, "bar")
def test_can_add_related_object_and_push(self): keanu = Person.select(self.graph, "Keanu Reeves").first() bill_and_ted = Film("Bill & Ted's Excellent Adventure") keanu.acted_in.add(bill_and_ted) self.graph.push(keanu) remote_node = remote(keanu.__ogm__.node) film_titles = set(title for title, in self.graph.run("MATCH (a:Person)-[:ACTED_IN]->(b) " "WHERE id(a) = {x} " "RETURN b.title", x=remote_node._id)) assert film_titles == {"The Devil's Advocate", 'The Matrix Reloaded', "Something's Gotta Give", 'The Matrix', 'The Replacements', 'The Matrix Revolutions', 'Johnny Mnemonic', "Bill & Ted's Excellent Adventure"}
def test_can_add_related_object_and_push(movie_repo): keanu = movie_repo.get(Person, "Keanu Reeves") bill_and_ted = Film("Bill & Ted's Excellent Adventure") keanu.acted_in.add(bill_and_ted) movie_repo.save(keanu) node_id = keanu.__node__.identity film_titles = set(title for title, in movie_repo.graph.run("MATCH (a:Person)-[:ACTED_IN]->(b) " "WHERE id(a) = $x " "RETURN b.title", x=node_id)) assert film_titles == {"The Devil's Advocate", 'The Matrix Reloaded', "Something's Gotta Give", 'The Matrix', 'The Replacements', 'The Matrix Revolutions', 'Johnny Mnemonic', "Bill & Ted's Excellent Adventure"}
def test_can_remove_object(movie_repo): # given filmography = movie_repo.get(Person, "Keanu Reeves").acted_in # when matrix_reloaded = Film.match(movie_repo, "The Matrix Reloaded").first() filmography.remove(matrix_reloaded) # then film_titles = set(film.title for film in filmography) assert film_titles == {"The Devil's Advocate", "Something's Gotta Give", 'The Matrix', 'The Replacements', 'The Matrix Revolutions', 'Johnny Mnemonic'}
def test_can_pull_with_incoming_relationships(self): # given matrix = Film.select(self.graph, "The Matrix").first() remote_node = remote(matrix.__ogm__.node) self.graph.run("MATCH (a:Movie)<-[r:ACTED_IN]-(b) WHERE id(a) = {x} AND b.name = 'Emil Eifrem' DELETE r", x=remote_node._id) # when self.graph.pull(matrix) # then names = set(a.name for a in matrix.actors) assert names == {'Keanu Reeves', 'Carrie-Anne Moss', 'Hugo Weaving', 'Laurence Fishburne'}
def test_can_pull_with_incoming_relationships(movie_repo): # given matrix = Film.match(movie_repo, "The Matrix").first() node_id = matrix.__node__.identity movie_repo.graph.run("MATCH (a:Movie)<-[r:ACTED_IN]-(b) " "WHERE id(a) = $x AND b.name = 'Emil Eifrem' DELETE r", x=node_id) # when movie_repo.reload(matrix) # then names = set(a.name for a in matrix.actors) assert names, {'Keanu Reeves', 'Carrie-Anne Moss', 'Hugo Weaving' == 'Laurence Fishburne'}