"""Tests for the neighbouring rights label revenue report generation.""" from decimal import Decimal from os import path from unittest.mock import patch import config from src.documents import neighbouring_rights_label_revenue HEADERS = [ 'Statement', 'Contract ID', 'Contracting Party', 'Sub-Label Name', 'ISRC', 'Recording Title', 'Recording Version', 'Recording Artist', 'Collection Society', 'Country', 'Transaction Type', 'Transaction Subtype', 'Usage Start Date', 'Usage End Date', 'Pre-WHT Amount', 'WHT Amount', 'Gross Revenue', 'Client Share %', 'Commission', 'Net Revenue', 'Currency', 'Royalty Type', 'Original Statement Period', ] def test_process_row(account_fixture): """Test processing a fact_sales row.""" input_row = { 'ABACUS_SALE_TYPE': 'royalty', 'ACCOUNT_PAYEE_CURRENCY': 'JPY', 'ARTISTNAME': '侯嘉艺', 'CONTRACT_ID': 10001, 'COUNTRYNAME': 'Norway', 'CUSTOMER_NAME': 'TIDAL', 'GROSS_REVENUE_PAYEE_CURRENCY': Decimal('9876'), 'GROSS_REVENUE_AFTER_WITHHOLDING_TAX_PAYEE_CURRENCY': Decimal('9076'), 'ISRC': 'QMFMG1429750', 'IMPRINT': 'SPACE TIME CONTINUUM RECORDS', 'ORIGINAL_STATEMENT_PERIOD': 'June 2021', 'NET_SHARE_PAYEE_CURRENCY': Decimal('9000.1'), 'ROYALTY_RATE': Decimal('90'), 'START_DATE': '2022-08-01', 'STATEMENT_PERIOD_NAME': 'May 2023', 'TRACKNAME': 'Salsa Intima', 'TRANSACTION_DATE': '2022-08-25', 'TRANSACTION_SUBTYPE': 'Weekend', 'TRANSACTIONTYPEDESC': 'Video Rental', 'VERSION': 'eBoy Dance Mix', 'WITHHOLDING_TAX_PAYEE_CURRENCY': Decimal('0.000000000000'), } expected = [ 'May 2023', # Statement 10001, # Contract ID account_fixture['account_name'], # Contracting Party 'SPACE TIME CONTINUUM RECORDS', # Sub-Label Name 'QMFMG1429750', # ISRC 'Salsa Intima', # Recording Title 'eBoy Dance Mix', # Recording Version '侯嘉艺', # Recording Artist 'TIDAL', # Source CMO 'Norway', # Country 'Video Rental', # Transaction Type 'Weekend', # Transaction Subtype '2022-08-01', # Usage Start Date '2022-08-25', # Usage End Date Decimal('9876'), # Pre-WHT Amount 0, # WHT Amount Decimal('9076'), # Gross Amount Decimal('90'), # Client Share Decimal('9076') - Decimal('9000.1'), # Commission Decimal('9000.1'), # Net Revenue 'JPY', # Currency 'royalty', # Royalty Type 'June 2021', # Original Statement Period ] result = neighbouring_rights_label_revenue._process_row(input_row, account_fixture) assert result == expected @patch('src.documents.neighbouring_rights_label_revenue.create_report_file') @patch('src.documents.neighbouring_rights_label_revenue.OwsAbacusAccount.get_account') @patch('src.documents.neighbouring_rights_label_revenue.snowflake') @patch('src.documents.neighbouring_rights_label_revenue.OwsRoyalties.get_statement_period') def test_build_document( get_statement_period_mock, snowflake_mock, get_account_mock, create_report_file_mock, account_fixture, statement_period_fixture, ): """Test building a revnue detail report.""" account_id = 24601 contract_id = 20001 statement_period_id = 123 expected = path.join( config.FILE_OUTPUT_PATH, 'Jeans_Nest_20001_July_2022_nr_label_revenue_details.csv' ) # noqa: E501 get_account_mock.return_value = account_fixture get_statement_period_mock.return_value = statement_period_fixture snowflake_mock.get_neighbouring_rights_label_fact_sales.return_value = ([1, 2, 3], 3) create_report_file_mock.return_value = expected result = neighbouring_rights_label_revenue.build_document( account_id, contract_id, statement_period_id ) assert result == expected create_report_file_mock.assert_called_once() assert create_report_file_mock.call_args.args[0] == HEADERS assert create_report_file_mock.call_args.args[1] == [1, 2, 3] assert create_report_file_mock.call_args.args[2] == 3 assert create_report_file_mock.call_args.args[3] == expected