"""Misc db_helper methods.""" import os import mysql.connector def check_db_empty(compare_func, table='ledger_accounting_run_balance'): """Check whether table is empty.""" cnx = mysql.connector.connect( host=os.environ.get('MYSQL_DB_HOST', '127.0.0.1'), port=os.environ.get('MYSQL_DB_PORT', '6053'), database=os.environ.get('MYSQL_DB_NAME', 'royalty_accounting'), user=os.environ.get('MYSQL_DB_USER', 'royalties'), password=os.environ.get('MYSQL_DB_PASS', '1234'), ) cursor = cnx.cursor() cursor.execute('SELECT * FROM {}'.format(table)) cursor.fetchall() rc = cursor.rowcount assert compare_func(rc, 0) cursor.close() cnx.close()