"""Combined expenses By Artist model tests.""" from decimal import Decimal from moneyhub.models import ExpensesByArtist from tests.unit.conftest import using_mock_snowflake_table ACCOUNT_ID = 24601 _MOCK_DATA = { 'combined_expenses_by_artist_dbt': [ { 'account_id': ACCOUNT_ID, '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': 123456, 'artist_name': 'Best Artist', 'contract_id': 1, 'reference_adjustment_type_id': 1, 'reference_adjustment_type_name': 'Physical Sales', 'upc': 1234, 'worksheet_adjustment_detail_id': 1 }, { 'account_id': ACCOUNT_ID, '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, 'reference_adjustment_type_id': 1, 'reference_adjustment_type_name': 'Physical Sales', 'upc': 1234, 'worksheet_adjustment_detail_id': 2 }, { 'account_id': ACCOUNT_ID, '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': 12345678, 'artist_name': 'Super Artist', 'contract_id': 1, 'reference_adjustment_type_id': 1, 'reference_adjustment_type_name': 'Physical Sales', 'upc': 1234, 'worksheet_adjustment_detail_id': 3 }, ], } @using_mock_snowflake_table(ExpensesByArtist, _MOCK_DATA) def test_get_by_account_id(): """Test getting revenue by account.""" (items, total_records) = ExpensesByArtist.get_by_artist_by_account_id(ACCOUNT_ID, 50, 0) assert total_records == 3 assert [item._asdict() for item in items] == [ { 'artist_id': None, 'artist_name': None, 'account_id': 24601, 'adjustment_payee_currency_code': 'GBP', 'adjustment_amount_payee_currency': Decimal('20.00'), 'total_records': 3, }, { 'artist_id': 123456, 'artist_name': 'Best Artist', 'account_id': 24601, 'adjustment_payee_currency_code': 'JPY', 'adjustment_amount_payee_currency': Decimal('10.00'), 'total_records': 3, }, { 'artist_id': 12345678, 'artist_name': 'Super Artist', 'account_id': 24601, 'adjustment_payee_currency_code': 'USD', 'adjustment_amount_payee_currency': Decimal('30.00'), 'total_records': 3, }, ] @using_mock_snowflake_table(ExpensesByArtist, _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 = 12345678 (items, total_records) = ExpensesByArtist.get_by_artist_by_account_id( ACCOUNT_ID, 50, 0, contract_id, statement_period_id_start, statement_period_id_end, artist_id=artist_id ) assert total_records == 1 assert [item._asdict() for item in items] == [ { 'artist_id': 12345678, 'artist_name': 'Super Artist', 'account_id': 24601, 'adjustment_payee_currency_code': 'USD', 'adjustment_amount_payee_currency': Decimal('30.00'), 'total_records': 1, }, ] @using_mock_snowflake_table(ExpensesByArtist, _MOCK_DATA) def test_get_by_account_id_with_empty_artist_id(): """Test getting by account with an empty artist ID.""" (items, total_records) = ExpensesByArtist.get_by_artist_by_account_id( ACCOUNT_ID, 50, 0, artist_id=0 ) assert total_records == 1 assert [item._asdict() for item in items] == [ { 'artist_id': None, 'artist_name': None, 'account_id': 24601, 'adjustment_payee_currency_code': 'GBP', 'adjustment_amount_payee_currency': Decimal('20.00'), 'total_records': 1, }, ]