"""Test for report_custom schema.""" from datetime import datetime from moneyhub.constants.constants import NumberFormat from moneyhub.constants.constants import ReportCustomColumnDimension from moneyhub.constants.constants import ReportCustomFileType from moneyhub.constants.constants import ReportCustomRowDimension from moneyhub.constants.constants import ReportCustomStatus from moneyhub.constants.constants import RevenueDisplayType from moneyhub.constants.constants import RevenueType from moneyhub.schemas.report_custom import ReportCustomCreateSchema from moneyhub.schemas.report_custom import ReportCustomDetailSchema from moneyhub.schemas.report_custom import ReportCustomFiltersSchema from moneyhub.schemas.report_custom import ReportCustomUpdateSchema def test_report_custom_schema(): """Test getting a dict from ReportCustomDetailSchema.""" expected = ReportCustomDetailSchema( report_custom_id=11, account_id=121, contract_id=77, subaccount_id=445, statement_period_ids=[1, 2, 3], revenue_type=RevenueType.DISTRIBUTION, revenue_display_type=RevenueDisplayType.GROSS, report_custom_status=ReportCustomStatus.COMPLETE, dimension_column=ReportCustomColumnDimension.STATEMENT_PERIOD, dimension_row=ReportCustomRowDimension.PRODUCT, filters=ReportCustomFiltersSchema( store_ids=[286, 1, 348], country_codes=['US', 'GB'], transaction_type_ids=[1, 2, 3], imprint_ids=[1, 2, 3], activity_period_ids=[1, 2, 3], artist_ids=[2, 3, 4], product_ids=[3, 4, 5], project_ids=[1, 2, 3], subaccount_ids=[4, 5, 6], recording_ids=['5', 'fake-6', 'fake-7'], track_unique_ids=[6, 7, 7], ), number_format=NumberFormat.EU, file_type=ReportCustomFileType.XLS, file_location=None, created_at=datetime(2022, 9, 26), created_by='someone' ) mock_response = { 'report_custom_id': 11, 'account_id': 121, 'contract_id': 77, 'subaccount_id': 445, 'statement_period_ids': '1,2,3', 'revenue_type': 'distribution', 'revenue_display_type': 'gross', 'report_custom_status': 'complete', 'dimension_column': 'statement_period', 'dimension_row': 'product', 'filters': { 'store_ids': [286, 1, 348], 'country_codes': ['US', 'GB'], 'transaction_type_ids': [1, 2, 3], 'imprint_ids': [1, 2, 3], 'activity_period_ids': [1, 2, 3], 'artist_ids': [2, 3, 4], 'product_ids': [3, 4, 5], 'project_ids': [1, 2, 3], 'subaccount_ids': [4, 5, 6], 'recording_ids': ['5', 'fake-6', 'fake-7'], 'track_unique_ids': [6, 7], }, 'number_format': 'eu', 'file_type': 'xls', 'file_location': None, 'created_at': '2022-09-26T00:00:00', 'created_by': 'someone' } actual = ReportCustomDetailSchema(**mock_response) assert expected == actual def test_report_custom_create_schema_defaults_revenue_display_type_to_net(): """When omitted, revenue_display_type defaults to NET.""" schema = ReportCustomCreateSchema( statement_period_ids=[1], revenue_type=RevenueType.DISTRIBUTION, dimension_column=ReportCustomColumnDimension.STATEMENT_PERIOD, dimension_row=ReportCustomRowDimension.PRODUCT, ) assert schema.revenue_display_type == RevenueDisplayType.NET def test_report_custom_schema_missing_filters(): """Get a custom report with some empty filters.""" expected = ReportCustomDetailSchema( report_custom_id=11, account_id=121, contract_id=77, subaccount_id=445, statement_period_ids=[1, 2, 3], revenue_type=RevenueType.DISTRIBUTION, report_custom_status=ReportCustomStatus.COMPLETE, dimension_column=ReportCustomColumnDimension.STATEMENT_PERIOD, dimension_row=ReportCustomRowDimension.PRODUCT, filters=ReportCustomFiltersSchema( store_ids=[286, 1, 348], country_codes=['US', 'GB'], activity_period_ids=[1, 2, 3], product_ids=[3, 4, 5], subaccount_ids=[4, 5, 6], recording_ids=['5', 'fake-6', 'fake-7'], ), number_format=NumberFormat.EU, file_type=ReportCustomFileType.XLS, file_location=None, created_at=datetime(2022, 9, 26), created_by='someone' ) mock_response = { 'report_custom_id': 11, 'account_id': 121, 'contract_id': 77, 'subaccount_id': 445, 'statement_period_ids': '1,2,3', 'revenue_type': 'distribution', 'report_custom_status': 'complete', 'dimension_column': 'statement_period', 'dimension_row': 'product', 'filters': { 'store_ids': [286, 1, 348], 'country_codes': ['US', 'GB'], 'transaction_type_ids': [], 'imprint_ids': [], 'activity_period_ids': [1, 2, 3], 'artist_ids': [], 'product_ids': [3, 4, 5], 'project_ids': [], 'subaccount_ids': [4, 5, 6], 'recording_ids': ['5', 'fake-6', 'fake-7'], 'track_unique_ids': [], }, 'number_format': 'eu', 'file_type': 'xls', 'file_location': None, 'created_at': '2022-09-26T00:00:00', 'created_by': 'someone' } actual = ReportCustomDetailSchema(**mock_response) assert expected == actual def test_report_custom_schema_empty_statement_period(): """Test getting a dict from ReportCustomDetailSchema.""" expected = ReportCustomDetailSchema( report_custom_id=11, account_id=121, contract_id=77, subaccount_id=445, statement_period_ids=[], revenue_type=RevenueType.DISTRIBUTION, report_custom_status=ReportCustomStatus.COMPLETE, dimension_column=ReportCustomColumnDimension.STATEMENT_PERIOD, dimension_row=ReportCustomRowDimension.PRODUCT, filters=None, number_format=NumberFormat.US, file_type=ReportCustomFileType.CSV, file_location=None, created_at=datetime(2022, 9, 26), created_by='someone' ) mock_response = { 'report_custom_id': 11, 'account_id': 121, 'contract_id': 77, 'subaccount_id': 445, 'statement_period_ids': '', 'revenue_type': 'distribution', 'report_custom_status': 'complete', 'dimension_column': 'statement_period', 'dimension_row': 'product', 'filters': None, 'number_format': 'us', 'file_type': 'csv', 'file_location': None, 'created_at': '2022-09-26T00:00:00', 'created_by': 'someone' } actual = ReportCustomDetailSchema(**mock_response) assert expected == actual def test_report_custom_create_schema(): """Test getting a dict from ReportCustomCreateSchema.""" expected = ReportCustomCreateSchema( contract_id=77, subaccount_id=445, statement_period_ids=[1, 2, 3], revenue_type=RevenueType.DISTRIBUTION, dimension_column=ReportCustomColumnDimension.STATEMENT_PERIOD, dimension_row=ReportCustomRowDimension.PRODUCT, filters=ReportCustomFiltersSchema( store_ids=[286, 1, 348], country_codes=['US', 'GB'], transaction_type_ids=[1, 2, 3], imprint_ids=[1, 2, 3], activity_period_ids=[1, 2, 3], artist_ids=[2, 3, 4], product_ids=[3, 4, 5], project_ids=[1, 2, 3], subaccount_ids=[4, 5, 6], recording_ids=['5', '6', '7'], track_unique_ids=[6, 7, 8], ), ) mock_response = { 'contract_id': 77, 'subaccount_id': 445, 'statement_period_ids': [1, 2, 3], 'revenue_type': 'distribution', 'dimension_column': 'statement_period', 'dimension_row': 'product', 'filters': { 'store_ids': [286, 1, 348], 'country_codes': ['US', 'GB'], 'transaction_type_ids': [1, 2, 3], 'imprint_ids': [1, 2, 3], 'activity_period_ids': [1, 2, 3], 'artist_ids': [2, 3, 4], 'product_ids': [3, 4, 5], 'project_ids': [1, 2, 3], 'subaccount_ids': [4, 5, 6], 'recording_ids': ['5', '6', '7'], 'track_unique_ids': [6, 7, 8], }, 'number_format': 'us', 'file_type': 'csv', } actual = ReportCustomCreateSchema(**mock_response) assert actual == expected def test_report_custom_update_schema(): """Test getting a dict from ReportCustomUpdateSchema.""" expected = ReportCustomUpdateSchema( file_location=None, report_custom_status=ReportCustomStatus.COMPLETE, ) mock_response = { 'file_location': None, 'report_custom_status': 'complete', } actual = ReportCustomUpdateSchema(**mock_response) assert actual == expected