예제 #1
0
def test_not_exists_on_non_existing(movie_repo):
    # given
    alice = Person()
    alice.name = "Alice Smith"
    alice.year_of_birth = 1970

    # when
    exists = movie_repo.exists(alice)

    # then
    assert not exists
예제 #2
0
파일: test_ogm.py 프로젝트: SyBen/py2neo
    def test_not_exists_on_non_existing(self):
        # given
        alice = Person()
        alice.name = "Alice Smith"
        alice.year_of_birth = 1970

        # when
        exists = self.graph.exists(alice)

        # then
        self.assertFalse(exists)
예제 #3
0
    def test_create(self):
        # given
        alice = Person()
        alice.name = "Alice"
        alice.year_of_birth = 1970
        alice.acted_in.add(Film.select(self.graph, "The Matrix").first())

        # when
        self.graph.create(alice)

        # then
        node = alice.__ogm__.node
        remote_node = remote(node)
        assert remote_node
예제 #4
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
예제 #5
0
def test_can_push_new(movie_repo):
    # given
    alice = Person()
    alice.name = "Alice Smith"
    alice.year_of_birth = 1970

    # when
    movie_repo.save(alice)

    # then
    node_id = alice.__node__.identity
    remote_name = movie_repo.graph.evaluate("MATCH (a:Person) WHERE id(a) = $x "
                                            "RETURN a.name", x=node_id)
    assert remote_name == "Alice Smith"
예제 #6
0
    def test_can_push_new(self):
        # given
        alice = Person()
        alice.name = "Alice Smith"
        alice.year_of_birth = 1970

        # when
        self.graph.push(alice)

        # then
        remote_node = remote(alice.__ogm__.node)
        remote_name = self.graph.evaluate("MATCH (a:Person) WHERE id(a) = {x} "
                                          "RETURN a.name", x=remote_node._id)
        assert remote_name == "Alice Smith"
예제 #7
0
파일: test_ogm.py 프로젝트: SyBen/py2neo
    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)
예제 #8
0
파일: test_ogm.py 프로젝트: SyBen/py2neo
    def test_can_push_new(self):
        # given
        alice = Person()
        alice.name = "Alice Smith"
        alice.year_of_birth = 1970

        # when
        self.graph.push(alice)

        # then
        node_id = alice.__node__.identity
        remote_name = self.graph.evaluate(
            "MATCH (a:Person) WHERE id(a) = {x} "
            "RETURN a.name", x=node_id)
        self.assertEqual(remote_name, "Alice Smith")
예제 #9
0
def test_can_push_new_that_points_to_new(movie_repo):
    # given
    the_dominatrix = Film("The Dominatrix")
    alice = Person()
    alice.name = "Alice Smith"
    alice.year_of_birth = 1970
    alice.acted_in.add(the_dominatrix)

    # 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 Dominatrix"
예제 #10
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"
예제 #11
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.select(self.graph, "The Matrix").first())

        # when
        self.graph.push(alice)

        # then
        remote_node = remote(alice.__ogm__.node)
        film_node = self.graph.evaluate("MATCH (a:Person)-[:ACTED_IN]->(b) WHERE id(a) = {x} RETURN b",
                                        x=remote_node._id)
        assert film_node["title"] == "The Matrix"
        assert film_node["tagline"] == "Welcome to the Real World"
예제 #12
0
    def test_can_push_new_that_points_to_new(self):
        # given
        the_dominatrix = Film("The Dominatrix")
        alice = Person()
        alice.name = "Alice Smith"
        alice.year_of_birth = 1970
        alice.acted_in.add(the_dominatrix)

        # when
        self.graph.push(alice)

        # then
        remote_node = remote(alice.__ogm__.node)
        film_node = self.graph.evaluate("MATCH (a:Person)-[:ACTED_IN]->(b) WHERE id(a) = {x} RETURN b",
                                        x=remote_node._id)
        assert film_node["title"] == "The Dominatrix"
예제 #13
0
파일: test_ogm.py 프로젝트: SyBen/py2neo
    def test_can_push_new_that_points_to_new(self):
        # given
        the_dominatrix = Film("The Dominatrix")
        alice = Person()
        alice.name = "Alice Smith"
        alice.year_of_birth = 1970
        alice.acted_in.add(the_dominatrix)

        # 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 Dominatrix")
예제 #14
0
 def test_can_load_and_pull(self):
     keanu = Person.select(self.graph, "Keanu Reeves").first()
     assert keanu.name == "Keanu Reeves"
     remote_node = remote(keanu.__ogm__.node)
     self.graph.run("MATCH (a:Person) WHERE id(a) = {x} SET a.name = {y}",
                    x=remote_node._id, y="Keanu Charles Reeves")
     self.graph.pull(keanu)
     assert keanu.name == "Keanu Charles Reeves"
