"""Combined expenses By Imprint model tests.""" from decimal import Decimal from moneyhub.models import ExpensesByImprint from tests.unit.conftest import using_mock_snowflake_table _MOCK_DATA = { 'combined_expenses_by_imprint_dbt': [ { 'account_id': 57608, 'activity_statement_period_id': 30, 'adjustment_amount_payee_currency': Decimal('10.00'), 'adjustment_payee_currency_code': 'JPY', 'apply_to_statement_period_id': 10, 'artist_id': 1234567, 'artist_name': 'Best of the best Artist', 'contract_id': 1, 'imprint_id': 123456, 'imprint': 'TEST IMPRINT', 'subaccount_id': 1, 'reference_adjustment_type_id': 1, 'reference_adjustment_type_name': 'Physical Sales', 'upc': 1234, 'worksheet_adjustment_detail_id': 1 }, { 'account_id': 57608, 'activity_statement_period_id': 10, 'adjustment_amount_payee_currency': Decimal('20.00'), 'adjustment_payee_currency_code': 'GBP', 'apply_to_statement_period_id': 10, 'artist_id': None, 'artist_name': None, 'contract_id': 1, 'imprint_id': 1234567, 'imprint': 'TEST IMPRINT 2', 'subaccount_id': 2, 'reference_adjustment_type_id': 1, 'reference_adjustment_type_name': 'Physical Sales', 'upc': 1234, 'worksheet_adjustment_detail_id': 2 }, { 'account_id': 57608, 'activity_statement_period_id': 40, 'adjustment_amount_payee_currency': Decimal('30.00'), 'adjustment_payee_currency_code': 'USD', 'apply_to_statement_period_id': 20, 'artist_id': 1234567, 'artist_name': 'Best of the best Artist', 'contract_id': 1, 'imprint_id': 12345678, 'imprint': 'TEST IMPRINT 3', 'subaccount_id': 1, 'reference_adjustment_type_id': 1, 'reference_adjustment_type_name': 'Physical Sales', 'upc': 1234, 'worksheet_adjustment_detail_id': 3 }, ], } ACCOUNT_ID = 57608 VISIBLE_PERIODS = [10, 20, 30] @using_mock_snowflake_table(ExpensesByImprint, _MOCK_DATA) def test_get_by_account_id(): """Test getting revenue by account.""" (items, total_record) = ExpensesByImprint.get_by_imprint_account_id(ACCOUNT_ID, 50, 0) actual = items[0]._asdict() assert actual == { 'imprint_id': 123456, 'imprint': 'TEST IMPRINT', 'account_id': 57608, 'subaccount_id': 1, 'adjustment_payee_currency_code': 'JPY', 'adjustment_amount_payee_currency': Decimal('10.00'), 'total_records': 3, } @using_mock_snowflake_table(ExpensesByImprint, _MOCK_DATA) def test_get_by_account_id_with_filters(): """Test getting by account with filters.""" contract_id = 1 statement_period_id_start = 20 statement_period_id_end = 30 artist_id = 1234567 (items, total_record) = ExpensesByImprint.get_by_imprint_account_id( ACCOUNT_ID, 50, 0, contract_id, statement_period_id_start, statement_period_id_end, artist_id=artist_id ) actual = items[0]._asdict() assert actual == { 'imprint_id': 12345678, 'imprint': 'TEST IMPRINT 3', 'account_id': 57608, 'subaccount_id': 1, 'adjustment_payee_currency_code': 'USD', 'adjustment_amount_payee_currency': Decimal('30.00'), 'total_records': 1, } @using_mock_snowflake_table(ExpensesByImprint, _MOCK_DATA) def test_get_by_account_id_with_empty_artist_id(): """Test getting by account with an empty artist ID.""" (items, total_records) = ExpensesByImprint.get_by_imprint_account_id( ACCOUNT_ID, 50, 0, artist_id=0 ) assert total_records == 1 assert [item._asdict() for item in items] == [ { 'imprint_id': 1234567, 'imprint': 'TEST IMPRINT 2', 'account_id': 57608, 'subaccount_id': 2, 'adjustment_payee_currency_code': 'GBP', 'adjustment_amount_payee_currency': Decimal('20.00'), 'total_records': 1, }, ]