示例#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_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"
示例#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
文件: 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)
示例#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
    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
示例#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_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"
示例#12
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"
示例#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
文件: 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")
示例#15
0
def test_can_pull_without_loading(movie_repo):
    keanu = Person()
    keanu.name = "Keanu Reeves"
    movie_repo.reload(keanu)
    assert keanu.year_of_birth == 1964
示例#16
0
文件: test_ogm.py 项目: SyBen/py2neo
 def test_can_pull_without_loading(self):
     keanu = Person()
     keanu.name = "Keanu Reeves"
     self.graph.pull(keanu)
     self.assertEqual(keanu.year_of_birth, 1964)