"""Do required things with db prior to the tests.""" from typing import Any import mysql.connector def mysqlclient_docker() -> Any: """Initialize mysql client for docker image.""" return mysql.connector.connect( host='sync-contract-sap-mysql', port='3306', database='royalty_accounting', user='db_user', password='db_pass', ) cnx = mysqlclient_docker() cursor = cnx.cursor() query = """ INSERT INTO account ( account_id, account_name, created_by, created_at, last_modified_by, last_modified ) VALUES ( 1, 'integration tests', 1, '2021-01-01 00:00:00', 1, '2021-01-01 00:00:00' ); """ cursor.execute(query) cnx.commit() query = """ INSERT INTO contract ( contract_id, reference_signing_entity_id, contract_name, term_start, term_end, created_by, created_at, last_modified_by, last_modified ) VALUES ( 1, 1, 'test', '2021-05-06', '2021-05-27', 'vz', NOW(), 'vz', NOW() ); """ cursor.execute(query) cnx.commit() query = """ INSERT INTO accounting_period ( accounting_period_id, accounting_period_name, accounting_period_status, closed_date, statement_period_id, created_by, created_at, last_modified_by, last_modified ) VALUES ( 1, 'period', 'locked', null, 300, 'vz', '2021-05-05 09:39:01', 'vz', '2021-05-05 09:39:04' ); """ cursor.execute(query) cnx.commit() query = """ UPDATE run_controller t SET t.run_controller_name = 'run-thru' WHERE t.run_controller_id = 2686 """ cursor.execute(query) cnx.commit() query = """ INSERT INTO run_controller_contract ( run_controller_contract_id, run_controller_id, contract_id ) VALUES ( 1, 2686, 1 ); """ cursor.execute(query) cnx.commit() query = """ INSERT INTO accounting_run ( accounting_run_id, accounting_period_id, run_controller_id, run_status, start_date, summary_export_url, created_by, created_at, last_modified_by, last_modified ) VALUES ( 2, 1, 2686, 'Committed', '2021-05-06 04:17:37', null, 'vz', '2021-05-05 09:45:47', 'vz', '2021-05-05 09:45:53' ); """ cursor.execute(query) cnx.commit() query = """ INSERT INTO abacus_event ( abacus_event_id, statement_period_id, event_name, target_type, target_id, event_date, previous_abacus_event_id, rolled_back_at ) VALUES ( 1, 300, 'sync_contract_sap', 'contract', 1, '2021-03-09 08:10:20.000000', null, null ); """ cursor.execute(query) cnx.commit() query = """ INSERT INTO account_contract( account_contract_id, account_id, contract_id ) VALUES ( 1, 1, 1 ); """ cursor.execute(query) cnx.commit() query = """ INSERT INTO account_payment_term ( account_payment_term_id, account_id, currency_code, payment_minimum, payment_entity_id, payment_schedule, created_by, created_at, last_modified_by, last_modified ) VALUES ( 1, 1, 'GBP', 42.00, 1, null, 'Test', NOW(), 'Test', NOW() ); """ cursor.execute(query) cnx.commit() query = """ INSERT INTO account_tax_info( account_tax_info_id, account_id, country_of_tax_residence, is_sba_signed, created_by, created_at, last_modified_by, last_modified ) VALUES ( 1, 1, 'USA', 0, 'test', '2021-10-29 13:22:52', 'test', '2021-10-29 13:22:58' ); """ cursor.execute(query) cnx.commit() query = """ INSERT INTO exchange_rate ( exchange_rate_id, statement_period_id, rate, from_currency_code, to_currency_code, created_by, created_at, last_modified_by, last_modified ) VALUES ( 1, 300, 10.000000, 'GBP', 'USD', 'vz', '2022-08-23 03:35:56', 'vz', '2022-08-23 03:35:59' ) """ cursor.execute(query) cnx.commit() query = """ INSERT INTO abacus_state ( parent_table_id, parent_table_name, action_name, action_status, message, created_by, created_at, last_modified_by, last_modified ) VALUES ( 1, 'contract', 'sap_sync', 'init', null, 'vz', '2022-09-13 04:37:58', 'vz', '2022-09-13 04:37:59' ) """ cursor.execute(query) cnx.commit() cnx.close() print('DB fixtures created.')