def add_frame_grid( self, name: str, frame_position: FrameGridPositionEnum, width: int = None, height: int = None, column_weight: int = 0, row_weight: int = 0, padx: int = None, pady: int = None, row: int = None, column: int = None, sticky: GridPositionEnum = GridPositionEnum.NONE) -> FrameAndName: if frame_position != FrameGridPositionEnum.CUSTOM_POSITION: if self.__is_custom_grid: raise ApplicationException( 'Bug: [frame_position] must be CUSTOM_POSITION' ' because it was in that state previously' f'but its value is [{frame_position.name}]') logger().debug(f'Add frame_and_name [{name}] in' f' parent frame_and_name [{self.__frame_and_name.name}]' f' in position [{frame_position.name}]') return FrameAndName( self.__create_frame_grid(frame_position, width=width, height=height, column_weight=column_weight, row_weight=row_weight, padx=padx, pady=pady, row=row, column=column, sticky=sticky), name)
def delete_db(self, db_name: str): if self.is_db_exist(db_name): logger().info(f'Delete database [{db_name}]') self.mongo_db_client.drop_database(db_name) else: raise DbException(f'Unable to delete database [{db_name}]' ' because it is not exist')
def destroy_window(cls, window_name: str): if window_name not in cls._window: logger().error(f'[{window_name}] not exist in Window dictionary') return window = cls._window[window_name] cls._window.pop(window_name) window.destroy()
def tearDown(self) -> None: # In LoggerApplicationTests ApplicationLogger.destroy() # is being executed init_logger(LogLevelEnum.DEBUG, LogLevelEnum.DEBUG) if not ApplicationLogger.is_logger_closed: logger().info(f'\n{self.SEPARATOR}\n' f' End Test [{self._testMethodName}]\n' f'{self.SEPARATOR}')
def delete_user(self, username: str): if not self.db_name: raise DbException(f'Unable to delete user [{username}]' ' because database was not chosen') try: logger().info(f'Delete user [{username}] if it is exist') self.mongo_db_client[self.db_name].command('dropUser', username) except OperationFailure: logger().debug(f'User [{username}] not exist')
def create_user(self, username: str, password: str, roles: list): if not self.db_name: raise DbException(f'Unable to create user [{username}]' ' because database was not chosen') logger().info(f'Create user [{username}]') self.mongo_db_client[self.db_name].command('createUser', username, pwd=password, roles=roles)
def __create_new_connection(self, db_username: str, db_password: str, user_type: UserTypeEnum, db_hostname: str, db_port: int, db_name: str, is_tls: bool): uri = self.get_mongo_db_uri(db_username, db_password, user_type, db_hostname, db_port, db_name, is_tls) logger().debug(f'Connect to MongoDB using URI [{uri}]') if DbClient.is_mock_db_enabled(): self.mongo_db_client = mongomock.MongoClient(uri) else: self.mongo_db_client = MongoClient(uri) self.verify_connected_to_db() self.__db = self.mongo_db_client.get_database()
def create_db(self, db_name: str, collection_name: str = None) -> Database: if db_name in self.mongo_db_client.list_database_names(): raise DbException(f'Unable to create database [{db_name}]' ' because it is already exist') logger().info(f'Create database [{db_name}]') db = self.mongo_db_client[db_name] if collection_name: logger().info(f'Create collection [{db_name}]') db.create_collection(collection_name) return db
def __create_frame_grid( self, frame_position: FrameGridPositionEnum, width: int = None, height: int = None, column_weight: int = 0, row_weight: int = 0, padx: int = None, pady: int = None, row: int = None, column: int = None, sticky: GridPositionEnum = GridPositionEnum.NONE) -> Frame: if frame_position == FrameGridPositionEnum.CUSTOM_POSITION \ and (row is None or column is None): raise ApplicationException( 'Bug: row and column parameters must have values' ' when frame_position is CUSTOM_POSITION') frame = Frame(self.__frame_and_name.frame) self.update_row_and_column(frame_position) if frame_position != FrameGridPositionEnum.CUSTOM_POSITION: row = self.__row column = self.__column logger().debug( f'Create new frame_and_name. Parent [{self.__frame_and_name.name}]' f' Row [{row}] Column [{column}]' f' Sticky [{sticky.value}]') frame.rowconfigure(row, weight=row_weight) frame.columnconfigure(column, weight=column_weight) frame.grid(row=row, column=column, padx=padx, pady=pady, sticky=sticky.value) if width: frame.config(width=width) if height: frame.config(height=height) return frame
def __debug(cls, msg: str): if cls.debug: logger().debug(msg)
def enable_mock_db(cls): logger().debug('Unit test DbClient using mongomock') DbClient.__is_mock_db = True
def _debug(self, msg: str): if self.debug: logger().debug(msg)
def set_db(cls, db: Database): if cls._db is None: cls._db = db else: logger().debug( f'DB already exists so will not set db in {cls.__name__}')
def quit_window(cls, window_name: str): if window_name not in cls._window: logger().error(f'[{window_name}] not exist in Window dictionary') return cls._window[window_name].quit()