| from django.test import TestCase | |
| from unittest.mock import patch, Mock | |
| # from data_pipeline.api_helper import MFList | |
| # class TestMFListExtract(TestCase): | |
| # @patch('requests.get') | |
| # def test_extract_successful_response(self, mock_get): | |
| # # Mock a successful response from the Morningstar API | |
| # mock_get.return_value = Mock(status_code=200, json=lambda: {'rows': [{'legalName': 'Test Fund 1', 'isin': '123456789012', 'secId': 'MST01234'}]}) | |
| # # Create an instance of the MFList class | |
| # mf_list = MFList() | |
| # # Call the extract method | |
| # mf_list.extract() | |
| # # Assert that the API response was set | |
| # self.assertIsNotNone(mf_list.api_response) | |
| # # Assert that the transformed data contains the extracted fund information | |
| # self.assertEqual(mf_list.transformed_data, [{'fund_name': 'Test Fund 1', 'isin_number': '123456789012', 'security_id': 'MST01234'}]) | |
| # @patch('requests.get') | |
| # def test_extract_unsuccessful_response(self, mock_get): | |
| # # Mock an unsuccessful response from the Morningstar API | |
| # mock_get.return_value = Mock(status_code=500, json=lambda: {'error': 'Internal Server Error'}) | |
| # # Create an instance of the MFList class | |
| # mf_list = MFList() | |
| # # Call the extract method | |
| # mf_list.extract() | |
| # # Assert that the API response was set | |
| # self.assertIsNone(mf_list.api_response) | |