"""Tests for revenue_analysis handlers.""" from unittest.mock import patch from moneyhub.constants.constants import ORDER_BY_ARTIST_NAME from moneyhub.constants.constants import ORDER_BY_IMPRINT from moneyhub.constants.constants import ORDER_BY_NET_REVENUE_PAYEE_CURRENCY from moneyhub.constants.constants import ORDER_BY_PRODUCT_ID from moneyhub.constants.constants import ORDER_BY_RECORDING_ID from moneyhub.constants.constants import ORDER_BY_SUBACCOUNT_ID from moneyhub.constants.constants import ORDER_BY_TRACK_UNIQUE_ID from moneyhub.constants.constants import OrderBy from moneyhub.constants.constants import OrderDirection from moneyhub.constants.constants import StatementPeriodStatus from moneyhub.schemas import PaginatedRevenueByRecordingSchema from moneyhub.schemas import PaginationSchema from moneyhub.schemas.revenue_analysis import AccountRevenueSchema from moneyhub.schemas.revenue_analysis import AccountStatementPeriodRevenueSchema from moneyhub.schemas.revenue_analysis import PaginatedRevenueByActivityMonthSchema from moneyhub.schemas.revenue_analysis import PaginatedRevenueByArtistSchema from moneyhub.schemas.revenue_analysis import PaginatedRevenueByImprintSchema from moneyhub.schemas.revenue_analysis import PaginatedRevenueByProjectSchema from moneyhub.schemas.revenue_analysis import PaginatedRevenueByStoreSchema from moneyhub.schemas.revenue_analysis import PaginatedRevenueBySubaccountSchema from moneyhub.schemas.revenue_analysis import PaginatedRevenueByTrackSchema from moneyhub.schemas.revenue_analysis import ResponseRevenueByTransactionTypeSchema from moneyhub.schemas.revenue_analysis import RevenueByStatementPeriodSchema from moneyhub.schemas.revenue_analysis import RevenueByTransactionTypeSchema from moneyhub.schemas.revenue_analysis import RevenuePayeeCurrencyTotalsSchema from tests.utils.factories import RevenueByActivityMonthFactory from tests.utils.factories import RevenueByArtistFactory from tests.utils.factories import RevenueByCountryFactory from tests.utils.factories import RevenueByImprintFactory from tests.utils.factories import RevenueByProductDistroFactory from tests.utils.factories import RevenueByProjectFactory from tests.utils.factories import RevenueByRecordingDistroFactory from tests.utils.factories import RevenueByRecordingNrFactory from tests.utils.factories import RevenueByStoreFactory from tests.utils.factories import RevenueBySubaccountFactory from tests.utils.factories import RevenueByTrackFactory @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_product') def test_get_revenue_analysis_by_product(mock_logic, fixture_client): """Test getting revenue analysis by product.""" account_id = 57608 mock_logic.return_value = { 'items': [RevenueByProductDistroFactory.build(account_id=account_id)], 'pagination': { 'pagination_type': 'standard', 'total_records': 554, } } actual = fixture_client.get(f'/revenue-analysis/account/{account_id}/product') assert actual.status_code == 200 assert actual.json() == { 'items': [{ 'product_id': 1234, 'account_payee_currency': 'JPY', 'project_name': 'Project Alpha', 'mechanical_deduction_amount_payee_currency': 80.0, 'publisher_admin_fee_payee_currency': 8.0, 'net_share_payee_currency': 80.0, 'gross_revenue_payee_currency': 100.0, 'subaccount_revenue': None }], 'pagination': { 'pagination_type': 'standard', 'total_records': 554, } } mock_logic.assert_called_with( account_id, 50, 0, None, None, None, None, None, None, None, ORDER_BY_PRODUCT_ID, OrderDirection.ASC, None, None, None, None, None, False, None) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_product') def test_get_revenue_analysis_by_product_with_subaccount(mock_logic, fixture_client): """Test getting revenue analysis by product.""" account_id = 57608 subaccount_id = 57609 item = RevenueByProductDistroFactory.build(account_id=account_id).to_dict() item['subaccount_revenue'] = 100 mock_logic.return_value = { 'items': [item], 'pagination': { 'pagination_type': 'standard', 'total_records': 554, } } actual = fixture_client.get(f'/revenue-analysis/account/{account_id}/product?subaccount_id={subaccount_id}&is_subaccount=True') # noqa: E501 assert actual.status_code == 200 assert actual.json() == { 'items': [{ 'product_id': 1234, 'account_payee_currency': 'JPY', 'project_name': 'Project Alpha', 'mechanical_deduction_amount_payee_currency': 160.0, 'publisher_admin_fee_payee_currency': 16.0, 'net_share_payee_currency': 160.0, 'gross_revenue_payee_currency': 200.0, 'subaccount_revenue': 100.0 }], 'pagination': { 'pagination_type': 'standard', 'total_records': 554, } } mock_logic.assert_called_with( account_id, 50, 0, None, None, None, None, None, None, subaccount_id, ORDER_BY_PRODUCT_ID, OrderDirection.ASC, None, None, None, None, None, True, None) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_product') def test_get_revenue_analysis_by_product_with_list_filters(mock_logic, fixture_client): """Test getting revenue analysis by product with list filters.""" account_id = 57608 store_ids = [101, 102] country_codes = ['US', 'GB'] imprint_ids = [201] transaction_type_ids = [301] project_id = 1 mock_logic.return_value = { 'items': [RevenueByProductDistroFactory.build(account_id=account_id).to_dict()], 'pagination': { 'pagination_type': 'standard', 'total_records': 1, } } actual = fixture_client.get( f'/revenue-analysis/account/{account_id}/product' f'?store_ids={store_ids[0]}&store_ids={store_ids[1]}' f'&country_codes={country_codes[0]}&country_codes={country_codes[1]}' f'&imprint_ids={imprint_ids[0]}&transaction_type_ids={transaction_type_ids[0]}' f'&project_id={project_id}') assert actual.status_code == 200 mock_logic.assert_called_with( account_id, 50, 0, None, None, None, None, None, None, None, ORDER_BY_PRODUCT_ID, OrderDirection.ASC, None, store_ids, country_codes, transaction_type_ids, imprint_ids, False, project_id) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_statement_period') def test_get_revenue_analysis_by_statement_period(mock_logic, fixture_client): """Test getting revenue analysis by statement period.""" account_id = 24601 statement_period_id_start = 123 statement_period_id_end = 124 mock_logic.return_value = [ RevenueByStatementPeriodSchema( statement_period_id=123, account_payee_currency='USD', net_revenue_payee_currency=80.0, gross_revenue_payee_currency=100.0, net_publishing_revenue_payee_currency=50.0, gross_publishing_revenue_payee_currency=60.0, ), RevenueByStatementPeriodSchema( statement_period_id=124, account_payee_currency='USD', net_revenue_payee_currency=160.0, gross_revenue_payee_currency=200.0, net_publishing_revenue_payee_currency=100.0, gross_publishing_revenue_payee_currency=120.0, ), ] params = { 'store_ids': 123, 'country_codes': 'US', 'imprint_ids': 1, 'transaction_type_ids': 2, 'statement_period_id_start': statement_period_id_start, 'statement_period_id_end': statement_period_id_end } result = fixture_client.get( f'/revenue-analysis/account/{account_id}/statement-period', params=params) assert result.status_code == 200 assert result.json() == [ { 'statement_period_id': 123, 'account_payee_currency': 'USD', 'net_revenue_payee_currency': 80.0, 'gross_revenue_payee_currency': 100.0, 'net_publishing_revenue_payee_currency': 50.0, 'gross_publishing_revenue_payee_currency': 60.0, 'subaccount_revenue': None }, { 'statement_period_id': 124, 'account_payee_currency': 'USD', 'net_revenue_payee_currency': 160.0, 'gross_revenue_payee_currency': 200.0, 'net_publishing_revenue_payee_currency': 100.0, 'gross_publishing_revenue_payee_currency': 120.0, 'subaccount_revenue': None } ] mock_logic.assert_called_with( account_id, None, None, None, None, None, statement_period_id_start, statement_period_id_end, False, None, None, [123], ['US'], [1], [2], project_id=None ) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_recording') def test_get_revenue_analysis_by_recording_nr(mock_logic, fixture_client): """Test getting revenue analysis by recording.""" account_id = 57608 payload = PaginatedRevenueByRecordingSchema( items=[RevenueByRecordingNrFactory.build(account_id=account_id)], pagination=PaginationSchema( pagination_type='standard', total_records=554, ) ) mock_logic.return_value = payload actual = fixture_client.get(f'/revenue-analysis/account/{account_id}/recording') assert actual.status_code == 200 assert actual.json() == { 'items': [ { 'recording_id': '1234', 'recording_title': 'Title', 'artist': 'Artist', 'version': 'Acoustic', 'isrc': 'JPYE70900611', 'account_id': account_id, 'contract_id': None, 'account_payee_currency': 'JPY', 'net_share_payee_currency': 100.0, 'gross_revenue_payee_currency': 100.00 } ], 'pagination': { 'pagination_type': 'standard', 'total_records': 554, } } mock_logic.assert_called_with( account_id, 50, 0, None, None, None, None, ORDER_BY_RECORDING_ID, OrderDirection.ASC, None, None, None, None, None, None) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_recording') def test_get_revenue_analysis_by_recording_distro(mock_logic, fixture_client): """Test getting revenue analysis by recording.""" account_id = 68410 payload = PaginatedRevenueByRecordingSchema( items=[RevenueByRecordingDistroFactory.build(account_id=account_id)], pagination=PaginationSchema( pagination_type='standard', total_records=554, ) ) mock_logic.return_value = payload actual = fixture_client.get(f'/revenue-analysis/account/{account_id}/recording') assert actual.status_code == 200 assert actual.json() == { 'items': [ { 'recording_id': '1234', 'recording_title': 'Title', 'artist': 'Artist', 'version': 'Acoustic', 'isrc': 'JPYE70900611', 'account_id': account_id, 'contract_id': None, 'account_payee_currency': 'JPY', 'net_share_payee_currency': 100.0, 'gross_revenue_payee_currency': 100.00 } ], 'pagination': { 'pagination_type': 'standard', 'total_records': 554, } } mock_logic.assert_called_with( account_id, 50, 0, None, None, None, None, ORDER_BY_RECORDING_ID, OrderDirection.ASC, None, None, None, None, None, None) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_recording') def test_get_revenue_analysis_by_recording_with_list_filters(mock_logic, fixture_client): """Test getting revenue analysis by recording with list filters.""" account_id = 68410 payload = PaginatedRevenueByRecordingSchema( items=[RevenueByRecordingDistroFactory.build(account_id=account_id)], pagination=PaginationSchema( pagination_type='standard', total_records=554, ) ) mock_logic.return_value = payload actual = fixture_client.get( f'/revenue-analysis/account/{account_id}/recording' f'?store_ids=101&store_ids=102&country_codes=US&country_codes=GB' f'&imprint_ids=201&transaction_type_ids=301') assert actual.status_code == 200 assert actual.json() == payload.model_dump() mock_logic.assert_called_once_with( account_id, 50, 0, None, None, None, None, ORDER_BY_RECORDING_ID, OrderDirection.ASC, None, None, [101, 102], ['US', 'GB'], [201], [301] ) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_store') def test_get_revenue_analysis_by_store(mock_logic, fixture_client): """Test getting revenue analysis by recording.""" account_id = 57608 artist_id = 2 subaccount_id = 1111 payload = PaginatedRevenueByStoreSchema( items=[ RevenueByStoreFactory.build(store_id=123), RevenueByStoreFactory.build(store_id=0, store_name='Others') ], totals=RevenuePayeeCurrencyTotalsSchema( net_revenue_payee_currency=22093.701372643944, gross_revenue_payee_currency=29988.667602314563 ), pagination=PaginationSchema( pagination_type='standard', total_records=554, ) ) activity_period_id_start = 1 activity_period_id_end = 1 country_codes = ['US'] imprint_ids = [1] transaction_type_ids = [2] store_ids = [1, 2, 3] mock_logic.return_value = payload params = { 'artist_id': artist_id, 'limit': 1, 'subaccount_id': subaccount_id, 'activity_period_id_start': activity_period_id_start, 'activity_period_id_end': activity_period_id_end, 'country_codes': country_codes, 'imprint_ids': imprint_ids, 'transaction_type_ids': transaction_type_ids, 'store_ids': store_ids } actual = fixture_client.get( f'/revenue-analysis/account/{account_id}/store', params=params ) assert actual.status_code == 200 assert actual.json() == { 'items': [ { 'store_id': 123, 'store_name': 'Spotify', 'account_payee_currency': 'USD', 'net_revenue_payee_currency': 80.0, 'gross_revenue_payee_currency': 100.00, 'subaccount_revenue': None }, { 'store_id': 0, 'store_name': 'Others', 'account_payee_currency': 'USD', 'net_revenue_payee_currency': 160.0, 'gross_revenue_payee_currency': 200.00, 'subaccount_revenue': None }, ], 'totals': { 'net_revenue_payee_currency': 22093.701372643944, 'gross_revenue_payee_currency': 29988.667602314563, 'subaccount_revenue': None }, 'pagination': { 'pagination_type': 'standard', 'total_records': 554, } } mock_logic.assert_called_with( account_id, artist_id, subaccount_id, 1, 0, None, None, None, None, None, OrderBy.NET_REVENUE_PAYEE_CURRENCY, OrderDirection.DESC, None, False, activity_period_id_start, activity_period_id_end, country_codes, imprint_ids, transaction_type_ids, store_ids, project_id=None, ) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_store') def test_get_revenue_analysis_by_store_with_zero_revenue(mock_logic, fixture_client): """Test getting revenue analysis by recording.""" account_id = 57608 payload = PaginatedRevenueByStoreSchema( items=[], totals=RevenuePayeeCurrencyTotalsSchema( net_revenue_payee_currency=None, gross_revenue_payee_currency=None ), pagination=PaginationSchema( pagination_type='standard', total_records=0, ) ) mock_logic.return_value = payload actual = fixture_client.get(f'/revenue-analysis/account/{account_id}/store?limit=1') assert actual.status_code == 200 assert actual.json() == payload.model_dump() mock_logic.assert_called_with( account_id, None, None, 1, 0, None, None, None, None, None, OrderBy.NET_REVENUE_PAYEE_CURRENCY, OrderDirection.DESC, None, False, None, None, None, None, None, None, project_id=None, ) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_project') def test_get_revenue_analysis_by_project(mock_logic, fixture_client): """Test getting revenue analysis by project.""" account_id = 57608 subaccount_id = 1111 payload = PaginatedRevenueByProjectSchema( items=[ RevenueByProjectFactory.build( project_id=123, project_name='Project Nimbus', project_code='PN-001', project_artist='Nimbus Artist', product_count=2, ) ], pagination=PaginationSchema( pagination_type='standard', total_records=554, ) ) mock_logic.return_value = payload actual = fixture_client.post( f'/revenue-analysis/account/{account_id}/project', json={ 'limit': 1, 'offset': 0, 'contract_id': 10001, 'subaccount_id': subaccount_id, 'statement_period_id_start': 10, 'statement_period_id_end': 20, 'is_subaccount': True, 'order_by': 'project_name', 'order_dir': 'asc', 'search_term': 'Nimbus', 'activity_period_id_start': 1, 'activity_period_id_end': 1, 'store_ids': [1, 2], 'country_codes': ['US'], 'imprint_ids': [10], 'transaction_type_ids': [20], } ) assert actual.status_code == 200 assert actual.json() == { 'items': [ { 'project_id': 123, 'project_name': 'Project Nimbus', 'project_code': 'PN-001', 'project_artist': 'Nimbus Artist', 'product_count': 2, 'account_payee_currency': 'USD', 'net_share_payee_currency': 80.0, 'gross_revenue_payee_currency': 100.0, 'subaccount_revenue': None, } ], 'pagination': { 'pagination_type': 'standard', 'total_records': 554, } } mock_logic.assert_called_once_with( account_id, 1, 0, 10001, subaccount_id, 10, 20, 'project_name', OrderDirection.ASC, 'Nimbus', True, 1, 1, [1, 2], ['US'], [10], [20], ) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_country') def test_get_revenue_analysis_by_country(mock_logic, fixture_client): """Test getting revenue analysis by country.""" account_id = 57608 mock_logic.return_value = [RevenueByCountryFactory.build()] actual = fixture_client.get(f'/revenue-analysis/account/{account_id}/country') assert actual.status_code == 200 assert actual.json() == [{ 'account_id': 24601, 'account_payee_currency': 'GBP', 'country_code': 'GB', 'net_revenue_payee_currency': 80.0, 'gross_revenue_payee_currency': 100.0, 'subaccount_revenue': None }] mock_logic.assert_called_once_with( account_id, None, None, None, None, None, None, None, None, None, None, None, None, None, False, project_id=None) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_country') def test_get_revenue_analysis_by_country_subaccount(mock_logic, fixture_client): """Test getting revenue analysis by country by subaccount.""" mock_revenue = RevenueByCountryFactory.build().to_dict() mock_revenue['subaccount_revenue'] = 60 mock_logic.return_value = [mock_revenue] actual = fixture_client.get( '/revenue-analysis/account/24601/country?is_subaccount=1&subaccount_id=10001') assert actual.status_code == 200 assert actual.json() == [{ 'account_id': 24601, 'account_payee_currency': 'GBP', 'country_code': 'GB', 'net_revenue_payee_currency': 160.0, 'gross_revenue_payee_currency': 200.0, 'subaccount_revenue': 60.0 }] mock_logic.assert_called_once_with( 24601, None, 10001, None, None, None, None, None, None, None, None, None, None, None, True, project_id=None) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_country') def test_get_revenue_analysis_by_country_with_list_filters(mock_logic, fixture_client): """Test getting revenue analysis by country with list filters.""" account_id = 57608 mock_logic.return_value = [RevenueByCountryFactory.build()] actual = fixture_client.get( f'/revenue-analysis/account/{account_id}/country', params={ 'store_ids': [101, 102], 'country_codes': ['GB'], 'imprint_ids': [201], 'transaction_type_ids': [301], } ) assert actual.status_code == 200 assert actual.json() == [{ 'account_id': 24601, 'account_payee_currency': 'GBP', 'country_code': 'GB', 'net_revenue_payee_currency': 240.0, 'gross_revenue_payee_currency': 300.0, 'subaccount_revenue': None }] mock_logic.assert_called_once_with( account_id, None, None, None, None, None, None, None, None, None, [101, 102], ['GB'], [201], [301], False, project_id=None) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_transaction_type') def test_get_revenue_analysis_by_transaction_type(mock_logic, fixture_client): """Test getting revenue analysis by transaction type.""" account_id = 24601 payload = ResponseRevenueByTransactionTypeSchema( items=[ RevenueByTransactionTypeSchema( transaction_type_id=1, transaction_type_desc='Downloaded Ringtones', transaction_type_group_name='Ringtone Group', account_payee_currency='USD', quantity=10, net_revenue_payee_currency=80.0, gross_revenue_payee_currency=100.00 )], totals=RevenuePayeeCurrencyTotalsSchema( net_revenue_payee_currency=22093.701372643944, gross_revenue_payee_currency=29988.667602314563 ), ) mock_logic.return_value = payload result = fixture_client.get(f'/revenue-analysis/account/{account_id}/transaction-type') assert result.status_code == 200 assert result.json() == payload.model_dump() @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_transaction_type') def test_get_revenue_analysis_by_transaction_type_with_filters(mock_logic, fixture_client): """Test getting revenue analysis by transaction type.""" account_id = 24601 subaccount_id = 24604 artist_id = 2 payload = ResponseRevenueByTransactionTypeSchema( items=[ RevenueByTransactionTypeSchema( transaction_type_id=1, transaction_type_desc='Downloaded Ringtones', transaction_type_group_name='Ringtone Group', account_payee_currency='USD', quantity=10, net_revenue_payee_currency=80.0, gross_revenue_payee_currency=100.00 )], totals=RevenuePayeeCurrencyTotalsSchema( net_revenue_payee_currency=22093.701372643944, gross_revenue_payee_currency=29988.667602314563 ), ) mock_logic.return_value = payload result = fixture_client.get( f'/revenue-analysis/account/{account_id}/transaction-type?artist_id=' f'{artist_id}&subaccount_id={subaccount_id}&product_id=1&track_unique_id=1') # noqa: E501 assert result.status_code == 200 assert result.json() == payload.model_dump() mock_logic.assert_called_once_with( account_id, artist_id, None, None, None, None, None, subaccount_id, ORDER_BY_NET_REVENUE_PAYEE_CURRENCY, OrderDirection.DESC, None, False, 1, 1, None, None, None, None, project_id=None, ) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_transaction_type') def test_get_revenue_analysis_by_transaction_type_with_list_filters(mock_logic, fixture_client): """Test getting revenue analysis by transaction type with list filters.""" account_id = 24601 payload = ResponseRevenueByTransactionTypeSchema( items=[ RevenueByTransactionTypeSchema( transaction_type_id=1, transaction_type_desc='Downloaded Ringtones', transaction_type_group_name='Ringtone Group', account_payee_currency='USD', quantity=10, net_revenue_payee_currency=80.0, gross_revenue_payee_currency=100.00 )], totals=RevenuePayeeCurrencyTotalsSchema( net_revenue_payee_currency=22093.701372643944, gross_revenue_payee_currency=29988.667602314563 ), ) mock_logic.return_value = payload result = fixture_client.get( f'/revenue-analysis/account/{account_id}/transaction-type?store_ids=1&store_ids=2' f'&country_codes=US&country_codes=GB&imprint_ids=10&imprint_ids=20&transaction_type_ids=9') assert result.status_code == 200 assert result.json() == payload.model_dump() mock_logic.assert_called_once_with( account_id, None, None, None, None, None, None, None, ORDER_BY_NET_REVENUE_PAYEE_CURRENCY, OrderDirection.DESC, None, False, None, None, [1, 2], ['US', 'GB'], [10, 20], [9], project_id=None, ) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_by_account') def test_get_revenue_account_id(mock_logic, fixture_client): """Test to get revenue for an account.""" account_id = 24601 endpoint = '/revenue-analysis/account/{account_id}/statement_period/{statement_period}/all-time-revenue' # noqa: E501 expected_result = AccountRevenueSchema( since_statement_period_id=285, currency_code='NOK', gross_revenue_payee_currency=523.00, net_revenue_payee_currency=423.00 ) mock_logic.return_value = expected_result res = fixture_client.get(endpoint.format(account_id=account_id, statement_period=285)) assert res.status_code == 200 assert res.json() == expected_result.model_dump() @patch('moneyhub.handlers.revenue_analysis.logic.get_latest_revenue_by_account_id') def test_get_latest_revenue_account_id(mock_logic, fixture_client): """Test to get latest revenue for an account.""" account_id = 24601 endpoint = '/revenue-analysis/account/{account_id}/statement_period/{statement_period}' expected_result = AccountStatementPeriodRevenueSchema( currency_code='NOK', gross_revenue_payee_currency=523.00, net_revenue_payee_currency=423.00, statement_period_id=296, statement_period_status=StatementPeriodStatus.CLOSED, statement_period_name='August 2023' ) mock_logic.return_value = expected_result res = fixture_client.get(endpoint.format(account_id=account_id, statement_period=285)) assert res.status_code == 200 assert res.json() == expected_result.model_dump() @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_track') def test_get_revenue_analysis_by_track(mock_logic, fixture_client): """Test getting revenue analysis by track.""" account_id = 57608 project_id = 2 mock_logic.return_value = { 'items': [RevenueByTrackFactory.build(account_id=account_id)], 'pagination': { 'pagination_type': 'standard', 'total_records': 554, } } actual = fixture_client.get( f'/revenue-analysis/account/{account_id}/track?project_id={project_id}') assert actual.status_code == 200 assert actual.json() == { 'items': [{ 'account_id': 57608, 'contract_id': None, 'subaccount_id': None, 'track_unique_id': 12341234, 'track_name': 'Best Name', 'isrc': 'IIIII1234187', 'account_payee_currency': 'JPY', 'project_name': 'Project Alpha', 'mechanical_deduction_amount_payee_currency': 80.0, 'publisher_admin_fee_payee_currency': 8.0, 'net_revenue_payee_currency': 80.0, 'gross_revenue_payee_currency': 100.0, 'subaccount_revenue': None }], 'pagination': { 'pagination_type': 'standard', 'total_records': 554 } } mock_logic.assert_called_with( account_id, 50, 0, None, None, None, None, None, None, None, None, ORDER_BY_TRACK_UNIQUE_ID, OrderDirection.ASC, None, None, None, None, None, False, project_id) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_track') def test_get_revenue_analysis_by_track_with_subaccount(mock_logic, fixture_client): """Test getting revenue analysis by product.""" account_id = 57608 subaccount_id = 57609 item = RevenueByTrackFactory.build(account_id=account_id).to_dict() item['subaccount_revenue'] = 100 mock_logic.return_value = { 'items': [item], 'pagination': { 'pagination_type': 'standard', 'total_records': 554, } } actual = fixture_client.get(f'/revenue-analysis/account/{account_id}/track?subaccount_id={subaccount_id}&is_subaccount=True') # noqa: E501 assert actual.status_code == 200 assert actual.json() == { 'items': [{ 'track_unique_id': 12341234, 'account_id': 57608, 'contract_id': None, 'subaccount_id': None, 'track_name': 'Best Name', 'isrc': 'IIIII1234187', 'account_payee_currency': 'JPY', 'project_name': 'Project Alpha', 'mechanical_deduction_amount_payee_currency': 160.0, 'publisher_admin_fee_payee_currency': 16.0, 'net_revenue_payee_currency': 160.0, 'gross_revenue_payee_currency': 200.0, 'subaccount_revenue': 100.0 }], 'pagination': { 'pagination_type': 'standard', 'total_records': 554, } } mock_logic.assert_called_with( account_id, 50, 0, None, None, None, None, None, None, subaccount_id, None, ORDER_BY_TRACK_UNIQUE_ID, OrderDirection.ASC, None, None, None, None, None, True, None) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_track') def test_get_revenue_analysis_by_track_with_list_filters(mock_logic, fixture_client): """Test getting revenue analysis by track with list filters.""" account_id = 57608 store_ids = [101, 102] country_codes = ['US', 'GB'] imprint_ids = [201] transaction_type_ids = [301] payload = PaginatedRevenueByTrackSchema( items=[RevenueByTrackFactory.build(account_id=account_id)], pagination=PaginationSchema( pagination_type='standard', total_records=1, ) ) mock_logic.return_value = payload actual = fixture_client.get( f'/revenue-analysis/account/{account_id}/track' f'?store_ids={store_ids[0]}&store_ids={store_ids[1]}' f'&country_codes={country_codes[0]}&country_codes={country_codes[1]}' f'&imprint_ids={imprint_ids[0]}&transaction_type_ids={transaction_type_ids[0]}') assert actual.status_code == 200 assert actual.json() == payload.model_dump() mock_logic.assert_called_once_with( account_id, 50, 0, None, None, None, None, None, None, None, None, ORDER_BY_TRACK_UNIQUE_ID, OrderDirection.ASC, None, store_ids, country_codes, transaction_type_ids, imprint_ids, False, None ) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_imprint') def test_get_revenue_analysis_by_imprint(mock_logic, fixture_client): """Test getting revenue analysis by imprint.""" account_id = 57608 payload = PaginatedRevenueByImprintSchema( items=[ RevenueByImprintFactory.build(imprintid=123456), RevenueByImprintFactory.build(imprintid=654321, imprint='SECOND TEST') ], pagination=PaginationSchema( pagination_type='standard', total_records=554, ) ) mock_logic.return_value = payload actual = fixture_client.get(f'/revenue-analysis/account/{account_id}/imprint') assert actual.status_code == 200 assert actual.json() == { 'items': [ { 'imprintid': 123456, 'imprint': 'TEST', 'account_id': 123, 'contract_id': None, 'account_payee_currency': 'USD', 'mechanical_deduction_amount_payee_currency': 80.0, 'publisher_admin_fee_payee_currency': 8.0, 'net_share_payee_currency': 80.0, 'gross_revenue_payee_currency': 100.00, 'subaccount_id': 1234, 'subaccount_revenue': None }, { 'imprintid': 654321, 'imprint': 'SECOND TEST', 'account_id': 123, 'contract_id': None, 'account_payee_currency': 'USD', 'mechanical_deduction_amount_payee_currency': 160.0, 'publisher_admin_fee_payee_currency': 16.0, 'net_share_payee_currency': 160.0, 'gross_revenue_payee_currency': 200.00, 'subaccount_id': 1234, 'subaccount_revenue': None }, ], 'pagination': { 'pagination_type': 'standard', 'total_records': 554, } } mock_logic.assert_called_with( account_id, None, 50, 0, None, None, None, None, None, None, ORDER_BY_IMPRINT, OrderDirection.ASC, None, None, None, None, None, False) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_imprint') def test_get_revenue_analysis_by_imprint_with_filters(mock_logic, fixture_client): """Test getting revenue analysis by imprint.""" account_id = 57608 subaccount_id = 57609 artist_id = 2 payload = PaginatedRevenueByImprintSchema( items=[ RevenueByImprintFactory.build(imprintid=123456, artist_id=artist_id), RevenueByImprintFactory.build( imprintid=654321, artist_id=artist_id, imprint='SECOND TEST') ], pagination=PaginationSchema( pagination_type='standard', total_records=554, ) ) mock_logic.return_value = payload actual = fixture_client.get( f'/revenue-analysis/account/{account_id}/imprint?artist_id={artist_id}&subaccount_id={subaccount_id}') # noqa: E501 assert actual.status_code == 200 assert actual.json() == { 'items': [ { 'imprintid': 123456, 'imprint': 'TEST', 'account_id': 123, 'contract_id': None, 'account_payee_currency': 'USD', 'mechanical_deduction_amount_payee_currency': 240.0, 'publisher_admin_fee_payee_currency': 24.0, 'net_share_payee_currency': 240.0, 'gross_revenue_payee_currency': 300.00, 'subaccount_id': 1234, 'subaccount_revenue': None }, { 'imprintid': 654321, 'imprint': 'SECOND TEST', 'account_id': 123, 'contract_id': None, 'account_payee_currency': 'USD', 'mechanical_deduction_amount_payee_currency': 320.0, 'publisher_admin_fee_payee_currency': 32.0, 'net_share_payee_currency': 320.0, 'gross_revenue_payee_currency': 400.00, 'subaccount_id': 1234, 'subaccount_revenue': None }, ], 'pagination': { 'pagination_type': 'standard', 'total_records': 554, } } mock_logic.assert_called_with( account_id, artist_id, 50, 0, None, None, None, None, None, subaccount_id, ORDER_BY_IMPRINT, OrderDirection.ASC, None, None, None, None, None, False) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_imprint') def test_get_revenue_analysis_by_imprint_with_subaccount(mock_logic, fixture_client): """Test getting revenue analysis by imprint.""" account_id = 57608 subaccount_id = 57609 artist_id = 2 item_1 = RevenueByImprintFactory.build(imprintid=123456, artist_id=artist_id).to_dict() item_1['subaccount_revenue'] = 220 item_2 = RevenueByImprintFactory.build( imprintid=654321, artist_id=artist_id, imprint='SECOND TEST').to_dict() item_2['subaccount_revenue'] = 240 payload = PaginatedRevenueByImprintSchema( items=[item_1, item_2], pagination=PaginationSchema( pagination_type='standard', total_records=554, ) ) mock_logic.return_value = payload actual = fixture_client.get( f'/revenue-analysis/account/{account_id}/imprint?subaccount_id={subaccount_id}&is_subaccount=True') # noqa: E501 assert actual.status_code == 200 assert actual.json() == { 'items': [ { 'imprintid': 123456, 'imprint': 'TEST', 'account_id': 123, 'contract_id': None, 'account_payee_currency': 'USD', 'mechanical_deduction_amount_payee_currency': 400.0, 'publisher_admin_fee_payee_currency': 40.0, 'net_share_payee_currency': 400.0, 'gross_revenue_payee_currency': 500.00, 'subaccount_id': 1234, 'subaccount_revenue': 220.0 }, { 'imprintid': 654321, 'imprint': 'SECOND TEST', 'account_id': 123, 'contract_id': None, 'account_payee_currency': 'USD', 'mechanical_deduction_amount_payee_currency': 480.0, 'publisher_admin_fee_payee_currency': 48.0, 'net_share_payee_currency': 480.0, 'gross_revenue_payee_currency': 600.00, 'subaccount_id': 1234, 'subaccount_revenue': 240.0 }, ], 'pagination': { 'pagination_type': 'standard', 'total_records': 554, } } mock_logic.assert_called_with( account_id, None, 50, 0, None, None, None, None, None, subaccount_id, ORDER_BY_IMPRINT, OrderDirection.ASC, None, None, None, None, None, True) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_imprint') def test_get_revenue_analysis_by_imprint_with_list_filters(mock_logic, fixture_client): """Test getting revenue analysis by imprint with list filters.""" account_id = 57608 payload = PaginatedRevenueByImprintSchema( items=[ RevenueByImprintFactory.build(imprintid=123456), ], pagination=PaginationSchema( pagination_type='standard', total_records=1, ) ) mock_logic.return_value = payload actual = fixture_client.get( f'/revenue-analysis/account/{account_id}/imprint', params={ 'store_ids': [1, 2], 'country_codes': ['US', 'GB'], 'imprint_ids': [1234], 'transaction_type_ids': [201, 202], } ) assert actual.status_code == 200 mock_logic.assert_called_with( account_id, None, 50, 0, None, None, None, None, None, None, ORDER_BY_IMPRINT, OrderDirection.ASC, None, [1, 2], ['US', 'GB'], [1234], [201, 202], False) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_subaccount') def test_get_revenue_analysis_by_subaccount(mock_logic, fixture_client): """Test getting revenue analysis by subaccount.""" account_id = 57608 payload = PaginatedRevenueBySubaccountSchema( items=[ RevenueBySubaccountFactory.build(), RevenueBySubaccountFactory.build( subaccount_id=333222, subaccount_name='Second subaccount') ], pagination=PaginationSchema( pagination_type='standard', total_records=554, ) ) mock_logic.return_value = payload actual = fixture_client.get(f'/revenue-analysis/account/{account_id}/subaccount') assert actual.status_code == 200 assert actual.json() == { 'items': [ { 'subaccount_id': 111222, 'subaccount_name': 'Test Subaccount', 'account_id': 123, 'contract_id': None, 'account_payee_currency': 'USD', 'mechanical_deduction_amount_payee_currency': 80.0, 'publisher_admin_fee_payee_currency': 8.0, 'net_revenue_payee_currency': 80.0, 'gross_revenue_payee_currency': 100.00 }, { 'subaccount_id': 333222, 'subaccount_name': 'Second subaccount', 'account_id': 123, 'contract_id': None, 'account_payee_currency': 'USD', 'mechanical_deduction_amount_payee_currency': 160.0, 'publisher_admin_fee_payee_currency': 16.0, 'net_revenue_payee_currency': 160.0, 'gross_revenue_payee_currency': 200.00 }, ], 'pagination': { 'pagination_type': 'standard', 'total_records': 554, } } mock_logic.assert_called_with( account_id, 50, 0, None, None, None, None, None, None, None, None, None, None, ORDER_BY_SUBACCOUNT_ID, OrderDirection.ASC, None) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_subaccount') def test_get_revenue_analysis_by_subaccount_filters(mock_logic, fixture_client): """Test getting revenue analysis by subaccount with filters.""" account_id = 57608 limit = 50 offset = 10 artist_id = 1122 contract_id = 10001 store_ids = [1, 2, 3] activity_period_id_start = 10 activity_period_id_end = 11 imprint_ids = [321] transaction_type_ids = [22] country_codes = ['NO', 'GB'] statement_period_id_start = 10 statement_period_id_end = 20 order_by = 'imprint' order_dir = 'desc' search_term = 'Test' payload = PaginatedRevenueBySubaccountSchema( items=[ RevenueBySubaccountFactory.build( mechanical_deduction_amount_payee_currency=80.0, publisher_admin_fee_payee_currency=8.0, net_revenue_payee_currency=80.0, gross_revenue_payee_currency=100.00, ), ], pagination=PaginationSchema( pagination_type='standard', total_records=1, ) ) mock_logic.return_value = payload actual = fixture_client.get( f'/revenue-analysis/account/{account_id}/subaccount', params={ 'limit': limit, 'offset': offset, 'artist_id': artist_id, 'contract_id': contract_id, 'store_ids': store_ids, 'activity_period_id_start': activity_period_id_start, 'activity_period_id_end': activity_period_id_end, 'imprint_ids': imprint_ids, 'transaction_type_ids': transaction_type_ids, 'country_codes': country_codes, 'statement_period_id_start': statement_period_id_start, 'statement_period_id_end': statement_period_id_end, 'order_by': order_by, 'order_dir': order_dir, 'search_term': search_term, } ) assert actual.status_code == 200 assert actual.json() == { 'items': [ { 'subaccount_id': 111222, 'subaccount_name': 'Test Subaccount', 'account_id': 123, 'contract_id': None, 'account_payee_currency': 'USD', 'mechanical_deduction_amount_payee_currency': 80.0, 'publisher_admin_fee_payee_currency': 8.0, 'net_revenue_payee_currency': 80.0, 'gross_revenue_payee_currency': 100.00 }, ], 'pagination': { 'pagination_type': 'standard', 'total_records': 1, } } mock_logic.assert_called_with( account_id, limit, offset, artist_id, contract_id, store_ids, activity_period_id_start, activity_period_id_end, imprint_ids, transaction_type_ids, country_codes, statement_period_id_start, statement_period_id_end, order_by, order_dir, search_term) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_activity_month') def test_get_revenue_analysis_by_activity_month(mock_logic, fixture_client): """Test getting revenue analysis by activity month.""" account_id = 57608 payload = PaginatedRevenueByActivityMonthSchema( items=[ RevenueByActivityMonthFactory.build( net_share_payee_currency=80.0, gross_revenue_payee_currency=100.00, net_publishing_revenue_payee_currency=10.0, gross_publishing_revenue_payee_currency=20.00, ), RevenueByActivityMonthFactory.build( activity_period_id=119, activity_month_name='June 2024', net_share_payee_currency=160.0, gross_revenue_payee_currency=200.00, ) ], pagination=PaginationSchema( pagination_type='standard', total_records=2, ) ) mock_logic.return_value = payload actual = fixture_client.get(f'/revenue-analysis/account/{account_id}/activity-month') assert actual.status_code == 200 assert actual.json() == { 'items': [ { 'activity_period_id': 120, 'activity_month_name': 'July 2024', 'account_payee_currency': 'USD', 'net_share_payee_currency': 80.0, 'gross_revenue_payee_currency': 100.00, 'net_publishing_revenue_payee_currency': 10.0, 'gross_publishing_revenue_payee_currency': 20.00, 'subaccount_revenue': None }, { 'activity_period_id': 119, 'activity_month_name': 'June 2024', 'account_payee_currency': 'USD', 'net_share_payee_currency': 160.0, 'gross_revenue_payee_currency': 200.00, 'net_publishing_revenue_payee_currency': None, 'gross_publishing_revenue_payee_currency': None, 'subaccount_revenue': None }, ], 'pagination': { 'pagination_type': 'standard', 'total_records': 2, } } mock_logic.assert_called_with( account_id, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, False, project_id=None) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_activity_month') def test_get_revenue_analysis_by_activity_month_subaccount_revenue(mock_logic, fixture_client): """Test getting revenue analysis by activity month paginated.""" account_id = 57608 subaccount_id = 123 item1 = RevenueByActivityMonthFactory.build( net_share_payee_currency=240.0, gross_revenue_payee_currency=300.00, ).to_dict() item1['subaccount_revenue'] = 80 item2 = RevenueByActivityMonthFactory.build( activity_period_id=119, activity_month_name='June 2024', net_share_payee_currency=320.0, gross_revenue_payee_currency=400.00, ).to_dict() item2['subaccount_revenue'] = 160 payload = PaginatedRevenueByActivityMonthSchema( items=[item1, item2], pagination=PaginationSchema( pagination_type='standard', total_records=10, ) ) mock_logic.return_value = payload limit = 2 offset = 0 actual = fixture_client.get( f'/revenue-analysis/account/{account_id}/activity-month?limit={limit}&offset=' f'{offset}&is_subaccount=True&subaccount_id={subaccount_id}') assert actual.status_code == 200 assert actual.json() == { 'items': [ { 'activity_period_id': 120, 'activity_month_name': 'July 2024', 'account_payee_currency': 'USD', 'net_share_payee_currency': 240.0, 'gross_revenue_payee_currency': 300.00, 'net_publishing_revenue_payee_currency': None, 'gross_publishing_revenue_payee_currency': None, 'subaccount_revenue': 80.0 }, { 'activity_period_id': 119, 'activity_month_name': 'June 2024', 'account_payee_currency': 'USD', 'net_share_payee_currency': 320.0, 'gross_revenue_payee_currency': 400.00, 'net_publishing_revenue_payee_currency': None, 'gross_publishing_revenue_payee_currency': None, 'subaccount_revenue': 160.0 }, ], 'pagination': { 'pagination_type': 'standard', 'total_records': 10, } } mock_logic.assert_called_with( account_id, 2, 0, None, subaccount_id, None, None, None, None, None, None, None, None, None, None, None, True, project_id=None) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_activity_month') def test_get_revenue_analysis_by_activity_month_with_filters(mock_logic, fixture_client): """Test getting revenue analysis by activity month with filters.""" account_id = 57608 limit = 10 offset = 5 imprint_ids = [1, 2] store_ids = [3, 4] country_codes = ['US', 'GB'] transaction_type_ids = [7, 8] payload = PaginatedRevenueByActivityMonthSchema( items=[ RevenueByActivityMonthFactory.build(), ], pagination=PaginationSchema( pagination_type='standard', total_records=1, ) ) mock_logic.return_value = payload response = fixture_client.get( f'/revenue-analysis/account/{account_id}/activity-month' f'?limit={limit}&offset={offset}' f'&imprint_ids={imprint_ids[0]}&imprint_ids={imprint_ids[1]}' f'&store_ids={store_ids[0]}&store_ids={store_ids[1]}' f'&country_codes={country_codes[0]}&country_codes={country_codes[1]}' f'&transaction_type_ids={transaction_type_ids[0]}&transaction_type_ids={transaction_type_ids[1]}' # noqa: E501 ) assert response.status_code == 200 assert response.json() == payload.model_dump() mock_logic.assert_called_with( account_id, limit, offset, None, None, None, None, None, None, None, None, None, imprint_ids, store_ids, country_codes, transaction_type_ids, False, project_id=None, ) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_activity_month') def test_get_revenue_analysis_by_activity_month_with_activity_period_filters( mock_logic, fixture_client ): """Test getting revenue analysis by activity month with activity period filters.""" account_id = 57608 activity_period_id_start = 202301 activity_period_id_end = 202303 payload = PaginatedRevenueByActivityMonthSchema( items=[ RevenueByActivityMonthFactory.build(activity_period_id=202301), RevenueByActivityMonthFactory.build(activity_period_id=202302), ], pagination=PaginationSchema( pagination_type='standard', total_records=2, ) ) mock_logic.return_value = payload response = fixture_client.get( f'/revenue-analysis/account/{account_id}/activity-month' f'?activity_period_id_start={activity_period_id_start}' f'&activity_period_id_end={activity_period_id_end}' ) assert response.status_code == 200 mock_logic.assert_called_with( account_id, None, None, None, None, None, None, None, None, None, activity_period_id_start, activity_period_id_end, None, None, None, None, False, project_id=None, ) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_artist') def test_get_revenue_analysis_by_artist_subaccount_revenue(mock_logic, fixture_client): """Test getting revenue analysis by artist.""" account_id = 57608 subaccount_id = 123 item1 = RevenueByArtistFactory.build(account_id=account_id).to_dict() item1['subaccount_revenue'] = 80 item2 = RevenueByArtistFactory.build(account_id=account_id).to_dict() item2['subaccount_revenue'] = 100 payload = PaginatedRevenueByArtistSchema( items=[item1, item2], pagination=PaginationSchema( pagination_type='standard', total_records=10, ) ) mock_logic.return_value = payload limit = 2 offset = 0 actual = fixture_client.get( f'/revenue-analysis/account/{account_id}/artist?limit={limit}&offset=' f'{offset}&is_subaccount=True&subaccount_id={subaccount_id}') assert actual.status_code == 200 assert actual.json() == { 'items': [ { 'artist_id': 12345, 'artist_name': 'The Artist Formerly Known As Test Artist', 'account_id': account_id, 'contract_id': None, 'account_payee_currency': 'JPY', 'mechanical_deduction_amount_payee_currency': 80.00, 'publisher_admin_fee_payee_currency': 8.00, 'net_revenue_payee_currency': 80.00, 'gross_revenue_payee_currency': 100.00, 'subaccount_id': None, 'subaccount_revenue': 80.0 }, { 'artist_id': 12345, 'artist_name': 'The Artist Formerly Known As Test Artist', 'account_id': account_id, 'contract_id': None, 'account_payee_currency': 'JPY', 'mechanical_deduction_amount_payee_currency': 160.00, 'publisher_admin_fee_payee_currency': 16.00, 'net_revenue_payee_currency': 160.00, 'gross_revenue_payee_currency': 200.00, 'subaccount_id': None, 'subaccount_revenue': 100.0 }, ], 'pagination': { 'pagination_type': 'standard', 'total_records': 10, } } mock_logic.assert_called_with( account_id, 2, 0, None, subaccount_id, None, None, None, None, ORDER_BY_ARTIST_NAME, OrderDirection.ASC, None, None, None, None, None, True ) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_artist') def test_get_revenue_analysis_by_artist_with_list_filters(mock_logic, fixture_client): """Test getting revenue analysis by artist with list filters.""" account_id = 57608 item = RevenueByArtistFactory.build(account_id=account_id).to_dict() payload = PaginatedRevenueByArtistSchema( items=[item], pagination=PaginationSchema( pagination_type='standard', total_records=1, ) ) mock_logic.return_value = payload limit = 50 offset = 0 store_ids = [101, 102] country_codes = ['US', 'GB'] transaction_type_ids = [301, 302] imprint_ids = [201] activity_period_id_start = 202301 activity_period_id_end = 202312 url = (f'/revenue-analysis/account/{account_id}/artist?limit={limit}&offset={offset}' f'&store_ids={store_ids[0]}&store_ids={store_ids[1]}' f'&country_codes={country_codes[0]}&country_codes={country_codes[1]}' f'&transaction_type_ids={transaction_type_ids[0]}&transaction_type_ids={transaction_type_ids[1]}' # noqa: E501 f'&imprint_ids={imprint_ids[0]}' f'&activity_period_id_start={activity_period_id_start}' f'&activity_period_id_end={activity_period_id_end}') actual = fixture_client.get(url) assert actual.status_code == 200 assert len(actual.json()['items']) == 1 mock_logic.assert_called_with( account_id, limit, offset, None, None, None, None, activity_period_id_start, activity_period_id_end, ORDER_BY_ARTIST_NAME, OrderDirection.ASC, None, store_ids, country_codes, transaction_type_ids, imprint_ids, False ) @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_store') def test_get_revenue_analysis_by_store_with_project_id(mock_logic, fixture_client): """Test that project_id is forwarded to the store logic.""" account_id = 57608 project_id = 4242 mock_logic.return_value = PaginatedRevenueByStoreSchema( items=[], totals=RevenuePayeeCurrencyTotalsSchema( net_revenue_payee_currency=None, gross_revenue_payee_currency=None, ), pagination=PaginationSchema(pagination_type='standard', total_records=0), ) response = fixture_client.get( f'/revenue-analysis/account/{account_id}/store?project_id={project_id}') assert response.status_code == 200 assert mock_logic.call_args.kwargs['project_id'] == project_id @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_country') def test_get_revenue_analysis_by_country_with_project_id(mock_logic, fixture_client): """Test that project_id is forwarded to the country logic.""" account_id = 57608 project_id = 4242 mock_logic.return_value = [] response = fixture_client.get( f'/revenue-analysis/account/{account_id}/country?project_id={project_id}') assert response.status_code == 200 assert mock_logic.call_args.kwargs['project_id'] == project_id @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_transaction_type') def test_get_revenue_analysis_by_transaction_type_with_project_id(mock_logic, fixture_client): """Test that project_id is forwarded to the transaction-type logic.""" account_id = 57608 project_id = 4242 mock_logic.return_value = ResponseRevenueByTransactionTypeSchema( items=[], totals=RevenuePayeeCurrencyTotalsSchema( net_revenue_payee_currency=0, gross_revenue_payee_currency=0, ), ) response = fixture_client.get( f'/revenue-analysis/account/{account_id}/transaction-type?project_id={project_id}') assert response.status_code == 200 assert mock_logic.call_args.kwargs['project_id'] == project_id @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_activity_month') def test_get_revenue_analysis_by_activity_month_with_project_id(mock_logic, fixture_client): """Test that project_id is forwarded to the activity-month logic.""" account_id = 57608 project_id = 4242 mock_logic.return_value = PaginatedRevenueByActivityMonthSchema( items=[], pagination=PaginationSchema(pagination_type='standard', total_records=0), ) response = fixture_client.get( f'/revenue-analysis/account/{account_id}/activity-month?project_id={project_id}') assert response.status_code == 200 assert mock_logic.call_args.kwargs['project_id'] == project_id @patch('moneyhub.handlers.revenue_analysis.logic.get_revenue_analysis_by_statement_period') def test_get_revenue_analysis_by_statement_period_with_project_id(mock_logic, fixture_client): """Test that project_id is forwarded to the statement-period logic.""" account_id = 57608 project_id = 4242 mock_logic.return_value = [] params = { 'project_id': project_id, 'statement_period_id_start': 123, 'statement_period_id_end': 124 } response = fixture_client.get( f'/revenue-analysis/account/{account_id}/statement-period', params=params) assert response.status_code == 200 assert mock_logic.call_args.kwargs['project_id'] == project_id