File size: 1,455 Bytes
38171fa |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
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)
|