from unittest.mock import MagicMock from unittest.mock import patch from processing_accounting.bin import copy_avro_files_for_qa @patch('processing_accounting.bin.copy_avro_files_for_qa.s3') def test_copy_avro_files(mock_s3): """Test copy_avro_files """ mock_s3_key = MagicMock() mock_s3_key.key = 'test_key' mock_bucket = MagicMock() mock_bucket.objects.filter.return_value = [mock_s3_key] mock_s3.Bucket.return_value = mock_bucket mock_s3.meta.client.copy.return_value = None copy_avro_files_for_qa.copy_avro_files( '212', 'month', '18805', 'test_key_path') mock_s3.meta.client.copy.assert_any_call( {'Bucket': 'prod-statement-detail-exports', 'Key': 'test_key'}, 'qa-statement-detail-exports', 'test_key') @patch('processing_accounting.bin.copy_avro_files_for_qa.copy_avro_files') def test_run(mock_copy_method): """Test entry point. """ mock_copy_method.return_value = None mock_params = ('-p', '202,203,204', '-i', 'quarter') copy_avro_files_for_qa.run(*mock_params) mock_copy_method.assert_any_call( '202,203,204', 'quarter', [ 2604, 4565, 4938, 5333, 7123, 7724, 8869, 10109, 16055, 16175, 17901, 21127, 22234, 22264, 7482 ], 'schematized_files/{}_label_all_all_{}/user_id_type={}L/') @patch('processing_accounting.bin.copy_avro_files_for_qa.copy_avro_files') def test_run_subaccount(mock_copy_method): """Test entry point for subaccount. """ mock_copy_method.return_value = None mock_params = ('-p', '202', '-i', 'month', '-s') copy_avro_files_for_qa.run(*mock_params) mock_copy_method.assert_any_call( '202', 'month', [13823], 'schematized_files/{}_subaccount_all_all_{}/user_id_type={}S/')