"""Revenue By Subaccount model tests.""" from decimal import Decimal from moneyhub.constants.constants import ORDER_BY_SUBACCOUNT_ID from moneyhub.constants.constants import OrderDirection from moneyhub.models import RevenueBySubaccount from tests.unit.conftest import using_mock_snowflake_table _MOCK_DATA = { 'revenue_by_subaccount_dbt': [ { 'subaccount_id': 112233, 'subaccount_name': 'Subaccount one', 'account_id': 57608, 'contract_id': 10001, 'artist_id': 1, 'store_id': 100, 'activity_period_id': 10, 'imprint_id': 12345, 'transaction_type_id': 1, 'country_code': 'NO', 'statement_period_id': 10, 'account_payee_currency': 'JPY', 'mechanical_deduction_amount_payee_currency': Decimal('10.00'), 'publisher_admin_fee_payee_currency': Decimal('1.00'), 'net_revenue_payee_currency': Decimal('10.00'), 'gross_revenue_payee_currency': Decimal('8.00') }, { 'subaccount_id': 223311, 'subaccount_name': 'Subaccount two', 'account_id': 57608, 'contract_id': 10001, 'artist_id': 2, 'store_id': 100, 'activity_period_id': 10, 'imprint_id': 12346, 'transaction_type_id': 1, 'country_code': 'JP', 'statement_period_id': 10, 'account_payee_currency': 'JPY', 'mechanical_deduction_amount_payee_currency': Decimal('20.00'), 'publisher_admin_fee_payee_currency': Decimal('2.00'), 'net_revenue_payee_currency': Decimal('20.00'), 'gross_revenue_payee_currency': Decimal('18.00') }, { 'subaccount_id': 332211, 'subaccount_name': 'Subaccount three', 'statement_period_id': 10, 'artist_id': 3, 'store_id': 100, 'activity_period_id': 10, 'imprint_id': 12346, 'transaction_type_id': 1, 'country_code': 'JP', 'account_id': 57608, 'contract_id': 10002, 'account_payee_currency': 'JPY', 'mechanical_deduction_amount_payee_currency': Decimal('10.00'), 'publisher_admin_fee_payee_currency': Decimal('1.00'), 'net_revenue_payee_currency': Decimal('10.00'), 'gross_revenue_payee_currency': Decimal('8.00') }, { 'subaccount_id': 223311, 'subaccount_name': 'Subaccount four', 'statement_period_id': 11, 'artist_id': 4, 'store_id': 100, 'activity_period_id': 10, 'imprint_id': 12345, 'transaction_type_id': 1, 'country_code': 'US', 'account_id': 57608, 'contract_id': 10002, 'account_payee_currency': 'GBP', 'mechanical_deduction_amount_payee_currency': Decimal('11.00'), 'publisher_admin_fee_payee_currency': Decimal('1.00'), 'net_revenue_payee_currency': Decimal('11.00'), 'gross_revenue_payee_currency': Decimal('9.00') }, ], } @using_mock_snowflake_table(RevenueBySubaccount, _MOCK_DATA) def test_get_by_account_id(): """Test getting revenue by account.""" account_id = 57608 limit = 50 offset = 0 (items, total_record) = RevenueBySubaccount.get_by_account_id( account_id, limit, offset, None, None, None, None, None, None, None, None, None, None, ORDER_BY_SUBACCOUNT_ID, OrderDirection.ASC, None) actual = items[0]._asdict() assert actual == { 'subaccount_id': Decimal('112233'), 'subaccount_name': 'Subaccount one', 'account_id': Decimal('57608'), 'account_payee_currency': 'JPY', 'mechanical_deduction_amount_payee_currency': Decimal('10.000000000000'), 'publisher_admin_fee_payee_currency': Decimal('1.000000000000'), 'net_revenue_payee_currency': Decimal('10.000000000000'), 'gross_revenue_payee_currency': Decimal('8.000000000000'), 'total_records': 4, } @using_mock_snowflake_table(RevenueBySubaccount, _MOCK_DATA) def test_get_by_account_id_with_filters(): """Test getting by account with filters.""" account_id = 57608 contract_id = 10001 artist_id = 2 limit = 50 offset = 0 search_query = 'Two' statement_period_start = 10 statement_period_end = 11 activity_period_start = 10 activity_period_end = 10 store_ids = [100] imprint_ids = [12346] transaction_type_ids = [1] country_codes = ['US', 'JP', 'NO'] order_by = 'subaccount_id' order_dir = OrderDirection.ASC (items, total_record) = RevenueBySubaccount.get_by_account_id( account_id, limit, offset, artist_id, contract_id, statement_period_start, statement_period_end, activity_period_start, activity_period_end, store_ids, imprint_ids, transaction_type_ids, country_codes, order_by, order_dir, search_query) assert [item._asdict() for item in items] == [ { 'subaccount_id': Decimal('223311'), 'subaccount_name': 'Subaccount two', 'account_id': Decimal('57608'), 'account_payee_currency': 'JPY', 'mechanical_deduction_amount_payee_currency': Decimal('20.000000000000'), 'publisher_admin_fee_payee_currency': Decimal('2.000000000000'), 'net_revenue_payee_currency': Decimal('20.000000000000'), 'gross_revenue_payee_currency': Decimal('18.000000000000'), 'total_records': 1, 'contract_id': Decimal('10001'), }, ]