Exemplo n.º 1
0
    def test_auto_rollback(self):
        """
        Sessions created without explicit transactions automatically rollback.

        """
        with SessionContext(self.graph):
            self.store.create(self.person)

        with SessionContext(self.graph):
            people = self.store.search(name=self.name)

        assert_that(
            people,
            is_(empty()),
        )
Exemplo n.º 2
0
    def test_transaction_commit(self):
        """
        Explicit transactions persist across sessions.

        """
        with SessionContext(self.graph), transaction():
            self.store.create(self.person)

        with SessionContext(self.graph):
            people = self.store.search(name=self.name)

        assert_that(
            people,
            contains(matches_person(self.person), ),
        )
Exemplo n.º 3
0
 def test_create_with_missing_dependency(self):
     with SessionContext(self.graph):
         self.person_store.create(self.left)
         assert_that(
             calling(self.store.create).with_args(self.relationship),
             raises(MissingDependencyError),
         )
Exemplo n.º 4
0
    def test_count(self):
        with SessionContext(self.graph):
            self.store.create(self.node)

            assert_that(
                self.store.count(),
                is_(equal_to(1)),
            )
Exemplo n.º 5
0
    def setup(self):
        self.graph = create_object_graph("microcosm_neo4j", testing=True)
        self.store = PersonStore(self.graph)

        with SessionContext(self.graph) as context:
            context.recreate_all()

        self.node = Person(name="name")
Exemplo n.º 6
0
    def test_delete(self):
        with SessionContext(self.graph):
            self.store.create(self.node)

            assert_that(
                self.store.delete(self.node.id),
                is_(equal_to(True)),
            )
Exemplo n.º 7
0
    def test_retrieve(self):
        with SessionContext(self.graph):
            self.store.create(self.node)

            assert_that(
                self.store.retrieve(self.node.id),
                is_(equal_to(self.node)),
            )
Exemplo n.º 8
0
    def test_search(self):
        with SessionContext(self.graph):
            self.store.create(self.node)

            assert_that(
                self.store.search(),
                contains(matches_person(self.node), ),
            )
Exemplo n.º 9
0
    def test_transaction_rollback_on_error(self):
        """
        Errors raised during a transaction cause a rollback.

        """
        with SessionContext(self.graph):
            try:
                with transaction():
                    self.store.create(self.person)

                    raise Break()
            except Break:
                pass

        with SessionContext(self.graph):
            people = self.store.search(name=self.name)

        assert_that(people, is_(empty()))
Exemplo n.º 10
0
    def test_retrieve(self):
        with SessionContext(self.graph):
            self.person_store.create(self.left)
            self.person_store.create(self.right)
            self.store.create(self.relationship)

            assert_that(
                self.store.retrieve(self.relationship.id),
                is_(equal_to(self.relationship)),
            )
Exemplo n.º 11
0
    def test_count(self):
        with SessionContext(self.graph):
            self.person_store.create(self.left)
            self.person_store.create(self.right)
            self.store.create(self.relationship)

            assert_that(
                self.store.count(),
                is_(equal_to(1)),
            )
Exemplo n.º 12
0
 def test_upsert_search(self):
     with SessionContext(self.graph):
         self.person_store.create(self.left)
         self.person_store.create(self.right)
         self.store.create(self.relationship)
         self.store.create(self.relationship)
         assert_that(
             self.store.search(),
             has_length(1),
         )
Exemplo n.º 13
0
    def test_upsert(self):
        with SessionContext(self.graph):
            self.store.create(self.node)

            assert_that(
                self.store.create(self.node),
                matches_person(self.node),
            )

            assert_that(
                self.store.count(),
                is_(equal_to(1)),
            )
Exemplo n.º 14
0
def main(graph):
    """
    Create and drop databases.

    """
    args = parse_args(graph)

    with SessionContext(graph):
        if args.drop:
            warn(
                "Deleting all Neo4J nodes is not recommended for production systems. "
                "Delete Neo4J file system data instead.")
            graph.neo4j_schema_manager.drop_all(force=True)
        graph.neo4j_schema_manager.create_all()
Exemplo n.º 15
0
    def setup(self):
        self.graph = create_object_graph("microcosm_neo4j", testing=True)
        self.person_store = PersonStore(self.graph)
        self.store = IsFriendsWithStore(self.graph)

        with SessionContext(self.graph) as context:
            context.recreate_all()

        self.left = Person(name="left")
        self.right = Person(name="right")

        self.relationship = IsFriendsWith(
            in_id=self.left.id,
            out_id=self.right.id,
        )
Exemplo n.º 16
0
    def test_search_filter(self):
        other = Person(name="other")
        with SessionContext(self.graph):
            self.store.create(self.node)
            self.store.create(other)

            assert_that(
                self.store.search(),
                contains_inanyorder(
                    matches_person(self.node),
                    matches_person(other),
                ),
            )

            assert_that(
                self.store.search(name=self.node.name),
                contains(matches_person(self.node), ),
            )
Exemplo n.º 17
0
 def test_retrieve_not_found(self):
     with SessionContext(self.graph):
         assert_that(
             calling(self.store.retrieve).with_args(self.node.id),
             raises(NotFoundError),
         )
Exemplo n.º 18
0
 def test_delete_not_found(self):
     with SessionContext(self.graph):
         assert_that(
             self.store.delete(self.node.id),
             is_(equal_to(False)),
         )
Exemplo n.º 19
0
 def test_create(self):
     with SessionContext(self.graph):
         self.person_store.create(self.left)
         self.person_store.create(self.right)
         self.store.create(self.relationship)
Exemplo n.º 20
0
 def test_create(self):
     with SessionContext(self.graph):
         assert_that(
             self.store.create(self.node),
             matches_person(self.node),
         )