added small integration test

This commit is contained in:
Daniil Fajnberg 2021-11-27 18:35:12 +01:00
parent 63008be829
commit 326b956be4
2 changed files with 24 additions and 4 deletions

View File

@ -19,6 +19,7 @@ class FunctionsTestCase(IsolatedAsyncioTestCase):
TEST_HTML_FILE_PATH = Path(THIS_DIR, 'test_structure.html')
log_lvl: int
test_html: str
@staticmethod
def get_mock_session(response_text: str = None) -> MagicMock:
@ -33,8 +34,8 @@ class FunctionsTestCase(IsolatedAsyncioTestCase):
@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, HTML_PARSER)
cls.test_html = f.read()
cls.test_soup = BeautifulSoup(cls.test_html, HTML_PARSER)
cls.log_lvl = functions.log.level
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_is.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]}'),
])

View File

@ -23,13 +23,13 @@
</thead>
<tbody>
<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><div> <div data-chart-data="11000000.0,-22000000.0"><div></div></td>
</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>