Db Generator Module

class mtf.test_utilities.db_generator.DbGenerator

Automate database generation.This class implements automated database generation using the DaTaBeX CLI tool. It checks for existing databases with matching characteristics to avoid redundant database generation. The generated DB files info is stored in a JSON file.

databex_path
json_path
__init__(databex_cli_path_: str = None)

Create a new instance.

Args:

databex_cli_path (str): The path to the DaTaBeX CLI tool (default: None).

Returns:

DbGenerator: The newly created instance.

get_dbx_version(dbx_cli_path)

Get the DaTaBeX version.

Args:

dbx_cli_path (str): The path to the DaTaBeX CLI tool.

Returns:

str: The version string or the error message of the tool / subprocess.

generate_db(dbx_cli_path, database_folder_path, dbx_version, scripts_version='', timeout=1800, apply_merge=False, adaptive_files_path=None)

Generate the database using the given parameters.

Args:

dbx_cli_path (str): The path to te DaTaBeX CLI tool. database_folder_path (str): The path to the database folder. dbx_version (str): dataBEx version. scripts_version (str, optional): The SQL file version (default: “”). timeout (int, optional): The timeout of the subprocess (default: 1800). apply_merge (bool, optional): Whether to apply the “–merge” argument (default: False). adaptive_files_path (str, optional): The path to adapted files (default: None).

Returns:

bool, str: True and the database file path on success, False otherwise.

detect_db_existence(database_folder_path, dbx_version, cli_options='', scripts_version='', adaptive_folder=None)

Search for a database specified by the given parameters.

Args:

database_folder_path (str): The path to detect databases in. dbx_version (str): The DaTaBeX CLI tool version. cli_options (str): Additional DaTaBeX CLI tool arguments (default: “”). scripts_version (str): The scripts sql file version (default: “”). adaptive_folder (str option): An additional adaptive folder to search (default: None).

Returns:

Union[bool, str]: The DB file path on success, False otherwise.

delete_info_with_no_db_folder(json_file)

Delete info with no corresponding DB folder.

Args:

json_file (str): The JSON file to delete from.

get_db_at_runtime(database_folder_path, timeout=1800, apply_merge=False)

Get an existing or generate a new database.

Args:

database_folder_path (str): Database folder path. timeout (int): The db file generation timeout in ms (default: 1800). apply_merge (bool): Whether to apply the merge CLI argument.

Returns:

bool, str: True and the db file path on success, False otherwise.

get_db_file_info(db_path)

Get the DB info.

Args:

db_path (str): The path containing the database file.

Returns:

dict: The extracted DB file info.

check_db_file_info(db_info)

Check whether the given DB information equals the extracted one.

Args:

db_info (dict): The DB information to check.

Returns:

bool, dict: (True, None) when the information matches, (False, None) if an error occurred or (False, extracted_info) when the information does not match.

update_json_db_info(old_info, new_info)

Replace the given old information with the given new one.

Args:

old_info (dict): the information to be replaced. new_info (dict): the information to be added.

get_sql_scripts_version(sql_file)

Get the SQL script version of the given file.

Args:

scripts_path (str): The SQL file path to get the version from.

Returns:

str: The SQLs scripts version.

get_scripts_version(database_folder_path)

Get the SQL script version from the given path.

Args:

database_folder_path (str): The database folder to retrieve the version from.

Returns:

str: The SQL script version on success, “” otherwise.