"""Expenses model tests.""" from moneyhub.models import Expenses from tests.unit.conftest import using_mock_snowflake_table _MOCK_DATA = { 'combined_expenses_dbt': [ { 'worksheet_adjustment_detail_id': 1, 'account_id': 24601, 'contract_id': 1001, 'activity_statement_period_id': 123, 'apply_to_statement_period_id': 123, 'distribution_type': 'digital', 'reference_adjustment_type_id': 1, 'reference_adjustment_type_name': 'Label Earnings', 'note': 'mock adjustment', 'upc': '87654321', 'artist_id': 12341231, 'artist_name': 'Pharoah Sanders', 'subaccount_id': 7116, 'subaccount_name': 'Subaccount Name', 'adjustment_amount_payee_currency': 800.00, 'adjustment_payee_currency_code': 'GBP', }, { 'worksheet_adjustment_detail_id': 2, 'account_id': 24601, 'contract_id': 1001, 'activity_statement_period_id': 124, 'apply_to_statement_period_id': 124, 'distribution_type': 'digital', 'reference_adjustment_type_id': 1, 'reference_adjustment_type_name': 'Label Earnings', 'note': 'mock adjustment', 'upc': '12345678', 'artist_id': 12341231, 'artist_name': 'Pharoah Sanders', 'subaccount_id': 7116, 'subaccount_name': 'Subaccount Name', 'adjustment_amount_payee_currency': 800.00, 'adjustment_payee_currency_code': 'GBP', }, { 'worksheet_adjustment_detail_id': 3, 'account_id': 24601, 'contract_id': 1001, 'activity_statement_period_id': 123, 'apply_to_statement_period_id': 123, 'distribution_type': 'digital', 'reference_adjustment_type_id': 1, 'reference_adjustment_type_name': 'Label Earnings', 'note': 'mock adjustment', 'upc': '87654321', 'artist_id': None, 'artist_name': None, 'adjustment_amount_payee_currency': 800.00, 'subaccount_id': 7111, 'subaccount_name': 'Another Subaccount Name', 'adjustment_payee_currency_code': 'GBP', }, { 'worksheet_adjustment_detail_id': 4, 'account_id': 999, 'contract_id': 1001, 'activity_statement_period_id': 123, 'apply_to_statement_period_id': 123, 'distribution_type': 'digital', 'reference_adjustment_type_id': 1, 'reference_adjustment_type_name': 'Label Earnings', 'note': 'mock adjustment', 'upc': '43214321', 'artist_id': 12341232, 'artist_name': 'Artist for other account', 'subaccount_id': 8989, 'subaccount_name': 'Another Subaccount Account', 'adjustment_amount_payee_currency': 800.00, 'adjustment_payee_currency_code': 'GBP', }, { 'worksheet_adjustment_detail_id': 5, 'account_id': 24601, 'contract_id': 1001, 'activity_statement_period_id': 124, 'apply_to_statement_period_id': 124, 'distribution_type': 'physical', 'reference_adjustment_type_id': 2, 'reference_adjustment_type_name': 'Label Earnings', 'note': 'mock adjustment', 'upc': '12345678', 'artist_id': 12341233, 'artist_name': 'Another artist', 'adjustment_amount_payee_currency': 800.00, 'subaccount_id': 7111, 'subaccount_name': 'Another Subaccount Name', 'adjustment_payee_currency_code': 'GBP', }, ] } @using_mock_snowflake_table(Expenses, _MOCK_DATA) def test_get_by_account_id(): """Test to get ledger adjustments details for a specified account.""" account_id = 24601 (items, total_record) = Expenses.get_by_account_id( account_id, 50, 0, None, None, None, None, None, None, None) assert [item.worksheet_adjustment_detail_id for item in items] == [2, 5, 1, 3] @using_mock_snowflake_table(Expenses, _MOCK_DATA) def test_get_by_account_id_and_statement_period_range(): """Test ledger adjustments details for a specified account with statement period range.""" account_id = 24601 statement_period_id_start = 120 statement_period_id_end = 130 (items, total_record) = Expenses.get_by_account_id( account_id, 50, 0, None, statement_period_id_start, statement_period_id_end, None, None, None) assert [item.worksheet_adjustment_detail_id for item in items] == [2, 5, 1, 3] @using_mock_snowflake_table(Expenses, _MOCK_DATA) def test_get_by_account_id_with_upc_distribution_type(): """Test to get ledger adjustments details for a specified account filtered by UPC and type.""" account_id = 24601 upc = '12345678' (items, total_record) = Expenses.get_by_account_id( account_id, 50, 0, None, None, None, upc, 'digital', None) assert total_record == 1 assert [item.distribution_type for item in items] == ['digital'] assert [item.upc for item in items] == [upc] @using_mock_snowflake_table(Expenses, _MOCK_DATA) def test_get_by_account_id_with_artist_id(): """Test to get ledger adjustments details for a specified account filtered by artist_id.""" account_id = 24601 artist_id = 12341231 (items, total_record) = Expenses.get_by_account_id( account_id, 50, 0, None, None, None, artist_id=artist_id) assert total_record == 2 @using_mock_snowflake_table(Expenses, _MOCK_DATA) def test_get_by_account_id_with_subaccount_id_id(): """Test to get expenses details for a specified account filtered by subaccount_id.""" account_id = 24601 subaccount_id = 7116 (items, total_record) = Expenses.get_by_account_id( account_id, 50, 0, None, None, None, subaccount_id=subaccount_id) assert total_record == 2 @using_mock_snowflake_table(Expenses, _MOCK_DATA) def test_get_by_account_id_with_empty_artist_id(): """Test to get ledger adjustments details for a specified account filtered by artist_id.""" account_id = 24601 artist_id = 0 (items, total_record) = Expenses.get_by_account_id( account_id, 50, 0, None, None, None, artist_id=artist_id) assert total_record == 1 @using_mock_snowflake_table(Expenses, _MOCK_DATA) def test_get_by_account_id_with_group_by(): """Test to get ledger adjustments details grouped by UPC.""" account_id = 24601 upc = '12345678' group_by = 'upc' (items, total_record) = Expenses.get_by_account_id( account_id, 50, 0, None, None, None, upc, None, None, None, None, group_by) assert [item.upc for item in items] == [upc, upc] assert [item.distribution_type for item in items] == ['digital', 'physical'] assert total_record == 2 @using_mock_snowflake_table(Expenses, _MOCK_DATA) def test_get_subaccounts_by_account(): """Test getting subaccounts based on an account.""" account_id = 24601 result = Expenses.get_expenses_subaccounts_by_account_id(account_id) assert [dict(item) for item in result] == [ { 'account_id': account_id, 'subaccount_id': 7111, 'subaccount_name': 'Another Subaccount Name', }, { 'account_id': account_id, 'subaccount_id': 7116, 'subaccount_name': 'Subaccount Name' } ] @using_mock_snowflake_table(Expenses, _MOCK_DATA) def test_get_by_account_id_with_group_by_expense_type_id(): """Test to get ledger adjustments details grouped by expense type id.""" account_id = 24601 group_by = 'expense_type_id' (items, total_record) = Expenses.get_by_account_id( account_id, 50, 0, None, None, None, None, None, None, None, None, group_by) assert total_record == 2 @using_mock_snowflake_table(Expenses, _MOCK_DATA) def test_get_by_account_id_with_expense_type(): """Test to get expenses for a specified account filtered by expenses type.""" account_id = 24601 expense_type_id = 2 (items, total_record) = Expenses.get_by_account_id( account_id, 50, 0, None, None, None, None, None, expense_type_id) assert [item.reference_adjustment_type_id for item in items] == [2] @using_mock_snowflake_table(Expenses, _MOCK_DATA) def test_get_artists_by_account(): """Test getting artists based on an account.""" account_id = 24601 result = Expenses.get_artists_by_account(account_id) assert [dict(item) for item in result] == [ {'artist_id': None, 'artist_name': None}, {'artist_id': 12341233, 'artist_name': 'Another artist'}, {'artist_id': 12341231, 'artist_name': 'Pharoah Sanders'}, ] @using_mock_snowflake_table(Expenses, _MOCK_DATA) def test_get_upcs_by_account(): """Test getting UPCs based on an account.""" account_id = 24601 result = Expenses.get_upcs_by_account(account_id) assert [dict(item) for item in result] == [ {'account_id': account_id, 'distribution_type': 'digital', 'upc': '12345678'}, {'account_id': account_id, 'distribution_type': 'physical', 'upc': '12345678'}, {'account_id': account_id, 'distribution_type': 'digital', 'upc': '87654321'} ] @using_mock_snowflake_table(Expenses, _MOCK_DATA) def test_get_account_adjustment_detail_activity(): """Test getting adjustment detail activity.""" account_id = 24601 result = Expenses.get_account_adjustment_detail_activity(account_id) assert bool(result) is True @using_mock_snowflake_table(Expenses, _MOCK_DATA) def test_get_account_adjustment_detail_activity_no_activity(): """Test getting adjustment detail activity no activity.""" account_id = 24602 result = Expenses.get_account_adjustment_detail_activity(account_id) assert bool(result) is False