from pathlib import Path from unittest import IsolatedAsyncioTestCase from unittest.mock import patch, MagicMock, AsyncMock, call from bs4 import BeautifulSoup from mwfin import functions THIS_DIR = Path(__file__).parent class FunctionsTestCase(IsolatedAsyncioTestCase): # boiled down & accurate structure of a relevant data table # https://www.marketwatch.com/investing/stock/aapl/financials/cash-flow # view page source @ line 2055 TEST_HTML_FILE_PATH = Path(THIS_DIR, 'test_structure.html') @classmethod def setUpClass(cls) -> None: with open(cls.TEST_HTML_FILE_PATH, 'r') as f: test_html = f.read() cls.test_soup = BeautifulSoup(test_html, functions.HTML_PARSER) @patch.object(functions, 'ClientSession') async def test_soup_from_url(self, mock_session_cls): test_html = 'foo' mock_response = MagicMock() mock_response.text = AsyncMock(return_value=test_html) mock_get_return = MagicMock() mock_get_return.__aenter__ = AsyncMock(return_value=mock_response) mock_session_obj = MagicMock() mock_session_obj.get = MagicMock(return_value=mock_get_return) mock_session_cls.return_value = mock_session_obj expected_output = BeautifulSoup(test_html, 'html.parser') output = await functions.soup_from_url('baz') self.assertEqual(expected_output, output) output = await functions.soup_from_url('baz', mock_session_obj) self.assertEqual(expected_output, output) def test_extract_end_dates(self): expected_output = ('End_Date_1', 'End_Date_2') output = functions.extract_end_dates(self.test_soup) self.assertTupleEqual(expected_output, output) def test_find_relevant_table_rows(self): pass def test_convert_number(self): pass def test_extract_row_data(self): pass def test_extract_all_data(self): pass async def test_get_balance_sheet(self): pass async def test_get_income_statement(self): pass async def test_get_cash_flow_statement(self): pass async def test_get_company_financials(self): pass