Beispiel #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()),
        )
Beispiel #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), ),
        )
Beispiel #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),
         )
    def test_count(self):
        with SessionContext(self.graph):
            self.store.create(self.node)

            assert_that(
                self.store.count(),
                is_(equal_to(1)),
            )
    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")
    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)),
            )
    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)),
            )
    def test_search(self):
        with SessionContext(self.graph):
            self.store.create(self.node)

            assert_that(
                self.store.search(),
                contains(matches_person(self.node), ),
            )
Beispiel #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()))
Beispiel #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)),
            )
Beispiel #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)),
            )
Beispiel #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),
         )
Beispiel #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)),
            )
Beispiel #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()
Beispiel #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,
        )
Beispiel #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), ),
            )
Beispiel #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),
         )
Beispiel #18
0
 def test_delete_not_found(self):
     with SessionContext(self.graph):
         assert_that(
             self.store.delete(self.node.id),
             is_(equal_to(False)),
         )
Beispiel #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)
Beispiel #20
0
 def test_create(self):
     with SessionContext(self.graph):
         assert_that(
             self.store.create(self.node),
             matches_person(self.node),
         )