"""Integration test configuration.""" import os from dotenv import load_dotenv import mysql.connector import pytest from tests.integration.utils.ows_abacus_adjustment_api_client import \ AbacusAdjustmentAPIClient # Load environment variables from a .env file if present dotenv_path = os.path.join(os.path.dirname(__file__), '.env') load_dotenv(dotenv_path) QA_BASE_URL = os.environ.get('QA_BASE_URL', 'http://localhost:6652') @pytest.fixture def basic_headers(): """Return basic headers.""" return {'Content-Type': 'application/json'} def ows_abacus_adjustment_api_client(basic_headers): """Create ows-abacus-adjustment client.""" return AbacusAdjustmentAPIClient(QA_BASE_URL, basic_headers) def db_connector(): """Create a db connector instance.""" cnx = mysql.connector.connect( host=os.environ.get('MYSQL_HOST', '127.0.0.1'), port=os.environ.get('MYSQL_PORT', '6650'), database=os.environ.get('MYSQL_DB', 'royalty_accounting'), user=os.environ.get('MYSQL_USER', 'royalties'), password=os.environ.get('MYSQL_PASS', '1234')) return cnx def clear_db(): """Clean tables between runs.""" cnx = db_connector() tables = [] cursor = cnx.cursor() cursor.execute('SET FOREIGN_KEY_CHECKS=0;') for table in tables: cursor.execute( """TRUNCATE TABLE {};""".format(table)) cursor.execute('SET FOREIGN_KEY_CHECKS=1;') cnx.close() def create_db_fixture(query): """Create a DB fixture.""" cnx = db_connector() cursor = cnx.cursor() cursor.execute(query) cnx.commit() cnx.close()