added small integration test
This commit is contained in:
parent
63008be829
commit
326b956be4
@ -19,6 +19,7 @@ class FunctionsTestCase(IsolatedAsyncioTestCase):
|
|||||||
TEST_HTML_FILE_PATH = Path(THIS_DIR, 'test_structure.html')
|
TEST_HTML_FILE_PATH = Path(THIS_DIR, 'test_structure.html')
|
||||||
|
|
||||||
log_lvl: int
|
log_lvl: int
|
||||||
|
test_html: str
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_mock_session(response_text: str = None) -> MagicMock:
|
def get_mock_session(response_text: str = None) -> MagicMock:
|
||||||
@ -33,8 +34,8 @@ class FunctionsTestCase(IsolatedAsyncioTestCase):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls) -> None:
|
def setUpClass(cls) -> None:
|
||||||
with open(cls.TEST_HTML_FILE_PATH, 'r') as f:
|
with open(cls.TEST_HTML_FILE_PATH, 'r') as f:
|
||||||
test_html = f.read()
|
cls.test_html = f.read()
|
||||||
cls.test_soup = BeautifulSoup(test_html, HTML_PARSER)
|
cls.test_soup = BeautifulSoup(cls.test_html, HTML_PARSER)
|
||||||
cls.log_lvl = functions.log.level
|
cls.log_lvl = functions.log.level
|
||||||
functions.log.setLevel(logging.CRITICAL)
|
functions.log.setLevel(logging.CRITICAL)
|
||||||
|
|
||||||
@ -165,3 +166,22 @@ class FunctionsTestCase(IsolatedAsyncioTestCase):
|
|||||||
mock_get_bs.assert_called_once_with(symbol, quarterly, mock_session)
|
mock_get_bs.assert_called_once_with(symbol, quarterly, mock_session)
|
||||||
mock_get_is.assert_called_once_with(symbol, quarterly, mock_session)
|
mock_get_is.assert_called_once_with(symbol, quarterly, mock_session)
|
||||||
mock_get_cf.assert_called_once_with(symbol, quarterly, mock_session)
|
mock_get_cf.assert_called_once_with(symbol, quarterly, mock_session)
|
||||||
|
|
||||||
|
@patch.object(functions, 'ClientSession')
|
||||||
|
async def test_integration_get_company_financials(self, mock_session_cls):
|
||||||
|
mock_session_cls.return_value = mock_session_obj = self.get_mock_session(self.test_html)
|
||||||
|
symbol = 'foo'
|
||||||
|
# Since we mock the web request and always receive the same HTML markup,
|
||||||
|
# and the function essentially does 3 separate requests always updating the output dictionary with the same
|
||||||
|
# data, we expect it to remain unchanged and only having one item.
|
||||||
|
expected_output = {
|
||||||
|
END_DATE: ('End_Date_1', 'End_Date_2'),
|
||||||
|
'Cash & Short Term Investments': (11000000, -22000000),
|
||||||
|
}
|
||||||
|
output = await functions.get_company_financials(symbol, session=mock_session_obj)
|
||||||
|
self.assertDictEqual(expected_output, output)
|
||||||
|
mock_session_obj.get.assert_has_calls([
|
||||||
|
call(f'{BASE_URL}/{symbol}/financials{FIN_STMT_URL_SUFFIX[BS]}'),
|
||||||
|
call(f'{BASE_URL}/{symbol}/financials{FIN_STMT_URL_SUFFIX[IS]}'),
|
||||||
|
call(f'{BASE_URL}/{symbol}/financials{FIN_STMT_URL_SUFFIX[CF]}'),
|
||||||
|
])
|
||||||
|
@ -23,13 +23,13 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td><div> Item_1 </div><div> Item_1 </div></td>
|
<td><div> Cash & Short Term Investments </div><div> Cash & Short Term Investments </div></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td><div> <div data-chart-data="11000000.0,-22000000.0"><div></div></td>
|
<td><div> <div data-chart-data="11000000.0,-22000000.0"><div></div></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><div> Item_2 </div><div> Item_2 </div></td>
|
<td><div> Cash & Short Term Investments Growth </div><div> Cash & Short Term Investments Growth </div></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
|
Loading…
Reference in New Issue
Block a user