67 lines
2.2 KiB
Python
67 lines
2.2 KiB
Python
from unittest import IsolatedAsyncioTestCase
|
|
from unittest.mock import patch, MagicMock, AsyncMock, call
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
from mwfin import functions
|
|
|
|
|
|
class FunctionsTestCase(IsolatedAsyncioTestCase):
|
|
|
|
@patch.object(functions, 'ClientSession')
|
|
async def test_soup_from_url(self, mock_session_cls):
|
|
test_html = '<b>foo</b>'
|
|
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):
|
|
test_html = '<tr>' \
|
|
'<th><div> ITEM </div></th>' \
|
|
'<th><div> 30-SEP-2020 </div></th>' \
|
|
'<th><div> 31-DEC-2020 </div></th>' \
|
|
'<th><div> 31-MAR-2021 </div></th>' \
|
|
'<th><div> 30-JUN-2021 </div></th>' \
|
|
'<th><div> 30-SEP-2021 </div></th>' \
|
|
'</tr>'
|
|
test_soup = BeautifulSoup(test_html, 'html.parser')
|
|
|
|
expected_output = ('30-SEP-2020', '31-DEC-2020', '31-MAR-2021',
|
|
'30-JUN-2021', '30-SEP-2021')
|
|
output = functions.extract_end_dates(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
|