Beispiel #1
0
    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)
Beispiel #2
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
Beispiel #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"
Beispiel #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
Beispiel #5
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 #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"
Beispiel #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
Beispiel #8
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
        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")
Beispiel #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"
Beispiel #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"
Beispiel #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"
Beispiel #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"
Beispiel #13
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
        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")
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")