diff --git a/src/connection.py b/src/connection.py index 16ed38bf..ac1a12fd 100644 --- a/src/connection.py +++ b/src/connection.py @@ -1,117 +1,23 @@ # coding: utf-8 # we support both pg8000 and psycopg2 + +# to backward compatibility +from .exceptions import NodeConnectionDatabaseException as DatabaseError +from .exceptions import NodeConnectionOperationalException as OperationalError +from .exceptions import NodeConnectionInternalException as InternalError +from .exceptions import NodeConnectionProgrammingException as ProgrammingError + try: - import psycopg2 as pglib + from .impl.connection_psycopg2 import NodeConnection, pglib except ImportError: try: - import pg8000 as pglib + from .impl.connection_pg8000 import NodeConnection, pglib except ImportError: raise ImportError("You must have psycopg2 or pg8000 modules installed") -from .enums import IsolationLevel - -from .defaults import \ - default_dbname, \ - default_username2 - -from .exceptions import QueryException - -# export some exceptions -DatabaseError = pglib.DatabaseError -InternalError = pglib.InternalError -ProgrammingError = pglib.ProgrammingError -OperationalError = pglib.OperationalError - - -class NodeConnection: - """ - Transaction wrapper returned by Node - """ - def __init__(self, - node, - dbname=None, - username=None, - password=None, - autocommit=False): - - # Set default arguments - dbname = dbname or default_dbname() - username = username or default_username2(node.os_ops) - - self._node = node - - self._connection = pglib.connect( - database=dbname, - user=username, - password=password, - host=node.host, - port=node.port - ) - - self._connection.autocommit = autocommit - self._cursor = self.connection.cursor() - - @property - def node(self): - return self._node - - @property - def connection(self): - return self._connection - - @property - def pid(self): - return self.execute("select pg_catalog.pg_backend_pid()")[0][0] - - @property - def cursor(self): - return self._cursor - - def __enter__(self): - return self - - def __exit__(self, type, value, traceback): - self.close() - - def begin(self, isolation_level=IsolationLevel.ReadCommitted): - # Check if level isn't an IsolationLevel - if not isinstance(isolation_level, IsolationLevel): - # Get name of isolation level - level_str = str(isolation_level).lower() - - # Validate level string - try: - isolation_level = IsolationLevel(level_str) - except ValueError: - error = 'Invalid isolation level "{}"' - raise QueryException(error.format(level_str)) - - # Set isolation level - cmd = 'SET TRANSACTION ISOLATION LEVEL {}' - self.cursor.execute(cmd.format(isolation_level.value)) - - return self - - def commit(self): - self.connection.commit() - - return self - - def rollback(self): - self.connection.rollback() - - return self - - def execute(self, query, *args): - self.cursor.execute(query, args) - - if self.cursor.description is None: - return None - - # pg8000 might return tuples - res = [tuple(t) for t in self.cursor.fetchall()] - return res - - def close(self): - self.cursor.close() - self.connection.close() +assert DatabaseError.__name__ == "NodeConnectionDatabaseException" +assert OperationalError.__name__ == "NodeConnectionOperationalException" +assert InternalError.__name__ == "NodeConnectionInternalException" +assert ProgrammingError.__name__ == "NodeConnectionProgrammingException" +assert NodeConnection.__name__ == "NodeConnection" +assert pglib is not None diff --git a/src/exceptions.py b/src/exceptions.py index d00de700..a05bf8d4 100644 --- a/src/exceptions.py +++ b/src/exceptions.py @@ -294,6 +294,85 @@ def __repr__(self) -> str: return result +class NodeConnectionException(TestgresException): + _message: typing.Optional[str] + + def __init__( + self, + message: typing.Optional[str] = None, + ): + assert message is None or type(message) is str + super().__init__(message) + self._message = message + return + + @property + def message(self) -> str: + assert self._message is None or type(self._message) is str + if self._message is None: + return "" + return self._message + + def __repr__(self) -> str: + args = [] + + if self._message is not None: + args.append(("message", self._message)) + + result = "{}(".format(type(self).__name__) + sep = "" + for a in args: + result += sep + a[0] + "=" + repr(a[1]) + sep = ", " + continue + result += ")" + return result + + +class NodeConnectionInterfaceException(NodeConnectionException): + pass + + +class NodeConnectionDatabaseException(NodeConnectionException): + pass + + +class NodeConnectionDataException(NodeConnectionDatabaseException): + pass + + +class NodeConnectionOperationalException(NodeConnectionDatabaseException): + pass + + +class NodeConnectionIntegrityException(NodeConnectionDatabaseException): + pass + + +class NodeConnectionInternalException(NodeConnectionDatabaseException): + pass + + +class NodeConnectionProgrammingException(NodeConnectionDatabaseException): + pass + + +class NodeConnectionNotSupportedException(NodeConnectionDatabaseException): + pass + + +class NodeConnectionQueryCanceledException(NodeConnectionOperationalException): + pass + + +class NodeConnectionTransactionRollbackException(NodeConnectionOperationalException): + pass + + +class NodeConnectionArrayContentNotSupportedException(NodeConnectionNotSupportedException): + pass + + assert ExecUtilException.__name__ == "ExecUtilException" assert InvalidOperationException.__name__ == "InvalidOperationException" assert ExecTimeoutException.__name__ == "ExecTimeoutException" diff --git a/src/impl/connection_pg8000.py b/src/impl/connection_pg8000.py new file mode 100644 index 00000000..8ac51ca9 --- /dev/null +++ b/src/impl/connection_pg8000.py @@ -0,0 +1,197 @@ +# coding: utf-8 +# we support both pg8000 and psycopg2 + +from ..enums import IsolationLevel + +from ..defaults import \ + default_dbname, \ + default_username2 + +from ..exceptions import QueryException +from ..exceptions import NodeConnectionException +from ..exceptions import NodeConnectionInterfaceException +from ..exceptions import NodeConnectionDatabaseException +from ..exceptions import NodeConnectionDataException +from ..exceptions import NodeConnectionOperationalException +from ..exceptions import NodeConnectionIntegrityException +from ..exceptions import NodeConnectionInternalException +from ..exceptions import NodeConnectionProgrammingException +from ..exceptions import NodeConnectionNotSupportedException +from ..exceptions import NodeConnectionArrayContentNotSupportedException + +import typing + +import pg8000 as pglib +import pg8000.dbapi as pglib_dbapi + + +class NodeConnection: + """ + Transaction wrapper returned by Node + """ + def __init__( + self, + node, + dbname=None, + username=None, + password=None, + autocommit=False, + ): + # Set default arguments + dbname = dbname or default_dbname() + username = username or default_username2(node.os_ops) + + self._node = node + + c = __class__._exec_dblib( + pglib.connect, + database=dbname, + user=username, + password=password, + host=node.host, + port=node.port, + ) + assert isinstance(c, pglib.Connection) + + self._connection = c + + self._connection.autocommit = autocommit + + c = self.connection.cursor() + assert isinstance(c, pglib.Cursor) + self._cursor = c + + @property + def node(self): + return self._node + + @property + def connection(self): + return self._connection + + @property + def pid(self): + r = self.execute("select pg_catalog.pg_backend_pid()") + assert r is not None + return r[0][0] + + @property + def cursor(self): + return self._cursor + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + self.close() + return + + def begin(self, isolation_level=IsolationLevel.ReadCommitted): + # Check if level isn't an IsolationLevel + if not isinstance(isolation_level, IsolationLevel): + # Get name of isolation level + level_str = str(isolation_level).lower() + + # Validate level string + try: + isolation_level = IsolationLevel(level_str) + except ValueError: + error = 'Invalid isolation level "{}"' + raise QueryException(error.format(level_str)) + + # Set isolation level + cmd_f = 'SET TRANSACTION ISOLATION LEVEL {}' + cmd = cmd_f.format(isolation_level.value) + + __class__._exec_dblib( + self.cursor.execute, + cmd, + ) + return self + + def commit(self): + __class__._exec_dblib( + self.connection.commit, + ) + return self + + def rollback(self): + __class__._exec_dblib( + self.connection.rollback, + ) + + return self + + def execute(self, query, *args): + __class__._exec_dblib( + self.cursor.execute, + query, + args, + ) + + if self.cursor.description is None: + return None + + # pg8000 might return tuples + r = __class__._exec_dblib( + self.cursor.fetchall, + ) + assert type(r) is tuple + res = [tuple(t) for t in r] + return res + + def close(self): + __class__._exec_dblib( + self.cursor.close, + ) + __class__._exec_dblib( + self.connection.close, + ) + return + + @staticmethod + def _exec_dblib( + func: typing.Callable, + *args, + **kwargs, + ) -> typing.Any: + try: + r = func(*args, **kwargs) + except Exception as e: + __class__._map_pglib_exception(e) + + return r + + @staticmethod + def _map_pglib_exception(exc: Exception) -> typing.NoReturn: + if isinstance(exc, pglib_dbapi.ArrayContentNotSupportedError): + raise NodeConnectionArrayContentNotSupportedException(str(exc)) from exc + + if isinstance(exc, pglib.NotSupportedError): + raise NodeConnectionNotSupportedException(str(exc)) from exc + + if isinstance(exc, pglib.InternalError): + raise NodeConnectionInternalException(str(exc)) from exc + + if isinstance(exc, pglib.ProgrammingError): + raise NodeConnectionProgrammingException(str(exc)) from exc + + if isinstance(exc, pglib.IntegrityError): + raise NodeConnectionIntegrityException(str(exc)) from exc + + if isinstance(exc, pglib.OperationalError): + raise NodeConnectionOperationalException(str(exc)) from exc + + if isinstance(exc, pglib.DataError): + raise NodeConnectionDataException(str(exc)) from exc + + if isinstance(exc, pglib.DatabaseError): + raise NodeConnectionDatabaseException(str(exc)) from exc + + if isinstance(exc, pglib.InterfaceError): + raise NodeConnectionInterfaceException(str(exc)) from exc + + if isinstance(exc, pglib.Error): + raise NodeConnectionException(str(exc)) from exc + + raise exc diff --git a/src/impl/connection_psycopg2.py b/src/impl/connection_psycopg2.py new file mode 100644 index 00000000..56e49021 --- /dev/null +++ b/src/impl/connection_psycopg2.py @@ -0,0 +1,203 @@ +# coding: utf-8 +# we support both pg8000 and psycopg2 + +from ..enums import IsolationLevel + +from ..defaults import \ + default_dbname, \ + default_username2 + +from ..exceptions import QueryException +from ..exceptions import NodeConnectionException +from ..exceptions import NodeConnectionInterfaceException +from ..exceptions import NodeConnectionDatabaseException +from ..exceptions import NodeConnectionDataException +from ..exceptions import NodeConnectionOperationalException +from ..exceptions import NodeConnectionIntegrityException +from ..exceptions import NodeConnectionInternalException +from ..exceptions import NodeConnectionProgrammingException +from ..exceptions import NodeConnectionNotSupportedException +from ..exceptions import NodeConnectionTransactionRollbackException +from ..exceptions import NodeConnectionQueryCanceledException + +import typing + +import psycopg2 as pglib +from psycopg2._psycopg import connection as PSYCOPG2__Connection +from psycopg2._psycopg import cursor as PSYCOPG2__Cursor +from psycopg2._psycopg import QueryCanceledError as PSYCOPG2__QueryCanceledError +from psycopg2._psycopg import TransactionRollbackError as PSYCOPG2__TransactionRollbackError + + +class NodeConnection: + """ + Transaction wrapper returned by Node + """ + def __init__( + self, + node, + dbname=None, + username=None, + password=None, + autocommit=False, + ): + # Set default arguments + dbname = dbname or default_dbname() + username = username or default_username2(node.os_ops) + + self._node = node + + c = __class__._exec_dblib( + pglib.connect, + database=dbname, + user=username, + password=password, + host=node.host, + port=node.port, + ) + assert isinstance(c, PSYCOPG2__Connection) + + self._connection = c + + self._connection.autocommit = autocommit + + c = self.connection.cursor() + assert isinstance(c, PSYCOPG2__Cursor) + self._cursor = c + + @property + def node(self): + return self._node + + @property + def connection(self): + return self._connection + + @property + def pid(self): + r = self.execute("select pg_catalog.pg_backend_pid()") + assert r is not None + return r[0][0] + + @property + def cursor(self): + return self._cursor + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + self.close() + return + + def begin(self, isolation_level=IsolationLevel.ReadCommitted): + # Check if level isn't an IsolationLevel + if not isinstance(isolation_level, IsolationLevel): + # Get name of isolation level + level_str = str(isolation_level).lower() + + # Validate level string + try: + isolation_level = IsolationLevel(level_str) + except ValueError: + error = 'Invalid isolation level "{}"' + raise QueryException(error.format(level_str)) + + # Set isolation level + cmd_f = 'SET TRANSACTION ISOLATION LEVEL {}' + cmd = cmd_f.format(isolation_level.value) + + __class__._exec_dblib( + self.cursor.execute, + cmd, + ) + return self + + def commit(self): + __class__._exec_dblib( + self.connection.commit, + ) + return self + + def rollback(self): + __class__._exec_dblib( + self.connection.rollback, + ) + + return self + + def execute(self, query, *args): + __class__._exec_dblib( + self.cursor.execute, + query, + args, + ) + + if self.cursor.description is None: + return None + + # note: pg8000 might return tuples + res = __class__._exec_dblib( + self.cursor.fetchall, + ) + assert type(res) is list + return res + + def close(self): + __class__._exec_dblib( + self.cursor.close, + ) + __class__._exec_dblib( + self.connection.close, + ) + return + + @staticmethod + def _exec_dblib( + func: typing.Callable, + *args, + **kwargs, + ) -> typing.Any: + try: + r = func(*args, **kwargs) + except Exception as e: + __class__._map_pglib_exception(e) + + return r + + @staticmethod + def _map_pglib_exception(exc: Exception) -> typing.NoReturn: + if isinstance(exc, PSYCOPG2__QueryCanceledError): + raise NodeConnectionQueryCanceledException(str(exc)) from exc + + if isinstance(exc, PSYCOPG2__TransactionRollbackError): + raise NodeConnectionTransactionRollbackException(str(exc)) from exc + + if isinstance(exc, pglib.NotSupportedError): + raise NodeConnectionNotSupportedException(str(exc)) from exc + + if isinstance(exc, pglib.InternalError): + raise NodeConnectionInternalException(str(exc)) from exc + + if isinstance(exc, pglib.ProgrammingError): + raise NodeConnectionProgrammingException(str(exc)) from exc + + if isinstance(exc, pglib.IntegrityError): + raise NodeConnectionIntegrityException(str(exc)) from exc + + if isinstance(exc, pglib.OperationalError): + raise NodeConnectionOperationalException(str(exc)) from exc + + if isinstance(exc, pglib.DataError): + raise NodeConnectionDataException(str(exc)) from exc + + if isinstance(exc, pglib.DatabaseError): + raise NodeConnectionDatabaseException(str(exc)) from exc + + if isinstance(exc, pglib.InterfaceError): + raise NodeConnectionInterfaceException(str(exc)) from exc + + if isinstance(exc, pglib.Error): + raise NodeConnectionException(str(exc)) from exc + + raise exc diff --git a/src/node.py b/src/node.py index 4706a287..86a6ccb1 100644 --- a/src/node.py +++ b/src/node.py @@ -10,7 +10,7 @@ from .config import testgres_config -from .connection import NodeConnection +from .connection import NodeConnection, pglib from .consts import \ DATA_DIR, \ @@ -68,6 +68,7 @@ from .backup import NodeBackup from . import utils +from . import exceptions from testgres.operations.os_ops import OsOperations from testgres.operations.os_ops import OsCommandResult @@ -82,22 +83,14 @@ import time import typing -# we support both pg8000 and psycopg2 -try: - import psycopg2 as pglib -except ImportError: - try: - import pg8000 as pglib - except ImportError: - raise ImportError("You must have psycopg2 or pg8000 modules installed") - - -InternalError = pglib.InternalError -ProgrammingError = pglib.ProgrammingError -OperationalError = pglib.OperationalError -InterfaceError = pglib.InterfaceError +InternalError = exceptions.NodeConnectionInternalException +ProgrammingError = exceptions.NodeConnectionProgrammingException +OperationalError = exceptions.NodeConnectionOperationalException +InterfaceError = exceptions.NodeConnectionInterfaceException +# to backward compatibility +assert pglib is not None assert TimeoutException == QueryTimeoutException diff --git a/tests/units/exceptions/NodeConnectionArrayContentNotSupportedException/__init__.py b/tests/units/exceptions/NodeConnectionArrayContentNotSupportedException/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/units/exceptions/NodeConnectionArrayContentNotSupportedException/test_set001__constructor.py b/tests/units/exceptions/NodeConnectionArrayContentNotSupportedException/test_set001__constructor.py new file mode 100644 index 00000000..6be5e23c --- /dev/null +++ b/tests/units/exceptions/NodeConnectionArrayContentNotSupportedException/test_set001__constructor.py @@ -0,0 +1,24 @@ +from src.exceptions import NodeConnectionTransactionRollbackException +from src.exceptions import TestgresException as testgres__TestgresException + + +class TestSet001_Constructor: + def test_001__default(self): + e = NodeConnectionTransactionRollbackException() + assert type(e) is NodeConnectionTransactionRollbackException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "" + assert str(e) == "" + assert repr(e) == "NodeConnectionTransactionRollbackException()" + return + + def test_002__message(self): + e = NodeConnectionTransactionRollbackException(message="abc\n123") + assert type(e) is NodeConnectionTransactionRollbackException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "abc\n123" + assert str(e) == "abc\n123" + assert repr(e) == "NodeConnectionTransactionRollbackException(message='abc\\n123')" + return diff --git a/tests/units/exceptions/NodeConnectionDataException/__init__.py b/tests/units/exceptions/NodeConnectionDataException/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/units/exceptions/NodeConnectionDataException/test_set001__constructor.py b/tests/units/exceptions/NodeConnectionDataException/test_set001__constructor.py new file mode 100644 index 00000000..0ee68a81 --- /dev/null +++ b/tests/units/exceptions/NodeConnectionDataException/test_set001__constructor.py @@ -0,0 +1,24 @@ +from src.exceptions import NodeConnectionDataException +from src.exceptions import TestgresException as testgres__TestgresException + + +class TestSet001_Constructor: + def test_001__default(self): + e = NodeConnectionDataException() + assert type(e) is NodeConnectionDataException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "" + assert str(e) == "" + assert repr(e) == "NodeConnectionDataException()" + return + + def test_002__message(self): + e = NodeConnectionDataException(message="abc\n123") + assert type(e) is NodeConnectionDataException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "abc\n123" + assert str(e) == "abc\n123" + assert repr(e) == "NodeConnectionDataException(message='abc\\n123')" + return diff --git a/tests/units/exceptions/NodeConnectionDatabaseException/__init__.py b/tests/units/exceptions/NodeConnectionDatabaseException/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/units/exceptions/NodeConnectionDatabaseException/test_set001__constructor.py b/tests/units/exceptions/NodeConnectionDatabaseException/test_set001__constructor.py new file mode 100644 index 00000000..16a3d20d --- /dev/null +++ b/tests/units/exceptions/NodeConnectionDatabaseException/test_set001__constructor.py @@ -0,0 +1,24 @@ +from src.exceptions import NodeConnectionInterfaceException +from src.exceptions import TestgresException as testgres__TestgresException + + +class TestSet001_Constructor: + def test_001__default(self): + e = NodeConnectionInterfaceException() + assert type(e) is NodeConnectionInterfaceException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "" + assert str(e) == "" + assert repr(e) == "NodeConnectionInterfaceException()" + return + + def test_002__message(self): + e = NodeConnectionInterfaceException(message="abc\n123") + assert type(e) is NodeConnectionInterfaceException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "abc\n123" + assert str(e) == "abc\n123" + assert repr(e) == "NodeConnectionInterfaceException(message='abc\\n123')" + return diff --git a/tests/units/exceptions/NodeConnectionException/__init__.py b/tests/units/exceptions/NodeConnectionException/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/units/exceptions/NodeConnectionException/test_set001__constructor.py b/tests/units/exceptions/NodeConnectionException/test_set001__constructor.py new file mode 100644 index 00000000..51172f26 --- /dev/null +++ b/tests/units/exceptions/NodeConnectionException/test_set001__constructor.py @@ -0,0 +1,24 @@ +from src.exceptions import NodeConnectionException +from src.exceptions import TestgresException as testgres__TestgresException + + +class TestSet001_Constructor: + def test_001__default(self): + e = NodeConnectionException() + assert type(e) is NodeConnectionException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "" + assert str(e) == "" + assert repr(e) == "NodeConnectionException()" + return + + def test_002__message(self): + e = NodeConnectionException(message="abc\n123") + assert type(e) is NodeConnectionException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "abc\n123" + assert str(e) == "abc\n123" + assert repr(e) == "NodeConnectionException(message='abc\\n123')" + return diff --git a/tests/units/exceptions/NodeConnectionIntegrityException/__init__.py b/tests/units/exceptions/NodeConnectionIntegrityException/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/units/exceptions/NodeConnectionIntegrityException/test_set001__constructor.py b/tests/units/exceptions/NodeConnectionIntegrityException/test_set001__constructor.py new file mode 100644 index 00000000..b3d0bb18 --- /dev/null +++ b/tests/units/exceptions/NodeConnectionIntegrityException/test_set001__constructor.py @@ -0,0 +1,24 @@ +from src.exceptions import NodeConnectionIntegrityException +from src.exceptions import TestgresException as testgres__TestgresException + + +class TestSet001_Constructor: + def test_001__default(self): + e = NodeConnectionIntegrityException() + assert type(e) is NodeConnectionIntegrityException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "" + assert str(e) == "" + assert repr(e) == "NodeConnectionIntegrityException()" + return + + def test_002__message(self): + e = NodeConnectionIntegrityException(message="abc\n123") + assert type(e) is NodeConnectionIntegrityException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "abc\n123" + assert str(e) == "abc\n123" + assert repr(e) == "NodeConnectionIntegrityException(message='abc\\n123')" + return diff --git a/tests/units/exceptions/NodeConnectionInterfaceException/__init__.py b/tests/units/exceptions/NodeConnectionInterfaceException/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/units/exceptions/NodeConnectionInterfaceException/test_set001__constructor.py b/tests/units/exceptions/NodeConnectionInterfaceException/test_set001__constructor.py new file mode 100644 index 00000000..838bf395 --- /dev/null +++ b/tests/units/exceptions/NodeConnectionInterfaceException/test_set001__constructor.py @@ -0,0 +1,24 @@ +from src.exceptions import NodeConnectionDatabaseException +from src.exceptions import TestgresException as testgres__TestgresException + + +class TestSet001_Constructor: + def test_001__default(self): + e = NodeConnectionDatabaseException() + assert type(e) is NodeConnectionDatabaseException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "" + assert str(e) == "" + assert repr(e) == "NodeConnectionDatabaseException()" + return + + def test_002__message(self): + e = NodeConnectionDatabaseException(message="abc\n123") + assert type(e) is NodeConnectionDatabaseException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "abc\n123" + assert str(e) == "abc\n123" + assert repr(e) == "NodeConnectionDatabaseException(message='abc\\n123')" + return diff --git a/tests/units/exceptions/NodeConnectionInternalException/__init__.py b/tests/units/exceptions/NodeConnectionInternalException/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/units/exceptions/NodeConnectionInternalException/test_set001__constructor.py b/tests/units/exceptions/NodeConnectionInternalException/test_set001__constructor.py new file mode 100644 index 00000000..cf36ab02 --- /dev/null +++ b/tests/units/exceptions/NodeConnectionInternalException/test_set001__constructor.py @@ -0,0 +1,24 @@ +from src.exceptions import NodeConnectionInternalException +from src.exceptions import TestgresException as testgres__TestgresException + + +class TestSet001_Constructor: + def test_001__default(self): + e = NodeConnectionInternalException() + assert type(e) is NodeConnectionInternalException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "" + assert str(e) == "" + assert repr(e) == "NodeConnectionInternalException()" + return + + def test_002__message(self): + e = NodeConnectionInternalException(message="abc\n123") + assert type(e) is NodeConnectionInternalException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "abc\n123" + assert str(e) == "abc\n123" + assert repr(e) == "NodeConnectionInternalException(message='abc\\n123')" + return diff --git a/tests/units/exceptions/NodeConnectionNotSupportedException/__init__.py b/tests/units/exceptions/NodeConnectionNotSupportedException/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/units/exceptions/NodeConnectionNotSupportedException/test_set001__constructor.py b/tests/units/exceptions/NodeConnectionNotSupportedException/test_set001__constructor.py new file mode 100644 index 00000000..650f3615 --- /dev/null +++ b/tests/units/exceptions/NodeConnectionNotSupportedException/test_set001__constructor.py @@ -0,0 +1,24 @@ +from src.exceptions import NodeConnectionNotSupportedException +from src.exceptions import TestgresException as testgres__TestgresException + + +class TestSet001_Constructor: + def test_001__default(self): + e = NodeConnectionNotSupportedException() + assert type(e) is NodeConnectionNotSupportedException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "" + assert str(e) == "" + assert repr(e) == "NodeConnectionNotSupportedException()" + return + + def test_002__message(self): + e = NodeConnectionNotSupportedException(message="abc\n123") + assert type(e) is NodeConnectionNotSupportedException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "abc\n123" + assert str(e) == "abc\n123" + assert repr(e) == "NodeConnectionNotSupportedException(message='abc\\n123')" + return diff --git a/tests/units/exceptions/NodeConnectionOperationalException/__init__.py b/tests/units/exceptions/NodeConnectionOperationalException/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/units/exceptions/NodeConnectionOperationalException/test_set001__constructor.py b/tests/units/exceptions/NodeConnectionOperationalException/test_set001__constructor.py new file mode 100644 index 00000000..68b4c4a7 --- /dev/null +++ b/tests/units/exceptions/NodeConnectionOperationalException/test_set001__constructor.py @@ -0,0 +1,24 @@ +from src.exceptions import NodeConnectionOperationalException +from src.exceptions import TestgresException as testgres__TestgresException + + +class TestSet001_Constructor: + def test_001__default(self): + e = NodeConnectionOperationalException() + assert type(e) is NodeConnectionOperationalException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "" + assert str(e) == "" + assert repr(e) == "NodeConnectionOperationalException()" + return + + def test_002__message(self): + e = NodeConnectionOperationalException(message="abc\n123") + assert type(e) is NodeConnectionOperationalException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "abc\n123" + assert str(e) == "abc\n123" + assert repr(e) == "NodeConnectionOperationalException(message='abc\\n123')" + return diff --git a/tests/units/exceptions/NodeConnectionProgrammingException/__init__.py b/tests/units/exceptions/NodeConnectionProgrammingException/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/units/exceptions/NodeConnectionProgrammingException/test_set001__constructor.py b/tests/units/exceptions/NodeConnectionProgrammingException/test_set001__constructor.py new file mode 100644 index 00000000..f191a908 --- /dev/null +++ b/tests/units/exceptions/NodeConnectionProgrammingException/test_set001__constructor.py @@ -0,0 +1,24 @@ +from src.exceptions import NodeConnectionProgrammingException +from src.exceptions import TestgresException as testgres__TestgresException + + +class TestSet001_Constructor: + def test_001__default(self): + e = NodeConnectionProgrammingException() + assert type(e) is NodeConnectionProgrammingException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "" + assert str(e) == "" + assert repr(e) == "NodeConnectionProgrammingException()" + return + + def test_002__message(self): + e = NodeConnectionProgrammingException(message="abc\n123") + assert type(e) is NodeConnectionProgrammingException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "abc\n123" + assert str(e) == "abc\n123" + assert repr(e) == "NodeConnectionProgrammingException(message='abc\\n123')" + return diff --git a/tests/units/exceptions/NodeConnectionQueryCanceledException/__init__.py b/tests/units/exceptions/NodeConnectionQueryCanceledException/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/units/exceptions/NodeConnectionQueryCanceledException/test_set001__constructor.py b/tests/units/exceptions/NodeConnectionQueryCanceledException/test_set001__constructor.py new file mode 100644 index 00000000..639798b1 --- /dev/null +++ b/tests/units/exceptions/NodeConnectionQueryCanceledException/test_set001__constructor.py @@ -0,0 +1,24 @@ +from src.exceptions import NodeConnectionQueryCanceledException +from src.exceptions import TestgresException as testgres__TestgresException + + +class TestSet001_Constructor: + def test_001__default(self): + e = NodeConnectionQueryCanceledException() + assert type(e) is NodeConnectionQueryCanceledException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "" + assert str(e) == "" + assert repr(e) == "NodeConnectionQueryCanceledException()" + return + + def test_002__message(self): + e = NodeConnectionQueryCanceledException(message="abc\n123") + assert type(e) is NodeConnectionQueryCanceledException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "abc\n123" + assert str(e) == "abc\n123" + assert repr(e) == "NodeConnectionQueryCanceledException(message='abc\\n123')" + return diff --git a/tests/units/exceptions/NodeConnectionTransactionRollbackException/__init__.py b/tests/units/exceptions/NodeConnectionTransactionRollbackException/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/units/exceptions/NodeConnectionTransactionRollbackException/test_set001__constructor.py b/tests/units/exceptions/NodeConnectionTransactionRollbackException/test_set001__constructor.py new file mode 100644 index 00000000..827bd061 --- /dev/null +++ b/tests/units/exceptions/NodeConnectionTransactionRollbackException/test_set001__constructor.py @@ -0,0 +1,24 @@ +from src.exceptions import NodeConnectionArrayContentNotSupportedException +from src.exceptions import TestgresException as testgres__TestgresException + + +class TestSet001_Constructor: + def test_001__default(self): + e = NodeConnectionArrayContentNotSupportedException() + assert type(e) is NodeConnectionArrayContentNotSupportedException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "" + assert str(e) == "" + assert repr(e) == "NodeConnectionArrayContentNotSupportedException()" + return + + def test_002__message(self): + e = NodeConnectionArrayContentNotSupportedException(message="abc\n123") + assert type(e) is NodeConnectionArrayContentNotSupportedException + assert isinstance(e, testgres__TestgresException) + assert e.source is None + assert e.message == "abc\n123" + assert str(e) == "abc\n123" + assert repr(e) == "NodeConnectionArrayContentNotSupportedException(message='abc\\n123')" + return