"""Revenue by activity month type model tests.""" from decimal import Decimal from moneyhub.models import RevenueByActivityMonth from tests.unit.conftest import using_mock_snowflake_table from tests.utils.factories import DimSubaccountFactory ACCOUNT_ID = 24601 _MOCK_DATA = { 'revenue_by_activity_month_dbt': [ { 'account_id': 24601, 'account_payee_currency': 'USD', 'activity_period_id': 9, 'activity_month_name': 'June 2024', 'artist_id': 1, 'subaccount_id': 1, 'product_id': 1, 'track_unique_id': 1234556, 'contract_id': 10001, 'statement_period_id': 10, 'net_share_payee_currency': Decimal('10.00'), 'gross_revenue_payee_currency': Decimal('8.00'), 'net_publishing_revenue_payee_currency': None, 'gross_publishing_revenue_payee_currency': None, 'imprint_id': 101, 'store_id': 201, 'country_code': 'US', 'transaction_type_id': 301, 'project_id': 1, }, { 'account_id': 24601, 'account_payee_currency': 'USD', 'activity_period_id': 9, 'activity_month_name': 'June 2024', 'artist_id': 2, 'subaccount_id': 2, 'product_id': 2, 'track_unique_id': 1234554, 'contract_id': 10001, 'statement_period_id': 10, 'net_share_payee_currency': Decimal('10.00'), 'gross_revenue_payee_currency': Decimal('8.00'), 'net_publishing_revenue_payee_currency': None, 'gross_publishing_revenue_payee_currency': None, 'imprint_id': 102, 'store_id': 202, 'country_code': 'GB', 'transaction_type_id': 302, 'project_id': 2, }, { 'account_id': 24601, 'account_payee_currency': 'USD', 'activity_period_id': 10, 'activity_month_name': 'July 2024', 'artist_id': 1, 'subaccount_id': 1, 'product_id': 1, 'track_unique_id': 1234556, 'contract_id': 10002, 'statement_period_id': 12, 'net_share_payee_currency': Decimal('12.00'), 'gross_revenue_payee_currency': Decimal('9.00'), 'net_publishing_revenue_payee_currency': None, 'gross_publishing_revenue_payee_currency': None, 'imprint_id': 101, 'store_id': 201, 'country_code': 'US', 'transaction_type_id': 301, 'project_id': 1, }, { 'account_id': 24601, 'account_payee_currency': 'USD', 'activity_period_id': 10, 'activity_month_name': 'July 2024', 'artist_id': 1, 'subaccount_id': 1, 'product_id': 1, 'track_unique_id': 1234556, 'contract_id': 10001, 'statement_period_id': 20, 'net_share_payee_currency': None, 'gross_revenue_payee_currency': None, 'net_publishing_revenue_payee_currency': Decimal('13.00'), 'gross_publishing_revenue_payee_currency': Decimal('15.00'), 'imprint_id': 101, 'store_id': 201, 'country_code': 'US', 'transaction_type_id': 301, 'project_id': 1, }, { 'account_id': 99999, 'account_payee_currency': 'USD', 'activity_period_id': 10, 'activity_month_name': 'July 2024', 'artist_id': 3, 'subaccount_id': 3, 'product_id': 3, 'track_unique_id': 1234478, 'contract_id': 10001, 'statement_period_id': 20, 'net_share_payee_currency': Decimal('15.00'), 'gross_revenue_payee_currency': Decimal('13.00'), 'net_publishing_revenue_payee_currency': None, 'gross_publishing_revenue_payee_currency': None, 'imprint_id': 103, 'store_id': 203, 'country_code': 'CA', 'transaction_type_id': 303, 'project_id': 1, }, ], } @using_mock_snowflake_table(RevenueByActivityMonth, _MOCK_DATA) def test_get_activity_periods_by_account_id(): """Test getting activity period by account ID.""" expected = [ { 'activity_period_id': 9, 'activity_month_name': 'June 2024', }, { 'activity_period_id': 10, 'activity_month_name': 'July 2024', }, ] results = RevenueByActivityMonth.get_activity_periods_by_account_id( 24601, None, None) assert [item._asdict() for item in results] == expected @using_mock_snowflake_table(RevenueByActivityMonth, _MOCK_DATA) def test_get_activity_periods_by_account_id_and_subaccount_id(): """Test getting activity period by account ID and contract ID.""" expected = [ { 'activity_period_id': 9, 'activity_month_name': 'June 2024', }, ] results = RevenueByActivityMonth.get_activity_periods_by_account_id( 24601, 2, None) assert [item._asdict() for item in results] == expected @using_mock_snowflake_table(RevenueByActivityMonth, _MOCK_DATA) def test_get_activity_periods_by_account_id_and_activity_periods(): """Test getting activity period by account ID and activity period IDs.""" expected = [ { 'activity_period_id': 10, 'activity_month_name': 'July 2024', }, ] results = RevenueByActivityMonth.get_activity_periods_by_account_id( 24601, None, [10]) assert [item._asdict() for item in results] == expected @using_mock_snowflake_table(RevenueByActivityMonth, _MOCK_DATA) def test_get_revenue_by_activity_month_by_account_id(): """Test getting revenue by activity month for an account.""" expected = [ { 'activity_period_id': Decimal('10'), 'activity_month_name': 'July 2024', 'account_payee_currency': 'USD', 'net_share_payee_currency': Decimal('12.000000000000'), 'gross_revenue_payee_currency': Decimal('9.000000000000'), 'net_publishing_revenue_payee_currency': None, 'gross_publishing_revenue_payee_currency': None, 'total_records': 2, }, { 'activity_period_id': Decimal('9'), 'activity_month_name': 'June 2024', 'account_payee_currency': 'USD', 'net_share_payee_currency': Decimal('10.000000000000'), 'gross_revenue_payee_currency': Decimal('8.000000000000'), 'net_publishing_revenue_payee_currency': None, 'gross_publishing_revenue_payee_currency': None, 'total_records': 2, }, ] (items, total_record) = RevenueByActivityMonth.get_revenue_by_activity_month_by_account_id( 24601, 50, 0, 1, 1, 1, 1234556, None, 10, 12, None, None) assert [item._asdict() for item in items] == expected @using_mock_snowflake_table(RevenueByActivityMonth, _MOCK_DATA) def test_get_revenue_by_activity_month_with_filters(): """Test getting revenue by activity month with filters.""" expected = [ { 'activity_period_id': Decimal('10'), 'activity_month_name': 'July 2024', 'account_payee_currency': 'USD', 'net_share_payee_currency': Decimal('12.000000000000'), 'gross_revenue_payee_currency': Decimal('9.000000000000'), 'net_publishing_revenue_payee_currency': Decimal('13.000000000000'), 'gross_publishing_revenue_payee_currency': Decimal('15.000000000000'), 'total_records': 2, }, { 'activity_period_id': Decimal('9'), 'activity_month_name': 'June 2024', 'account_payee_currency': 'USD', 'net_share_payee_currency': Decimal('10.000000000000'), 'gross_revenue_payee_currency': Decimal('8.000000000000'), 'net_publishing_revenue_payee_currency': None, 'gross_publishing_revenue_payee_currency': None, 'total_records': 2, }, ] (items, total_record) = RevenueByActivityMonth.get_revenue_by_activity_month_by_account_id( 24601, 50, 0, None, None, None, None, None, None, None, None, None, imprint_ids=[101], store_ids=[201], country_codes=['US'], transaction_type_ids=[301] ) assert [item._asdict() for item in items] == expected @using_mock_snowflake_table(RevenueByActivityMonth, _MOCK_DATA) def test_get_revenue_by_activity_month_by_subaccount(): """Test getting revenue by activity month with subaccount revenue.""" subaccount_id = 1 expected = [ { 'activity_period_id': Decimal('10'), 'activity_month_name': 'July 2024', 'account_payee_currency': 'USD', 'net_share_payee_currency': Decimal('12.000000000000'), 'gross_revenue_payee_currency': Decimal('9.000000000000'), 'net_publishing_revenue_payee_currency': None, 'gross_publishing_revenue_payee_currency': None, 'total_records': 2, 'subaccount_revenue': Decimal('10.800000000000'), }, { 'activity_period_id': Decimal('9'), 'activity_month_name': 'June 2024', 'account_payee_currency': 'USD', 'net_share_payee_currency': Decimal('10.000000000000'), 'gross_revenue_payee_currency': Decimal('8.000000000000'), 'net_publishing_revenue_payee_currency': None, 'gross_publishing_revenue_payee_currency': None, 'total_records': 2, 'subaccount_revenue': Decimal('9.000000000000'), }, ] subaccount_info = DimSubaccountFactory.build( subaccount_id=subaccount_id) (items, total_record) = RevenueByActivityMonth.get_revenue_by_activity_month_by_account_id( 24601, 50, 0, 1, 1, 1, 1234556, None, 10, 12, None, None, subaccount_info=subaccount_info) assert [item._asdict() for item in items] == expected @using_mock_snowflake_table(RevenueByActivityMonth, _MOCK_DATA) def test_get_revenue_by_activity_month_with_activity_period_filters(): """Test getting revenue by activity month with activity period filters.""" expected = [ { 'activity_period_id': Decimal('10'), 'activity_month_name': 'July 2024', 'account_payee_currency': 'USD', 'net_share_payee_currency': Decimal('12.000000000000'), 'gross_revenue_payee_currency': Decimal('9.000000000000'), 'net_publishing_revenue_payee_currency': Decimal('13.000000000000'), 'gross_publishing_revenue_payee_currency': Decimal('15.000000000000'), 'total_records': 2, }, { 'activity_period_id': Decimal('9'), 'activity_month_name': 'June 2024', 'account_payee_currency': 'USD', 'net_share_payee_currency': Decimal('20.000000000000'), 'gross_revenue_payee_currency': Decimal('16.000000000000'), 'net_publishing_revenue_payee_currency': None, 'gross_publishing_revenue_payee_currency': None, 'total_records': 2, }, ] (items, total_record) = RevenueByActivityMonth.get_revenue_by_activity_month_by_account_id( 24601, 50, 0, None, None, None, None, None, None, None, 9, 10) assert [item._asdict() for item in items] == expected @using_mock_snowflake_table(RevenueByActivityMonth, _MOCK_DATA) def test_get_revenue_by_activity_month_with_project_id_filter(): """Test filtering revenue by activity month by project ID.""" (items, total_record) = RevenueByActivityMonth.get_revenue_by_activity_month_by_account_id( 24601, 50, 0, None, None, None, None, None, None, None, None, None, project_id=2) assert total_record == 1 assert items[0].activity_month_name == 'June 2024'