"""Test for statement_attachment schema.""" from datetime import datetime from moneyhub.constants.constants import NumberFormat from moneyhub.constants.constants import StatementAttachmentFailureReason from moneyhub.constants.constants import StatementAttachmentFileType from moneyhub.constants.constants import StatementAttachmentStatus from moneyhub.constants.constants import StatementAttachmentType from moneyhub.schemas.statement_attachment import InternalAttachmentPostSchema from moneyhub.schemas.statement_attachment import StatementAttachmentDetailSchema from moneyhub.schemas.statement_attachment import StatementAttachmentFiltersSchema from moneyhub.schemas.statement_attachment import StatementAttachmentInvoiceDetailSchema from moneyhub.schemas.statement_attachment import StatementAttachmentLegacyReportSchema from moneyhub.schemas.statement_attachment import StatementAttachmentPutSchema from moneyhub.schemas.statement_attachment import StatementAttachmentRegenerateSchema def test_statement_attachment_detail_schema(): """Test statement attachment detail schema.""" expected = StatementAttachmentDetailSchema( account_id=1, contract_id=2, file_location=None, displayed_file_name='rps_001_Aquilo_Third_Party-_Jon_Class_(You_Should_Get_Some_Sleep).pdf', file_type=StatementAttachmentFileType.PDF, invoice_number='6575765765', number_format=NumberFormat.US, statement_attachment_id=1, statement_attachment_status=StatementAttachmentStatus.IN_PROGRESS.value, statement_attachment_type=StatementAttachmentType.DISTRIBUTION_FEE_INVOICE.value, failure_reason=StatementAttachmentFailureReason.MISSING_TAX_INFORMATION.value, statement_period_id=1, statement_period_ids='1', created_at=datetime(2010, 9, 8, 7, 6, 5), created_by='me', ) data = { 'account_id': 1, 'contract_id': 2, 'file_location': None, 'displayed_file_name': 'rps_001_Aquilo_Third_Party-_Jon_Class_(You_Should_Get_Some_Sleep).pdf', # noqa: E501 'file_type': StatementAttachmentFileType.PDF, 'invoice_number': '6575765765', 'number_format': NumberFormat.US, 'statement_attachment_id': 1, 'statement_attachment_status': 'in_progress', 'statement_attachment_type': 'distribution_fee_invoice', 'failure_reason': 'missing_tax_information', 'statement_period_id': 1, 'statement_period_ids': '1', 'created_at': datetime(2010, 9, 8, 7, 6, 5), 'created_by': 'me', } actual = StatementAttachmentDetailSchema(**data) assert actual == expected def test_statement_attachment_invoice_detail_schema(): """Test statement attachment invoice schema.""" expected = StatementAttachmentInvoiceDetailSchema( account_id=1, account_name='Name', contract_id=2, file_location=None, file_type=StatementAttachmentFileType.PDF, invoice_number='6575765765', number_format=NumberFormat.US, statement_attachment_id=1, statement_attachment_status=StatementAttachmentStatus.IN_PROGRESS.value, statement_attachment_type=StatementAttachmentType.DISTRIBUTION_FEE_INVOICE.value, failure_reason=StatementAttachmentFailureReason.MISSING_TAX_INFORMATION.value, statement_period_id=1, created_at=datetime(2010, 9, 8, 7, 6, 5), created_by='me', ) data = { 'account_id': 1, 'account_name': 'Name', 'contract_id': 2, 'file_location': None, 'file_type': StatementAttachmentFileType.PDF, 'invoice_number': '6575765765', 'number_format': NumberFormat.US, 'statement_attachment_id': 1, 'statement_attachment_status': 'in_progress', 'statement_attachment_type': 'distribution_fee_invoice', 'failure_reason': 'missing_tax_information', 'statement_period_id': 1, 'created_at': datetime(2010, 9, 8, 7, 6, 5), 'created_by': 'me', } actual = StatementAttachmentInvoiceDetailSchema(**data) assert actual == expected def test_statement_attachment_put_schema(): """Test statement attachment PUT schema.""" expected = StatementAttachmentPutSchema( file_location='s3://testurl', statement_attachment_status=StatementAttachmentStatus.IN_PROGRESS, ) mock_response = { 'file_location': 's3://testurl', 'statement_attachment_status': 'in_progress', } actual = StatementAttachmentPutSchema(**mock_response) assert expected == actual def test_statement_attachment_put_schema_with_failure(): """Test statement attachment PUT schema.""" expected = StatementAttachmentPutSchema( file_location='s3://testurl', statement_attachment_status=StatementAttachmentStatus.ERROR, failure_reason=StatementAttachmentFailureReason.MISSING_TAX_INFORMATION ) mock_response = { 'file_location': 's3://testurl', 'statement_attachment_status': 'error', 'failure_reason': 'missing_tax_information' } actual = StatementAttachmentPutSchema(**mock_response) assert expected == actual def test_statement_attachment_regenerate_schema(): """Test statement attachment regenerate schema.""" expected = StatementAttachmentRegenerateSchema( account_id=24601, statement_attachment_type=StatementAttachmentType.REVENUE_DETAIL, ) data = { 'account_id': 24601, 'statement_attachment_type': StatementAttachmentType.REVENUE_DETAIL, } actual = StatementAttachmentRegenerateSchema(**data) assert actual == expected def test_internal_attachment_post_schema(): """Test internal attachment post schema.""" expected = InternalAttachmentPostSchema( file_type=StatementAttachmentFileType.PDF, file_location='https://fakefile.pdf', upload_date=datetime(2022, 10, 31, 10, 10, 10), contract_id=12345, ) data = { 'file_type': 'pdf', 'file_location': 'https://fakefile.pdf', 'upload_date': '2022-10-31T10:10:10', 'contract_id': 12345, } actual = InternalAttachmentPostSchema(**data) assert actual == expected def test_statement_attachment_filters_schema(): """Test statement attachment filters schema.""" expected = StatementAttachmentFiltersSchema( transaction_type_ids=[1, 2, 3], transaction_type_group_ids=[4, 5, 6], exclude_transaction_type_group_ids=[8, 9, 10], exclude_transaction_type_ids=[11, 12, 13], variant='physical' ) data = { 'transaction_type_ids': [1, 2, 3], 'transaction_type_group_ids': [4, 5, 6], 'exclude_transaction_type_group_ids': [8, 9, 10], 'exclude_transaction_type_ids': [11, 12, 13], 'variant': 'physical' } actual = StatementAttachmentFiltersSchema(**data) assert actual == expected def test_statement_attachment_legacy_report_schema(): """Test statement attachment legacy report schema.""" filters_data = { 'transaction_type_ids': [1, 2, 3], 'transaction_type_group_ids': [4, 5, 6], 'exclude_transaction_type_group_ids': None, 'exclude_transaction_type_ids': None, 'variant': 'all' } expected = StatementAttachmentLegacyReportSchema( account_id=1, contract_id=2, file_location=None, file_type=StatementAttachmentFileType.XLS, invoice_number=None, number_format=NumberFormat.US, statement_attachment_id=1, statement_attachment_status=StatementAttachmentStatus.IN_PROGRESS.value, statement_attachment_type=StatementAttachmentType.LEGACY_REVENUE_DETAIL_PHYSICAL.value, failure_reason=None, statement_period_id=1, statement_period_ids='1', filters=StatementAttachmentFiltersSchema(**filters_data), created_at=datetime(2010, 9, 8, 7, 6, 5), created_by='me', ) data = { 'account_id': 1, 'contract_id': 2, 'file_location': None, 'file_type': StatementAttachmentFileType.XLS, 'invoice_number': None, 'number_format': NumberFormat.US, 'statement_attachment_id': 1, 'statement_attachment_status': 'in_progress', 'statement_attachment_type': 'legacy_revenue_detail_physical', 'failure_reason': None, 'statement_period_id': 1, 'statement_period_ids': '1', 'filters': filters_data, 'created_at': datetime(2010, 9, 8, 7, 6, 5), 'created_by': 'me', } actual = StatementAttachmentLegacyReportSchema(**data) assert actual == expected