preset-io / elasticsearch-dbapi

@@ -115,9 +115,11 @@
Loading
115 115
    @check_closed
116 116
    def cursor(self) -> "Cursor":
117 117
        """Return a new Cursor Object using the connection."""
118 -
        cursor = Cursor(self.url, self.es, **self.kwargs)
119 -
        self.cursors.append(cursor)
120 -
        return cursor
118 +
        if self.es:
119 +
            cursor = Cursor(self.url, self.es, **self.kwargs)
120 +
            self.cursors.append(cursor)
121 +
            return cursor
122 +
        raise exceptions.UnexpectedESInitError()
121 123
122 124
123 125
class Cursor(BaseCursor):

@@ -1,5 +1,5 @@
Loading
1 1
class Error(Exception):
2 -
    pass
2 +
    """Base exception"""
3 3
4 4
5 5
class Warning(Exception):
@@ -36,3 +36,13 @@
Loading
36 36
37 37
class NotSupportedError(DatabaseError):
38 38
    pass
39 +
40 +
41 +
class UnexpectedESInitError(Error):
42 +
    """ Should never happen, when a cursor is requested
43 +
    without an ElasticSearch object being initialized"""
44 +
45 +
46 +
class UnexpectedRequestResponse(Error):
47 +
    """ When perform request returns False, only when HTTP method HEAD
48 +
    and status code 404 """

@@ -69,9 +69,11 @@
Loading
69 69
    @check_closed
70 70
    def cursor(self) -> BaseCursor:
71 71
        """Return a new Cursor Object using the connection."""
72 -
        cursor = Cursor(self.url, self.es, **self.kwargs)
73 -
        self.cursors.append(cursor)
74 -
        return cursor
72 +
        if self.es:
73 +
            cursor = Cursor(self.url, self.es, **self.kwargs)
74 +
            self.cursors.append(cursor)
75 +
            return cursor
76 +
        raise exceptions.UnexpectedESInitError()
75 77
76 78
77 79
class Cursor(BaseCursor):
@@ -165,9 +167,7 @@
Loading
165 167
                f"Error connecting to {self.url}: {e.info}"
166 168
            )
167 169
        except es_exceptions.NotFoundError as e:
168 -
            raise exceptions.ProgrammingError(
169 -
                f"Error ({e.error}): {e.info['error']['reason']}"
170 -
            )
170 +
            raise exceptions.ProgrammingError(f"Error ({e.error}): {e.info}")
171 171
        try:
172 172
            if response["hits"]["total"]["value"] == 0:
173 173
                source = {}

@@ -130,7 +130,7 @@
Loading
130 130
        self.cursors: List[BaseCursor] = []
131 131
        self.kwargs = kwargs
132 132
        # Subclass needs to initialize Elasticsearch
133 -
        self.es = None
133 +
        self.es: Optional[Elasticsearch] = None
134 134
135 135
    @check_closed
136 136
    def close(self):
@@ -320,9 +320,11 @@
Loading
320 320
        except es_exceptions.ConnectionError:
321 321
            raise exceptions.OperationalError("Error connecting to Elasticsearch")
322 322
        except es_exceptions.RequestError as ex:
323 -
            raise exceptions.ProgrammingError(
324 -
                f"Error ({ex.error}): {ex.info['error']['reason']}"
325 -
            )
323 +
            raise exceptions.ProgrammingError(f"Error ({ex.error}): {ex.info}")
324 +
        # When method is HEAD and code is 404 perform request returns True
325 +
        # So response is Union[bool, Any]
326 +
        if isinstance(response, bool):
327 +
            raise exceptions.UnexpectedRequestResponse()
326 328
        # Opendistro errors are http status 200
327 329
        if "error" in response:
328 330
            raise exceptions.ProgrammingError(
Files Coverage
es 94.39%
Project Totals (15 files) 94.39%
Notifications are pending CI completion. Waiting for GitHub's status webhook to queue notifications. Push notifications now.

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading