"""Revenue By Recording Distro model tests.""" from decimal import Decimal from moneyhub.constants.constants import ORDER_BY_RECORDING_ID from moneyhub.constants.constants import OrderDirection from moneyhub.models import RevenueByRecordingDistro from tests.unit.conftest import using_mock_snowflake_table _MOCK_DATA = { 'revenue_by_recording_distro_dbt': [ { 'recording_id': 37736998, 'recording_title': 'Thrift Shop', 'artist': 'Macklemore & Ryan Lewis feat. Wanz', 'version': 'Acoustic', 'isrc': 'JPYE70900611', 'account_id': 24601, 'contract_id': 535866, 'statement_period_id': 123, 'account_payee_currency': 'JPY', 'net_share_payee_currency': Decimal('8.00'), 'gross_revenue_payee_currency': Decimal('10.00'), 'store_id': 101, 'country_code': 'US', 'imprint_id': 201, 'transaction_type_id': 301, 'activity_period_id': 100, }, { 'recording_id': 37736999, 'recording_title': "Can't Hold Us", 'artist': 'Macklemore & Ryan Lewis feat. Ray Dalton', 'version': 'Acoustic', 'isrc': 'fake5678', 'account_id': 24601, 'contract_id': 10001, 'statement_period_id': 123, 'account_payee_currency': 'USD', 'net_share_payee_currency': Decimal('12222.00'), 'gross_revenue_payee_currency': Decimal('12226.00'), 'store_id': 102, 'country_code': 'GB', 'imprint_id': 202, 'transaction_type_id': 302, 'activity_period_id': 101, }, { 'recording_id': 37768138, 'recording_title': 'Gold', 'artist': 'Macklemore & Ryan Lewis', 'version': 'Acoustic', 'isrc': 'fake91011', 'account_id': 24601, 'contract_id': 18001, 'statement_period_id': 123, 'account_payee_currency': 'USD', 'net_share_payee_currency': Decimal('30022.00'), 'gross_revenue_payee_currency': Decimal('30029.00'), 'store_id': 103, 'country_code': 'CA', 'imprint_id': 203, 'transaction_type_id': 303, 'activity_period_id': 102, }, ], } @using_mock_snowflake_table(RevenueByRecordingDistro, _MOCK_DATA) def test_get_by_account_id(): """Test getting revenue by account.""" account_id = 24601 limit = 50 offset = 0 (items, total_record) = RevenueByRecordingDistro.get_by_account_id( account_id, limit, offset, None, None, None, None, ORDER_BY_RECORDING_ID, OrderDirection.ASC) actual = items[0]._asdict() assert actual == { 'recording_id': Decimal('37736998'), 'recording_title': 'Thrift Shop', 'artist': 'Macklemore & Ryan Lewis feat. Wanz', 'version': 'Acoustic', 'isrc': 'JPYE70900611', 'account_id': Decimal('24601'), 'account_payee_currency': 'JPY', 'net_share_payee_currency': Decimal('8.000000000000'), 'gross_revenue_payee_currency': Decimal('10.000000000000'), 'total_records': 3, } assert total_record == 3 @using_mock_snowflake_table(RevenueByRecordingDistro, _MOCK_DATA) def test_get_by_account_id_with_filters(): """Test getting by account with filters.""" account_id = 24601 limit = 50 offset = 0 recording_title = 'Hold Us' statement_period_start = 123 statement_period_end = 124 (items, total_record) = RevenueByRecordingDistro.get_by_account_id( account_id, limit, offset, None, statement_period_start, statement_period_end, recording_title, ORDER_BY_RECORDING_ID, OrderDirection.ASC, 101, 101) assert [item._asdict() for item in items] == [ { 'recording_id': Decimal('37736999'), 'recording_title': "Can't Hold Us", 'artist': 'Macklemore & Ryan Lewis feat. Ray Dalton', 'version': 'Acoustic', 'isrc': 'fake5678', 'account_id': Decimal('24601'), 'account_payee_currency': 'USD', 'net_share_payee_currency': Decimal('12222.000000000000'), 'gross_revenue_payee_currency': Decimal('12226.000000000000'), 'total_records': 1, }, ] assert total_record == 1 @using_mock_snowflake_table(RevenueByRecordingDistro, _MOCK_DATA) def test_get_by_account_id_with_list_filters(): """Test getting by account with list filters.""" account_id = 24601 limit = 50 offset = 0 store_ids = [101, 102] country_codes = ['US', 'GB'] imprint_ids = [201] transaction_type_ids = [301, 302] (items, total_record) = RevenueByRecordingDistro.get_by_account_id( account_id, limit, offset, None, None, None, None, ORDER_BY_RECORDING_ID, OrderDirection.ASC, 100, 101, store_ids, country_codes, imprint_ids, transaction_type_ids) assert [item._asdict() for item in items] == [ { 'recording_id': Decimal('37736998'), 'recording_title': 'Thrift Shop', 'artist': 'Macklemore & Ryan Lewis feat. Wanz', 'version': 'Acoustic', 'isrc': 'JPYE70900611', 'account_id': Decimal('24601'), 'account_payee_currency': 'JPY', 'net_share_payee_currency': Decimal('8.000000000000'), 'gross_revenue_payee_currency': Decimal('10.000000000000'), 'total_records': 1, }, ] assert total_record == 1 @using_mock_snowflake_table(RevenueByRecordingDistro, _MOCK_DATA) def test_get_by_account_id_with_activity_period_filter(): """Test getting by account with activity period filters.""" account_id = 24601 limit = 50 offset = 0 (items, total_record) = RevenueByRecordingDistro.get_by_account_id( account_id, limit, offset, None, None, None, None, ORDER_BY_RECORDING_ID, OrderDirection.ASC, 100, 101) assert [item._asdict() for item in items] == [ { 'recording_id': Decimal('37736998'), 'recording_title': 'Thrift Shop', 'artist': 'Macklemore & Ryan Lewis feat. Wanz', 'version': 'Acoustic', 'isrc': 'JPYE70900611', 'account_id': Decimal('24601'), 'account_payee_currency': 'JPY', 'net_share_payee_currency': Decimal('8.000000000000'), 'gross_revenue_payee_currency': Decimal('10.000000000000'), 'total_records': 2, }, { 'recording_id': Decimal('37736999'), 'recording_title': "Can't Hold Us", 'artist': 'Macklemore & Ryan Lewis feat. Ray Dalton', 'version': 'Acoustic', 'isrc': 'fake5678', 'account_id': Decimal('24601'), 'account_payee_currency': 'USD', 'net_share_payee_currency': Decimal('12222.000000000000'), 'gross_revenue_payee_currency': Decimal('12226.000000000000'), 'total_records': 2, }, ] assert total_record == 2 @using_mock_snowflake_table(RevenueByRecordingDistro, _MOCK_DATA) def test_get_recordings_by_account_id(): """Test getting distinct recordings by account id.""" account_id = 24601 limit = 50 recordings = RevenueByRecordingDistro.get_recordings_by_account_id(account_id, limit, None) assert len(recordings) == 3 recording_ids = [r.recording_id for r in recordings] assert 37736998 in recording_ids assert 37736999 in recording_ids assert 37768138 in recording_ids @using_mock_snowflake_table(RevenueByRecordingDistro, _MOCK_DATA) def test_get_recordings_by_account_id_with_search(): """Test getting distinct recordings by account id with a search term.""" account_id = 24601 limit = 50 search_term = 'Thrift' recordings = RevenueByRecordingDistro.get_recordings_by_account_id( account_id, limit, search_term) assert len(recordings) == 1 assert recordings[0].recording_title == 'Thrift Shop' assert recordings[0].recording_id == 37736998 @using_mock_snowflake_table(RevenueByRecordingDistro, _MOCK_DATA) def test_get_recordings_by_account_id_with_contract_id(): """Test getting distinct recordings by account id with a contract id filter.""" account_id = 24601 limit = 50 contract_id = 535866 recordings = RevenueByRecordingDistro.get_recordings_by_account_id( account_id, limit, None, contract_id) assert len(recordings) == 1 assert recordings[0].recording_title == 'Thrift Shop' assert recordings[0].recording_id == 37736998