def test_parse_page_invalid_url_type(self): valid_page = page.ParseDisplayPage(page_url=self.DUMMY_URL_3) valid_page.source = sample_valid_html_page.split('\n') link = valid_page.parse_page_for_link() assert_equals(link, None) assert_equals(valid_page.image_info.dl_status, status.DownloadStatus.ERROR)
def test_get_valid_page_with_author(self, mocked_response, mocked_metadata): valid_page = page.ParseDisplayPage(page_url=self.DUMMY_URL_1) valid_page.get_image_info() author = valid_page._get_author_name() assert_equals(author, sample_name) assert_equals(mocked_metadata.call_count, 1) assert_equals(mocked_response.call_count, 1)
def test_get_valid_page_info(self, mock_get, mock_metadata): valid_page = page.ParseDisplayPage(page_url=self.DUMMY_URL_1) valid_page.get_image_info() assert_equals(len(valid_page.source_list), len(sample_valid_html_page.split('\n'))) assert_equals(valid_page.image_info.author, sample_name) assert_equals(valid_page.image_info.image_url, sample_link) assert_equals(valid_page.image_info.page_url, self.DUMMY_URL_1) assert_equals(mock_get.call_count, 1)
def test_connection_error(self, mock_get): # Mocks a connection error. requests.get returns None, so return value # should be none, but the mock should have been called MAX_ATTEMPTS # times. valid_page = page.ParseDisplayPage(page_url=self.DUMMY_URL_1) valid_page.RETRY_INTERVAL = 0 # No need to wait, since it is mocked page_content = valid_page.get_page() print(f"PAGE CONTENT:\n{page_content}") assert page_content is None assert_equals(mock_get.call_count, page.ParseDisplayPage.MAX_ATTEMPTS)
def test_parse_page_valid_content_for_link(self, mocked_response, mocked_metadata): valid_page = page.ParseDisplayPage(page_url=self.DUMMY_URL_1) valid_page.source = sample_valid_html_page.split('\n') valid_page.get_image_info() link = valid_page._get_image_url() assert_equals(link, sample_link) assert_equals(valid_page.image_info.dl_status, status.DownloadStatus.NOT_SET) assert_equals(mocked_metadata.call_count, 1) assert_equals(mocked_response.call_count, 1)
def test_get_valid_page(self, mock_get): valid_page = page.ParseDisplayPage(page_url=self.DUMMY_URL_1) page_content = valid_page.get_page() assert_equals(len(page_content), len(sample_valid_html_page.split('\n'))) assert_equals(mock_get.call_count, 1)
def test_incorrect_html_source_found_returns_empty_metadata_dict(self): valid_page = page.ParseDisplayPage(page_url=self.DUMMY_URL_1) valid_page.source_list = sample_html_page_format.split('\n') metadata = valid_page._get_metadata() assert isinstance(metadata, dict) assert_equals(len(metadata.keys()), 0)
def test_no_html_source_found_returns_empty_metadata_dict(self): valid_page = page.ParseDisplayPage(page_url=self.DUMMY_URL_1) metadata = valid_page._get_metadata() assert isinstance(metadata, dict) assert_equals(len(metadata.keys()), 0)
def test_get_source_page_returns_non_200_code(self, mocked_request_error): target_page = page.ParseDisplayPage(page_url=self.DUMMY_URL_1) source = target_page.get_page() assert source is None assert_equals(mocked_request_error.call_count, 1)
def test_get_source_page_for_non_existent_page(self, mock_get_page): target_page = page.ParseDisplayPage(page_url=self.DUMMY_URL_1) target_page.get_image_info() assert target_page.source_list is None
def test_get_page_with_no_content(self, mock_get): valid_page = page.ParseDisplayPage(page_url=self.DUMMY_URL_1) page_content = valid_page.get_page() print(f"PAGE CONTENT:\n{page_content}") assert page_content is None assert_equals(mock_get.call_count, page.ParseDisplayPage.MAX_ATTEMPTS)