예제 #15
0
파일: test_ogm.py 프로젝트: SyBen/py2neo
    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")
예제 #16
0
파일: test_ogm.py 프로젝트: SyBen/py2neo
    def test_exists_on_existing(self):
        # given
        keanu = Person.match(self.graph, "Keanu Reeves").first()

        # when
        exists = self.graph.exists(keanu)

        # then
        self.assertTrue(exists)
예제 #17
0
파일: test_ogm.py 프로젝트: SyBen/py2neo
    def test_delete_on_existing(self):
        # given
        keanu = Person.match(self.graph, "Keanu Reeves").first()

        # when
        self.graph.delete(keanu)

        # then
        self.assertFalse(self.graph.exists(keanu))
예제 #18
0
def test_raw_query_returns_actors_of_both_films(movie_repo):
    actor = Person.match(movie_repo).raw_query(
        """Match (m:Movie)<-[:ACTED_IN]-(_:Person)-[:ACTED_IN]->(n:Movie)
        WHERE m.title = $movie1 AND n.title = $movie2""", {
            "movie1": "Top Gun",
            "movie2": "Jerry Maguire"
        })

    assert actor[0].name == "Tom Cruise"
예제 #19
0
파일: test_ogm.py 프로젝트: SyBen/py2neo
 def test_can_load_and_pull(self):
     keanu = Person.match(self.graph, "Keanu Reeves").first()
     self.assertEqual(keanu.name, "Keanu Reeves")
     node_id = keanu.__node__.identity
     self.graph.run("MATCH (a:Person) WHERE id(a) = {x} SET a.name = {y}",
                    x=node_id,
                    y="Keanu Charles Reeves")
     self.graph.pull(keanu)
     self.assertEqual(keanu.name, "Keanu Charles Reeves")
예제 #20
0
파일: test_ogm.py 프로젝트: SyBen/py2neo
 def test_related_objects_are_automatically_loaded(self):
     keanu = Person.match(self.graph, "Keanu Reeves").first()
     film_titles = set(film.title for film in list(keanu.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'
         })
예제 #21
0
 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"
예제 #22
0
    def test_delete_on_existing(self):
        # given
        keanu = Person.select(self.graph, "Keanu Reeves").first()
        node = keanu.__ogm__.node

        # when
        self.graph.delete(keanu)

        # then
        assert not self.graph.exists(node)
예제 #23
0
def test_can_match_multiple_objects(movie_repo):
    people = list(Person.match(movie_repo, ("Keanu Reeves", "Hugo Weaving")))
    if people[0].name == "Keanu Reeves":
        keanu, hugo = people
    else:
        hugo, keanu = people
    assert keanu.name == "Keanu Reeves"
    assert keanu.year_of_birth == 1964
    assert hugo.name == "Hugo Weaving"
    assert hugo.year_of_birth == 1960
예제 #24
0
 def test_graph_propagation(self):
     keanu = Person.select(self.graph, "Keanu Reeves").first()
     films = list(keanu.acted_in)
     colleagues = set()
     for film in films:
         colleagues |= set(film.actors)
     names = set(colleague.name for colleague in colleagues)
     expected_names = {'Al Pacino', 'Dina Meyer', 'Keanu Reeves', 'Brooke Langton', 'Hugo Weaving', 'Diane Keaton',
                       'Takeshi Kitano', 'Laurence Fishburne', 'Charlize Theron', 'Emil Eifrem', 'Orlando Jones',
                       'Carrie-Anne Moss', 'Ice-T', 'Gene Hackman', 'Jack Nicholson'}
     assert names == expected_names
예제 #25
0
 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']
예제 #26
0
파일: test_ogm.py 프로젝트: SyBen/py2neo
 def test_can_match_multiple_objects(self):
     people = list(
         Person.match(self.graph, ("Keanu Reeves", "Hugo Weaving")))
     if people[0].name == "Keanu Reeves":
         keanu, hugo = people
     else:
         hugo, keanu = people
     self.assertEqual(keanu.name, "Keanu Reeves")
     self.assertEqual(keanu.year_of_birth, 1964)
     self.assertEqual(hugo.name, "Hugo Weaving")
     self.assertEqual(hugo.year_of_birth, 1960)
예제 #27
0
 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'}
예제 #28
0
def test_raw_query_returns_actors_of_either_film(movie_repo):
    actors = Person.match(movie_repo).raw_query(
        """Match (m:Movie)<-[:ACTED_IN]-(_:Person)
        WHERE m.title IN $movie_titles""",
        {"movie_titles": ["Top Gun", "Jerry Maguire"]})

    assert len(actors) == 15

    for actor in actors:
        if actor.name == "Regina King":
            return
    assert 0, "Regina King was not found"
예제 #29
0
파일: test_ogm.py 프로젝트: SyBen/py2neo
 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")
예제 #30
0
 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"}