Db Generator Module
- class mtf.test_utilities.db_generator.DbGenerator
- databex_path
- json_path
- __init__(databex_cli_path_: str | None = None)
- get_dbx_version(dbx_cli_path)
This method aims to get the databex version using a subprocess. Arguments:
dbx_cli_path (str): databex cli path
- Returns:
str: it returns the databex version if there’s no problem occurred, else it returns the subprocess error message.
- generate_db(dbx_cli_path, database_folder_path, dbx_version, scripts_version='', timeout=1800)
This method uses the databex Cli to generate a db file with the data sources that exist in the database folder and stores this db file info into the json file. Arguments:
dbx_cli_path (str): databex cli path database_folder_path (str): Database folder path dbx_version (str): databex version scripts_version (str): scripts sql file version. By default, its value is an empty string timeout (int): subprocess timeout
- Returns:
- bool, str: if the db file was generated without problems, it returns True, generated db file path
else it returns False, “”
- detect_db_existence(database_folder_path, dbx_version, scripts_version='')
This method searches for an existing db file that have the same characteristics ( data sources in NK folder, databex version). Arguments:
database_folder_path (str): Database folder path dbx_version (str): databex version scripts_version (str): scripts sql file version. By default, its value is an empty string
- Returns:
Union[bool, str]: it returns the db file path if there is a db file with the same characteristics, else it returns False.
- delete_info_with_no_db_folder(json_file)
This method deletes the db info that has no correspond db folder. Arguments:
json_file (str): db_info.json path, the path to the json file which stores the info the databases.
- get_db_at_runtime(database_folder_path, timeout=1800)
This method aims to get an existing db file or to generate a new db file. Arguments:
database_folder_path (str): Database folder path timeout (int): db file generation subprocess timeout
- Returns:
bool, str: if there is a db file it returns ” True, db file path “, else it returns ” False, “” “
- get_db_file_info(db_path)
This method extracts the db file info. Arguments:
db_path (str): db file path
- Returns:
dict: the extracted db file info.
- check_db_file_info(db_info)
This method checks whether the given info is the same as that extracted from the db file. Arguments:
db_info (dict): db file info
- Returns:
- bool, dict: if the two info is the same, it returns ” True, None ” else it returns ” False, the extracted info from the db file “.
If a problem occurred during extracting info from the db file it returns ” False, None “.
- update_json_db_info(old_info, new_info)
This method updates info in the json file with new info. If the new info is already present in the json file, then the existing info and its corresponding db file will be deleted and the new info added. Arguments:
old_info (dict): the info to be replaced new_info (dict): the info to be added
- get_sql_scripts_version(sql_file)
This method aims to get the views scripts version from the sql file path. Arguments:
scripts_path (str): databex_views.sql path
- Returns:
str: sql scripts version
- get_scripts_version(database_folder_path)
This method aims to get the views scripts version from the input nk folder path. It searches for the sql file in the nk folder and returns its version, otherwise, if there is no sql file, it returns an empty string Arguments:
database_folder_path (str): Database folder path
- Returns:
str: sql scripts version