import sys from ytownership import config from ytownership.connectors.mysql import session_scope CREATE_LOG_TABLE = """ CREATE TABLE `yt_api_log` ( `id` INTEGER PRIMARY KEY, `content_owner_id` VARCHAR(100) NOT NULL, `correlation_id` VARCHAR(100) NOT NULL, `isrc` VARCHAR(20) NOT NULL, `territories` VARCHAR(45) NOT NULL, `created_date_utc` DATETIME NOT NULL, `status` VARCHAR(20) NOT NULL, `code` INT NULL, `message` TEXT NOT NULL) """ DROP_LOG_TABLE = """ DROP TABLE IF EXISTS `yt_api_log`; """ def create_log_table(): with session_scope() as session: session.execute(CREATE_LOG_TABLE) def drop_log_table(): with session_scope() as session: session.execute(DROP_LOG_TABLE) def exit_if_not_test_environment(): """For safety, only run tests in test environment pointed to sqlite Exit immediately if not in test environment or not pointed to sqlite """ with session_scope() as session: if config.ENVIRONMENT != config.ENVIRONMENT_TEST: sys.exit('Environment must be set to {}'.format( config.ENVIRONMENT_TEST)) elif 'sqlite' not in session.bind.url.drivername: sys.exit('Tests must point to sqlite database')