"""Test configs.""" import io import json from airflow.www.app import create_app import pytest @pytest.fixture(scope='session') def test_app(): """Create a test application.""" return create_app(testing=True) @pytest.fixture def test_client(test_app): """Create a test client.""" return test_app.test_client() @pytest.fixture def accounting_run_commit_request_data(): """Return requests params for triggering accounting_run_commit dag.""" return { 'accounting_period_id': 333, 'accounting_period_name': 'test_period', 'run_controller_name': 'test_controller', 'target_id': 1, 'target_type': 'accounting_run' } @pytest.fixture def accounting_run_commit_dag_config(accounting_run_commit_request_data): """Build config for accounting_run_commit dag.""" return accounting_run_commit_request_data @pytest.fixture def lambda_response_success(): """Return a successful lambda response.""" return { 'ResponseMetadata': { 'RequestId': '688af35d-3a99-4399-a1a9-485e56bd000e', 'HTTPStatusCode': 200, 'HTTPHeaders': { 'date': 'Tue, 14 Jul 2020 03:02:38 GMT', 'content-type': 'application/json', 'content-length': '53', 'connection': 'keep-alive', 'x-amzn-requestid': '688af35d-3a99-4399-a1a9-485e56bd000e', 'x-amzn-remapped-content-length': '0', 'x-amz-executed-version': '$LATEST', 'x-amz-log-result': '', 'x-amzn-trace-id': 'root=1-5f0d204e-208f3fc009571fc8fd2e5570;sampled=0' # noqa: E501 }, 'RetryAttempts': 0 }, 'StatusCode': 200, 'LogResult': '', 'ExecutedVersion': '$LATEST', 'Payload': io.BytesIO(b'{"statusCode": 200, "body": "Hello from Lambda!"}') } @pytest.fixture def lambda_response_error(): """Return an error lambda response.""" return { 'ResponseMetadata': { 'RequestId': '01bb3d7b-2217-48c9-9df4-ce8bcb8395ad', 'HTTPStatusCode': 200, 'HTTPHeaders': { 'date': 'Tue, 14 Jul 2020 03:07:19 GMT', 'content-type': 'application/json', 'content-length': '176', 'connection': 'keep-alive', 'x-amzn-requestid': '01bb3d7b-2217-48c9-9df4-ce8bcb8395ad', 'x-amz-function-error': 'Unhandled', 'x-amzn-remapped-content-length': '0', 'x-amz-executed-version': '$LATEST', 'x-amz-log-result': '', 'x-amzn-trace-id': 'root=1-5f0d2167-0c769076c917303800a8222b;sampled=0' # noqa: E501 }, 'RetryAttempts': 0 }, 'StatusCode': 200, 'FunctionError': 'Unhandled', 'LogResult': '', 'ExecutedVersion': '$LATEST', 'Payload': io.BytesIO(b'{"errorMessage": "This did not work", "errorType": "ValueError", "stackTrace": [["/var/task/lambda_function.py", 5, "lambda_handler", "raise ValueError(\'This did not work\')"]]}') # noqa: E501 } @pytest.fixture def payments_generate_request_data(): """Return requests params for triggering payments_generate dag.""" return { 'abacus_event_id': 1, 'event_name': 'payments_generate', 'target_id': 1, 'target_type': 'payment_group_payment' } @pytest.fixture def payments_generate_dag_config(payments_generate_request_data): """Build config for payments_generate dag.""" return payments_generate_request_data @pytest.fixture def mock_event_partial_data(): """Get a mock event data.""" return { 'abacus_event_id': 1, 'event_date': '2020-07-17 18:57:21.590679', 'event_name': 'foo' } @pytest.fixture def mock_event_data(mock_event_partial_data): """Get a mock event.""" return { **mock_event_partial_data, **{ 'previous_abacus_event_id': None, 'rolled_back_at': None, 'statement_period_id': None, 'target_id': None, 'target_type': None, 'user_id': None, 'user_type': None } } @pytest.fixture def mock_event_json(mock_event_data): """Get a mock event data as json.""" return json.dumps(mock_event_data) @pytest.fixture def mock_contract_mechanicals_response(): """Return contract mechanicals as csv data.""" return 'contract_id\tadmin_fee\tadmin_type\t' \ 'mechanical_deduction_id\tmechanical_type\n' \ '1\t20.20\tboth\t1\tphysical\n' \ '1\t20.20\tboth\t1\tringtone\n' \ '2\t20.20\tboth\t2\tdigital_download\n' @pytest.fixture def mock_accounting_period_state_response(): """Return abacus state data.""" abacus_state = [ { 'action_status': 'complete', 'action_name': 'deliver_sales_files', 'abacus_state_id': 7 }, { 'action_status': 'complete', 'action_name': 'upload_exchange_rates', 'abacus_state_id': 8 }, { 'action_status': 'init', 'action_name': 'prep_mechanical_deductions', 'abacus_state_id': 9 }, { 'action_status': 'init', 'action_name': 'close_period', 'abacus_state_id': 10 } ] return json.dumps(abacus_state) @pytest.fixture def mock_sales_file_state_response(): """Return abacus state data.""" abacus_state = [ { 'action_status': 'complete', 'action_name': 'get_eligible_sales', 'abacus_state_id': 11 }, { 'action_status': 'complete', 'action_name': 'approve_sales', 'abacus_state_id': 12 } ] return json.dumps(abacus_state) @pytest.fixture def mock_ledger_accounting_run_balances(): """Test fixture for ledger_accounting_run_balances data.""" return [ { 'abacus_event_id': 43, 'accounting_run_id': 1, 'account_id': 35977, 'account_name': 'TEST GDA - GBP', 'adjusted_net_revenue': '1210373.80', 'contract_id': 11, 'contract_name': 'TEST GDA - GBP', 'currency_code': 'GBP', 'distribution_fee': '302593.45', 'ledger_accounting_run_balance_id': 2, 'mechanical_deduction_admin_fee_total': '0.00', 'mechanical_deduction_total': '0.00', 'total_adjustment_amount': None, 'total_gross_revenue_amount': '1512967.25', 'total_net_revenue_amount': '1210373.80' }, { 'abacus_event_id': 43, 'accounting_run_id': 1, 'account_id': 35976, 'account_name': 'TEST GDA - GBP - VAT', 'adjusted_net_revenue': '109296.26', 'contract_id': 10, 'contract_name': 'TEST GDA - GBP - VAT', 'currency_code': 'GBP', 'distribution_fee': '27324.07', 'ledger_accounting_run_balance_id': 1, 'mechanical_deduction_admin_fee_total': '0.00', 'mechanical_deduction_total': '0.00', 'total_adjustment_amount': None, 'total_gross_revenue_amount': '136620.33', 'total_net_revenue_amount': '109296.26' } ] @pytest.fixture def mock_statement_period(): """Mock statement_period data.""" return { 'statement_period_status': 'current', 'statement_period_name': 'June 2021', 'statement_period_id': 270, 'closed_date': None } @pytest.fixture def mock_payment_group(): """Mock payment_group data.""" return { 'payment_group_id': 11, 'is_reusable': True, 'group_name': 'Test Payment Group', 'group_criteria': { 'payment_schedules': ['30_days_after_quarter_end'], 'signing_entities': [2], 'reference_payment_entities': [1], 'currency_codes': ['USD'] } } @pytest.fixture def mock_payment_group_payment(): """Mock payment_group_payment data.""" return { 'created_at': '2022-07-01', 'payment_group_payment_id': 22, 'payment_group_id': 11, 'payment_name': 'Make It Rain', 'statement_period_id': 270 } @pytest.fixture def mock_report_payment_group_payment(): """Mock report_payment_group_payment data.""" return [ { 'report_payment_group_payment_id': 1, 'payment_group_payment_id': 22, 'report_export_url': 's3://qa-abacus-payments/22-make-it-rain/summary/summary.tsv', # noqa E501 'report_type': 'summary' }, { 'report_payment_group_payment_id': 2, 'payment_group_payment_id': 22, 'report_export_url': 's3://qa-abacus-payments/22-make-it-rain/approval/approve.pdf', # noqa E501 'report_type': 'approval' } ] @pytest.fixture def mock_payment_group_payment_accounts(): """Mock payment_group_payment_accounts list.""" return [ { 'account_id': 123, 'account_name': '(SME Sweden) GMG Sweden AB', 'account_payee_id': 12, 'balance_after_tax': '667686.00', 'current_balance': '667686.00', 'currency_code': 'CAD', 'currency_name': 'Canadian Dollar', 'current_statement_period_name': 'June 2021', 'last_payment': '0.00', 'last_statement_period_name': 'May 2021', 'note': 'test', 'payment_group_payment_account_id': 17, 'payment_group_payment_id': 22, 'payment_difference': None, 'payoneer_payee_id': 1, 'payoneer_program_id': 100158940, 'percent_difference': '45%', 'tax_withholding': '0.00', 'vat_amount': '0.00' }, { 'account_id': 124, 'account_name': 'Lifestyle Music Pty Ltd', 'account_payee_id': 13, 'balance_after_tax': '787865.00', 'current_balance': '789865.00', 'currency_code': 'GBP', 'currency_name': 'Pound Sterling', 'current_statement_period_name': 'June 2021', 'last_payment': '0.00', 'last_statement_period_name': 'May 2021', 'note': None, 'payment_difference': '789.00', 'payment_group_payment_account_id': 18, 'payment_group_payment_id': 22, 'payoneer_payee_id': 2, 'payoneer_program_id': 100158970, 'percent_difference': '46%', 'tax_withholding': '-3000.00', 'vat_amount': '1000.00' } ] @pytest.fixture def mock_account_payment_term(): """Mock account_payment_term data.""" return { 'account_id': 1012, 'account_payment_term_id': 1, 'currency_code': 'EUR', 'payment_minimum': '25.00', 'payment_schedule': '30_days_after_quarter_end', 'signing_entity_id': 2, 'payment_entity_id': 1 } @pytest.fixture def mock_signing_entities(): """Mock signing_entities data.""" return [{ 'vat_number': None, 'signing_entity_name': 'AWAL Digital Limited (UK)', 'sap_id': None, 'address': None, 'signing_entity_id': 2, 'legal_name': None }] @pytest.fixture def mock_ref_payment_entities(): """Mock reference_payment_entities data.""" return { 'items': [ { 'payment_entity_name': 'AWAL-UK', 'reference_payment_entity_id': 1 }, { 'payment_entity_name': 'AWAL-US', 'reference_payment_entity_id': 2 } ], 'total_count': 2 } @pytest.fixture def mock_formatted_signing_entities(): """Mock formatted signing_entities data.""" return {2: 'AWAL Digital Limited (UK)'} @pytest.fixture def mock_formatted_ref_payment_entities(): """Mock formatted reference_payment_entities data.""" return {1: 'AWAL-UK'} @pytest.fixture def mock_statement_period_adjustment_file_details(): """Mock statement period adjustment file details data.""" return { 'file_name': 'test_file.csv', 'valid_file_location': 's3://qa-abacus-adjustments/valid/location/test_file.csv', 'invalid_file_location': 's3://qa-abacus-adjustments/invalid/location/test_file.csv', 'valid_row_count': 1, 'invalid_row_count': 2, 'valid_row_amount': '3.01', 'invalid_row_amount': '4.02', 'md5sum': 'b6579ec2950296ed6a04f08f67f64422' }