Example #1
0
 def test_can_handle_other_error_from_get(self):
     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
Example #2
0
class UnmanagedExtension(object):
    """ Base class for unmanaged extensions.
    """

    def __init__(self, graph, path):
        self.graph = graph
        self.remote = Resource(remote(self.graph.dbms).uri.resolve(path))
        try:
            self.remote.get()
        except GraphError:
            raise NotImplementedError("No extension found at path %r on "
                                      "graph <%s>" % (path, remote(self.graph).uri))
Example #3
0
class UnmanagedExtension(object):
    """ Base class for unmanaged extensions.
    """
    def __init__(self, graph, path):
        self.graph = graph
        self.remote = Resource(remote(self.graph.dbms).uri.resolve(path))
        try:
            self.remote.get()
        except GraphError:
            raise NotImplementedError("No extension found at path %r on "
                                      "graph <%s>" %
                                      (path, remote(self.graph).uri))
Example #4
0
 def test_can_handle_404(self):
     node_id = self.get_non_existent_node_id()
     resource = Resource("http://localhost:7474/db/data/node/%s" % node_id)
     try:
         resource.get()
     except GraphError as error:
         self.assert_error(
             error, (GraphError, ),
             "org.neo4j.server.rest.web.NodeNotFoundException",
             (_ClientError, _Response), 404)
     else:
         assert False
Example #5
0
class ServerErrorTestCase(GraphTestCase):
    def setUp(self):
        self.non_existent_resource = Resource(
            "http://localhost:7474/db/data/x")

    def test_can_handle_json_error_from_get(self):
        try:
            self.non_existent_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

    def test_can_handle_json_error_from_put(self):
        try:
            self.non_existent_resource.put("")
        except GraphError as error:
            cause = error.__cause__
            assert isinstance(cause, _ClientError)
            assert isinstance(cause, _Response)
            assert cause.status_code == 404
        else:
            assert False

    def test_can_handle_json_error_from_post(self):
        try:
            self.non_existent_resource.post("")
        except GraphError as error:
            cause = error.__cause__
            assert isinstance(cause, _ClientError)
            assert isinstance(cause, _Response)
            assert cause.status_code == 404
        else:
            assert False

    def test_can_handle_json_error_from_delete(self):
        try:
            self.non_existent_resource.delete()
        except GraphError as error:
            cause = error.__cause__
            assert isinstance(cause, _ClientError)
            assert isinstance(cause, _Response)
            assert cause.status_code == 404
        else:
            assert False

    def test_can_handle_other_error_from_get(self):
        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

    def test_can_handle_other_error_from_put(self):
        with patch.object(_Resource, "put") as mocked:
            mocked.side_effect = DodgyServerError
            resource = Resource("http://localhost:7474/db/data/node/spam")
            try:
                resource.put()
            except GraphError as error:
                assert isinstance(error.__cause__, DodgyServerError)
            else:
                assert False

    def test_can_handle_other_error_from_post(self):
        with patch.object(_Resource, "post") as mocked:
            mocked.side_effect = DodgyServerError
            resource = Resource("http://localhost:7474/db/data/node/spam")
            try:
                resource.post()
            except GraphError as error:
                assert isinstance(error.__cause__, DodgyServerError)
            else:
                assert False

    def test_can_handle_other_error_from_delete(self):
        with patch.object(_Resource, "delete") as mocked:
            mocked.side_effect = DodgyServerError
            resource = Resource("http://localhost:7474/db/data/node/spam")
            try:
                resource.delete()
            except GraphError as error:
                assert isinstance(error.__cause__, DodgyServerError)
            else:
                assert False