def test_can_handle_json_error_from_get():
    resource = Resource("http://localhost:7474/db/data/node/spam")
    try:
        resource.get()
    except ClientError:
        assert True
    else:
        assert False
Esempio n. 2
0
def test_can_handle_other_error_from_get():
    with patch.object(_Resource, "get") as mocked:
        mocked.side_effect = DodgyServerError
        resource = Resource("http://localhost:7474/db/data/node/spam")
        try:
            resource.get()
        except GraphError as error:
            assert isinstance(error.__cause__, DodgyServerError)
        else:
            assert False
Esempio n. 3
0
def test_can_handle_other_error_from_get():
    with patch.object(_Resource, "get") as mocked:
        mocked.side_effect = DodgyServerError
        resource = Resource("http://localhost:7474/db/data/node/spam")
        try:
            resource.get()
        except GraphError as error:
            assert isinstance(error.__cause__, DodgyServerError)
        else:
            assert False
Esempio n. 4
0
def test_can_handle_json_error_from_get():
    resource = Resource("http://localhost:7474/db/data/node/spam")
    try:
        resource.get()
    except GraphError as error:
        cause = error.__cause__
        assert isinstance(cause, _ClientError)
        assert isinstance(cause, _Response)
        assert cause.status_code == 404
    else:
        assert False
Esempio n. 5
0
def test_can_handle_json_error_from_get():
    resource = Resource("http://localhost:7474/db/data/node/spam")
    try:
        resource.get()
    except GraphError as error:
        cause = error.__cause__
        assert isinstance(cause, _ClientError)
        assert isinstance(cause, _Response)
        assert cause.status_code == 404
    else:
        assert False
Esempio n. 6
0
def test_can_handle_404(graph):
    node_id = get_non_existent_node_id(graph)
    resource = Resource("http://localhost:7474/db/data/node/%s" % node_id)
    try:
        resource.get()
    except GraphError as error:
        assert_error(
            error, (GraphError,), "org.neo4j.server.rest.web.NodeNotFoundException",
            (_ClientError, _Response), 404)
    else:
        assert False
Esempio n. 7
0
    def constraints(self):
        if not self.__constraints:
            constraints = []
            constraints_resource = Resource(self.graph.uri.string + "schema/constraint")
            constraints_content = list(constraints_resource.get().content)

            for i in constraints_content:
                constraint = dict(i)
                constraint["property_keys"] = list(constraint["property_keys"])
                constraints.append(constraint)

            self.__constraints = constraints

        return self.__constraints
Esempio n. 8
0
    def indexes(self):
        if not self.__indexes:
            indexes = []
            for label in self.labels():
                index_resource = Resource(self.graph.uri.string + "schema/index/" + label)
                indexes_content = list(index_resource.get().content)

                for i in indexes_content:
                    index = dict(i)
                    index["property_keys"] = list(index["property_keys"])
                    indexes.append(index)

            self.__indexes = indexes

        return self.__indexes
Esempio n. 9
0
    def relationship_types(self):
        if not self.__relationship_types:
            relationship_types_resource = Resource(self.graph.uri.string + "relationship/types")
            self.__relationship_types = sorted(list(frozenset(relationship_types_resource.get().content)))

        return self.__relationship_types
Esempio n. 10
0
    def labels(self):
        if not self.__labels:
            labels_resource = Resource(self.graph.uri.string + "labels")
            self.__labels = sorted(list(frozenset(labels_resource.get().content)))

        return self.__labels