Beispiel #1
0
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
Beispiel #2
0
    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)
Beispiel #3
0
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"
Beispiel #4
0
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'}
Beispiel #5
0
 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")
Beispiel #6
0
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'}
Beispiel #7
0
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'}
Beispiel #8
0
def test_create(movie_repo):
    # given
    alice = Person()
    alice.name = "Alice"
    alice.year_of_birth = 1970
    alice.acted_in.add(Film.match(movie_repo, "The Matrix").first())

    # when
    movie_repo.save(alice)

    # then
    node = alice.__node__
    assert node.graph == movie_repo.graph
    assert node.identity is not None
Beispiel #9
0
    def test_create(self):
        # given
        alice = Person()
        alice.name = "Alice"
        alice.year_of_birth = 1970
        alice.acted_in.add(Film.match(self.graph, "The Matrix").first())

        # when
        self.graph.create(alice)

        # then
        node = alice.__node__
        self.assertEqual(node.graph, self.graph)
        self.assertIsNotNone(node.identity)
Beispiel #10
0
def test_can_push_with_incoming_relationships(movie_repo):
    # given
    matrix = Film.match(movie_repo, "The Matrix").first()

    # when
    matrix.actors.remove(Person.match(movie_repo, "Emil Eifrem").first())
    movie_repo.save(matrix)

    # then
    node_id = matrix.__node__.identity
    names = set()
    for name, in movie_repo.graph.run("MATCH (a:Movie)<-[:ACTED_IN]-(b) WHERE id(a) = $x "
                                      "RETURN b.name", x=node_id):
        names.add(name)
    assert names, {'Keanu Reeves', 'Carrie-Anne Moss',
                   'Hugo Weaving' == 'Laurence Fishburne'}
Beispiel #11
0
def test_can_push_new_that_points_to_existing(movie_repo):
    # given
    alice = Person()
    alice.name = "Alice Smith"
    alice.year_of_birth = 1970
    alice.acted_in.add(Film.match(movie_repo, "The Matrix").first())

    # when
    movie_repo.save(alice)

    # then
    node_id = alice.__node__.identity
    film_node = movie_repo.graph.evaluate("MATCH (a:Person)-[:ACTED_IN]->(b) "
                                          "WHERE id(a) = $x RETURN b", x=node_id)
    assert film_node["title"] == "The Matrix"
    assert film_node["tagline"] == "Welcome to the Real World"
Beispiel #12
0
    def test_can_remove_object(self):
        # given
        films_acted_in = self.new_keanu_acted_in()
        self.graph.pull(films_acted_in)

        # when
        matrix_reloaded = Film.match(self.graph, "The Matrix Reloaded").first()
        films_acted_in.remove(matrix_reloaded)

        # then
        film_titles = set(film.title for film in films_acted_in)
        self.assertEqual(
            film_titles, {
                "The Devil's Advocate", "Something's Gotta Give", 'The Matrix',
                'The Replacements', 'The Matrix Revolutions', 'Johnny Mnemonic'
            })
Beispiel #13
0
 def test_can_remove_related_object_and_push(self):
     keanu = Person.match(self.graph, "Keanu Reeves").first()
     johnny_mnemonic = Film.match(self.graph, "Johnny Mnemonic").first()
     keanu.acted_in.remove(johnny_mnemonic)
     self.graph.push(keanu)
     node_id = keanu.__node__.identity
     film_titles = set(title for title, in self.graph.run(
         "MATCH (a:Person)-[:ACTED_IN]->(b) "
         "WHERE id(a) = {x} "
         "RETURN b.title",
         x=node_id))
     self.assertEqual(
         film_titles, {
             "The Devil's Advocate", 'The Matrix Reloaded',
             "Something's Gotta Give", 'The Matrix', 'The Replacements',
             'The Matrix Revolutions'
         })
Beispiel #14
0
    def test_can_push_new_that_points_to_existing(self):
        # given
        alice = Person()
        alice.name = "Alice Smith"
        alice.year_of_birth = 1970
        alice.acted_in.add(Film.match(self.graph, "The Matrix").first())

        # when
        self.graph.push(alice)

        # then
        node_id = alice.__node__.identity
        film_node = self.graph.evaluate(
            "MATCH (a:Person)-[:ACTED_IN]->(b) WHERE id(a) = {x} RETURN b",
            x=node_id)
        self.assertEqual(film_node["title"], "The Matrix")
        self.assertEqual(film_node["tagline"], "Welcome to the Real World")
Beispiel #15
0
    def test_can_pull_with_incoming_relationships(self):
        # given
        matrix = Film.match(self.graph, "The Matrix").first()
        node_id = matrix.__node__.identity
        self.graph.run(
            "MATCH (a:Movie)<-[r:ACTED_IN]-(b) WHERE id(a) = {x} AND b.name = 'Emil Eifrem' DELETE r",
            x=node_id)

        # when
        self.graph.pull(matrix)

        # then
        names = set(a.name for a in matrix.actors)
        self.assertEqual(
            names, {
                'Keanu Reeves', 'Carrie-Anne Moss', 'Hugo Weaving',
                'Laurence Fishburne'
            })
Beispiel #16
0
def test_property_default(movie_repo):
    # given
    film = Film.match(movie_repo, "Something's Gotta Give").first()

    # then
    assert film.tag_line == "Bit boring"