"""Revenue By Recording Nr 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 RevenueByRecordingNr from tests.unit.conftest import using_mock_snowflake_table _MOCK_DATA = { 'revenue_by_recording_nr_dbt': [ { 'recording_id': '1234', 'recording_title': 'Title', 'artist': 'Artist', 'version': 'Acoustic', 'isrc': 'JPYE70900611', 'account_id': 24601, 'contract_id': 10001, 'statement_period_id': 123, 'account_payee_currency': 'JPY', 'net_share_payee_currency': Decimal('8.00'), 'gross_revenue_payee_currency': Decimal('10.00'), }, { 'recording_id': '5678', 'recording_title': 'If I Ruled the world (Imagine That)', 'artist': 'Nas', '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'), }, { 'recording_id': '91011', 'recording_title': 'The World is Yours', 'artist': 'Nas', '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'), }, { 'recording_id': '91011', 'recording_title': 'The World is Yours', 'artist': 'Nas', 'version': 'Acoustic', 'isrc': 'fake91011', 'account_id': 24601, 'contract_id': 18001, 'statement_period_id': 124, 'account_payee_currency': 'USD', 'net_share_payee_currency': Decimal('12000.00'), 'gross_revenue_payee_currency': Decimal('12008.00'), } ], } @using_mock_snowflake_table(RevenueByRecordingNr, _MOCK_DATA) def test_get_by_account_id(): """Test getting revenue by account.""" account_id = 24601 limit = 50 offset = 0 (items, total_record) = RevenueByRecordingNr.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': '1234', 'recording_title': 'Title', 'artist': 'Artist', '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(RevenueByRecordingNr, _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 = 'world' statement_period_start = 123 statement_period_end = 124 (items, total_record) = RevenueByRecordingNr.get_by_account_id( account_id, limit, offset, None, statement_period_start, statement_period_end, recording_title, ORDER_BY_RECORDING_ID, OrderDirection.ASC) assert [item._asdict() for item in items] == [ { 'recording_id': '5678', 'recording_title': 'If I Ruled the world (Imagine That)', 'artist': 'Nas', '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, }, { 'recording_id': '91011', 'recording_title': 'The World is Yours', 'artist': 'Nas', 'version': 'Acoustic', 'isrc': 'fake91011', 'account_id': Decimal('24601'), 'account_payee_currency': 'USD', 'net_share_payee_currency': Decimal('42022.000000000000'), 'gross_revenue_payee_currency': Decimal('42037.000000000000'), 'total_records': 2, }, ] assert total_record == 2 @using_mock_snowflake_table(RevenueByRecordingNr, _MOCK_DATA) def test_get_recordings_by_account_id(): """Test getting distinct recordings by account id.""" account_id = 24601 limit = 50 recordings = RevenueByRecordingNr.get_recordings_by_account_id(account_id, limit, None) assert len(recordings) == 3 recording_ids = [r.recording_id for r in recordings] assert '1234' in recording_ids assert '5678' in recording_ids assert '91011' in recording_ids @using_mock_snowflake_table(RevenueByRecordingNr, _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 = 'world' recordings = RevenueByRecordingNr.get_recordings_by_account_id(account_id, limit, search_term) assert len(recordings) == 2 titles = [r.recording_title for r in recordings] assert 'If I Ruled the world (Imagine That)' in titles assert 'The World is Yours' in titles @using_mock_snowflake_table(RevenueByRecordingNr, _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 = 10001 recordings = RevenueByRecordingNr.get_recordings_by_account_id( account_id, limit, None, contract_id) assert len(recordings) == 2 titles = [r.recording_title for r in recordings] assert 'Title' in titles assert 'If I Ruled the world (Imagine That)' in titles