"""Create database fixtures for tests.""" import mysql.connector cnx = mysql.connector.connect( host='adjustments-apply-mysql', port='3306', database='royalty_accounting', user='db_user', password='db_pass', ) cursor = cnx.cursor() insert_accounts = """ INSERT INTO account ( account_id, account_name, created_by, created_at, last_modified_by, last_modified ) VALUES ( 1, 'Test Account', 'test', NOW(), 'test', NOW() ); """ cursor.execute(insert_accounts) cnx.commit() insert_contracts = """ INSERT INTO contract ( contract_id, reference_signing_entity_id, reference_sap_profit_center_id, contract_name, term_start, term_end, created_by, created_at, last_modified_by, last_modified ) VALUES ( 1, 1, 1, 'Test Contract', '2021-05-06', '2021-05-27', 'test', NOW(), 'test', NOW() ); """ cursor.execute(insert_contracts) cnx.commit() insert_account_contracts = """ INSERT INTO account_contract( account_contract_id, account_id, contract_id ) VALUES (1, 1, 1); """ cursor.execute(insert_account_contracts) cnx.commit() insert_account_payment_terms = """ 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(insert_account_payment_terms) cnx.commit() insert_exchange_rate = """ 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, 282, 10.000000, 'USD', 'GBP', 'vz', '2022-08-23 03:35:56', 'vz', '2022-08-23 03:35:59' ); """ cursor.execute(insert_exchange_rate) cnx.commit() update_run_controller = """ UPDATE run_controller SET run_controller_name = 'run-thru' WHERE run_controller_id = 2686 """ cursor.execute(update_run_controller) cnx.commit() update_statement_period = """ UPDATE statement_period SET statement_period_status = 'current' WHERE statement_period_id = 282; """ cursor.execute(update_statement_period) cnx.commit() update_statement_period_payment_entity = """ UPDATE statement_period_payment_entity SET reference_payment_entity_id = 1 WHERE statement_period_payment_entity_id = 1; """ cursor.execute(update_statement_period_payment_entity) cnx.commit() insert_adjustment_files = """ INSERT INTO statement_period_adjustment_file ( statement_period_adjustment_file_id, statement_period_id, file_name, created_by, created_at, last_modified_by, last_modified ) VALUES ( 1, 282, 'Test File 1', 'test', NOW(), 'test', NOW() ), ( 2, 282, 'Test File 1', 'test', NOW(), 'test', NOW() ); """ cursor.execute(insert_adjustment_files) cnx.commit() insert_abacus_events = """ INSERT INTO abacus_event ( abacus_event_id, statement_period_id, event_name, target_type, target_id, event_date ) VALUES ( 1, 282, 'adjustment_file_worksheet_import', 'statement_period_adjustment_file', 1, NOW() ), ( 2, 282, 'adjustment_file_worksheet_import', 'statement_period_adjustment_file', 1, NOW() ), ( 3, 282, 'apply_pending_adjustments', 'statement_period_adjustment_file', 1, NOW() ), ( 4, 282, 'apply_pending_adjustments', 'statement_period_adjustment_file', 2, NOW() ); """ cursor.execute(insert_abacus_events) cnx.commit() insert_worksheet_adjustments = """ INSERT INTO worksheet_adjustment ( worksheet_adjustment_id, statement_period_adjustment_file_id, abacus_event_id, account_id, contract_id, activity_statement_period_id, apply_to_statement_period_id, reference_adjustment_type_id, adjustment_amount, adjustment_currency_code, created_by, created_at, last_modified_by, last_modified ) VALUES ( 1, 1, 1, 1, 1, 282, 282, 1, 100.00, 'USD', 'test', NOW(), 'test', NOW() ), ( 2, 2, 2, 1, 1, 282, 282, 1, 100.00, 'GBP', 'test', NOW(), 'test', NOW() ) """ cursor.execute(insert_worksheet_adjustments) cnx.commit() insert_abacus_states = """ INSERT INTO abacus_state( abacus_state_id, parent_table_id, parent_table_name, action_name, action_status, created_by, created_at, last_modified_by, last_modified ) VALUES ( 100, 1, 'statement_period_payment_entity', 'close_balance', 'init', 'test', NOW(), 'test', NOW() ); """ cursor.execute(insert_abacus_states) cnx.commit() cnx.close() print('DB fixtures created.')