def test_table_get_database_node(self): # If: I create a DB that is connected mock_server = Server(utils.MockConnection(None, name='not_connected')) db = Database(mock_server, 'dbname') schema = Schema(mock_server, db, 'schema') table = Table(mock_server, schema, 'table') # check for schema: node = schema.get_database_node() # assert: self.assertIsNotNone(node) self.assertEqual(node.__class__.__name__, 'Database') # check for table: node = table.get_database_node() # assert: self.assertIsNotNone(node) self.assertEqual(node.__class__.__name__, 'Database')
def setUp(self): # Setup: Create an OE service and add a session to it self.cs = ConnectionService() self.mock_connection = {} self.oe = ObjectExplorerService() params, session_uri = _connection_details() self.session = ObjectExplorerSession(session_uri, params) self.oe._session_map[session_uri] = self.session name = 'dbname' self.mock_server = Server(MockPGServerConnection()) self.session.server = self.mock_server self.db = Database(self.mock_server, name) self.db._connection = self.mock_server._conn self.session.server._child_objects[Database.__name__] = [self.db] self.cs.get_connection = mock.MagicMock( return_value=self.mock_connection) self.cs.disconnect = mock.MagicMock(return_value=True) self.oe._service_provider = utils.get_mock_service_provider( {constants.CONNECTION_SERVICE_NAME: self.cs})
def __init__(self, conn: ServerConnection, db_connection_callback: Callable[[str], ServerConnection] = None): """ Initializes a server object using the provided connection :param conn: a connection object """ # Everything we know about the server will be based on the connection self._conn = conn self._db_connection_callback = db_connection_callback # Declare the server properties self._host: str = self._conn.host_name self._port: int = self._conn.port self._maintenance_db_name: str = self._conn.database_name # These properties will be defined later self._recovery_props: NodeLazyPropertyCollection = NodeLazyPropertyCollection(self._fetch_recovery_state) # Declare the child objects self._child_objects: Mapping[str, NodeCollection] = { Database.__name__: NodeCollection(lambda: Database.get_nodes_for_parent(self, None)), Role.__name__: NodeCollection(lambda: Role.get_nodes_for_parent(self, None)), Tablespace.__name__: NodeCollection(lambda: Tablespace.get_nodes_for_parent(self, None)), } self._search_path = NodeCollection(lambda: self._fetch_search_path())
def init_lambda(self): return lambda server, parent, name: Database(server, name)