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

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