mwfin/tests/test_functions.py

62 lines
1.9 KiB
Python

from unittest import IsolatedAsyncioTestCase
from unittest.mock import patch, MagicMock, AsyncMock, call
from bs4 import BeautifulSoup
from mwfin import functions
# 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 = ''
TEST_SOUP = BeautifulSoup(TEST_HTML, 'html.parser')
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):
expected_output = ('End_Date_1', 'End_Date_2')
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