fixes; another function implemented
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from unittest import IsolatedAsyncioTestCase
|
||||
from unittest.mock import patch, MagicMock, AsyncMock, call
|
||||
@ -17,6 +18,8 @@ class FunctionsTestCase(IsolatedAsyncioTestCase):
|
||||
# view page source @ line 2055
|
||||
TEST_HTML_FILE_PATH = Path(THIS_DIR, 'test_structure.html')
|
||||
|
||||
log_lvl: int
|
||||
|
||||
@staticmethod
|
||||
def get_mock_session(response_text: str = None) -> MagicMock:
|
||||
mock_response = MagicMock()
|
||||
@ -32,6 +35,12 @@ class FunctionsTestCase(IsolatedAsyncioTestCase):
|
||||
with open(cls.TEST_HTML_FILE_PATH, 'r') as f:
|
||||
test_html = f.read()
|
||||
cls.test_soup = BeautifulSoup(test_html, HTML_PARSER)
|
||||
cls.log_lvl = functions.log.level
|
||||
functions.log.setLevel(logging.CRITICAL)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls) -> None:
|
||||
functions.log.setLevel(cls.log_lvl)
|
||||
|
||||
@patch.object(functions, 'ClientSession')
|
||||
async def test_soup_from_url(self, mock_session_cls):
|
||||
@ -47,21 +56,21 @@ class FunctionsTestCase(IsolatedAsyncioTestCase):
|
||||
self.assertTupleEqual(expected_output, output)
|
||||
|
||||
def test_is_relevant_table_row(self):
|
||||
test_html = '<tr><td><div> Cash & Short Term Investments </div></td></tr>'
|
||||
test_soup = BeautifulSoup(test_html, HTML_PARSER)
|
||||
test_soup = BeautifulSoup('<tr><td><div> Cash & Short Term Investments </div></td></tr>', HTML_PARSER)
|
||||
self.assertTrue(functions.is_relevant_table_row(test_soup.tr))
|
||||
test_html = '<tr><td><div> Cash & Short Term Investments Growth </div></td></tr>'
|
||||
test_soup = BeautifulSoup(test_html, HTML_PARSER)
|
||||
test_soup = BeautifulSoup('<tr><td><div> Cash & Short Term Investments Growth </div></td></tr>', HTML_PARSER)
|
||||
self.assertFalse(functions.is_relevant_table_row(test_soup.tr))
|
||||
test_soup = BeautifulSoup('<tr><td><div> baz </div></td></tr>', HTML_PARSER)
|
||||
self.assertFalse(functions.is_relevant_table_row(test_soup.tr))
|
||||
self.assertFalse(functions.is_relevant_table_row(test_soup.div))
|
||||
|
||||
@patch.object(functions, 'is_relevant_table_row')
|
||||
def test_find_relevant_table_rows(self, mock_is_relevant_table_row):
|
||||
mock_is_relevant_table_row.return_value = True
|
||||
test_table = self.test_soup.find('div', attrs={'class': 'financials'})
|
||||
expected_output = test_table.find_all('tr')[1:-1]
|
||||
expected_output = self.test_soup.find('div', attrs={'class': 'financials'}).tbody.find_all('tr')
|
||||
output = functions.find_relevant_table_rows(self.test_soup)
|
||||
self.assertListEqual(expected_output, output)
|
||||
mock_is_relevant_table_row.assert_called_once_with(expected_output[0])
|
||||
mock_is_relevant_table_row.assert_has_calls([call(expected_output[0]), call(expected_output[1])])
|
||||
|
||||
def test_extract_row_data(self):
|
||||
test_table = self.test_soup.find('div', attrs={'class': 'financials'}).div.div.table
|
||||
|
Reference in New Issue
Block a user