def get_books_from_http_no_soup_test(self): """ Test the get_books_from_http method when get_soup_for_bible_ref returns a falsey value """ # GIVEN: An instance of BSExtract, and reset log, urllib & get_soup_for_bible_ref mocks instance = BSExtract() self.mock_log.debug.reset_mock() self.mock_urllib.reset_mock() self.mock_get_soup_for_bible_ref.reset_mock() # WHEN: get_books_from_http is called with 'NIV' and get_soup_for_bible_ref returns a None value self.mock_urllib.parse.quote.return_value = 'NIV' self.mock_get_soup_for_bible_ref.return_value = None result = instance.get_books_from_http('NIV') # THEN: The rest mocks should be called with known values and get_books_from_http should return None self.mock_log.debug.assert_called_once_with( 'BSExtract.get_books_from_http("%s")', 'NIV') self.mock_urllib.parse.quote.assert_called_once_with(b'NIV') self.mock_get_soup_for_bible_ref.assert_called_once_with( 'http://m.bibleserver.com/overlay/selectBook?translation=NIV') self.assertIsNone( result, 'BSExtract.get_books_from_http should return None when get_soup_for_bible_ref returns a ' 'false value')
def get_books_from_http_content_test(self): """ Test the get_books_from_http method with sample HTML Also a regression test for bug #1184869. (The anchor tag in the second list item is empty) """ # GIVEN: An instance of BSExtract, and reset log, urllib & get_soup_for_bible_ref mocks and sample HTML data self.test_html = '<ul><li><a href="/overlay/selectChapter?tocBook=1">Genesis</a></li>' \ '<li><a href="/overlay/selectChapter?tocBook=2"></a></li>' \ '<li><a href="/overlay/selectChapter?tocBook=3">Leviticus</a></li></ul>' self.test_soup = BeautifulSoup(self.test_html) instance = BSExtract() self.mock_log.reset_mock() self.mock_urllib.reset_mock() self.mock_get_soup_for_bible_ref.reset_mock() self.mock_send_error_message.reset_mock() # WHEN: get_books_from_http is called with 'NIV' and get_soup_for_bible_ref returns tag object based on the # supplied test data. self.mock_urllib.parse.quote.return_value = 'NIV' self.mock_get_soup_for_bible_ref.return_value = self.test_soup result = instance.get_books_from_http('NIV') # THEN: The rest mocks should be called with known values and get_books_from_http should return the two books # in the test data self.mock_log.debug.assert_called_once_with( 'BSExtract.get_books_from_http("%s")', 'NIV') self.mock_urllib.parse.quote.assert_called_once_with(b'NIV') self.mock_get_soup_for_bible_ref.assert_called_once_with( 'http://m.bibleserver.com/overlay/selectBook?translation=NIV') self.assertFalse(self.mock_log.error.called, 'log.error should not have been called') self.assertFalse(self.mock_send_error_message.called, 'send_error_message should not have been called') self.assertEqual(result, ['Genesis', 'Leviticus'])
def get_books_from_http_no_content_test(self): """ Test the get_books_from_http method when the specified element cannot be found in the tag object returned from get_soup_for_bible_ref """ # GIVEN: An instance of BSExtract, and reset log, urllib, get_soup_for_bible_ref & soup mocks instance = BSExtract() self.mock_log.reset_mock() self.mock_urllib.reset_mock() self.mock_get_soup_for_bible_ref.reset_mock() self.mock_soup.reset_mock() # WHEN: get_books_from_http is called with 'NIV', get_soup_for_bible_ref returns a mocked_soup object and # mocked_soup.find returns None self.mock_urllib.parse.quote.return_value = 'NIV' self.mock_soup.find.return_value = None self.mock_get_soup_for_bible_ref.return_value = self.mock_soup result = instance.get_books_from_http('NIV') # THEN: The rest mocks should be called with known values and get_books_from_http should return None self.mock_log.debug.assert_called_once_with( 'BSExtract.get_books_from_http("%s")', 'NIV') self.mock_urllib.parse.quote.assert_called_once_with(b'NIV') self.mock_get_soup_for_bible_ref.assert_called_once_with( 'http://m.bibleserver.com/overlay/selectBook?translation=NIV') self.mock_soup.find.assert_called_once_with('ul') self.mock_log.error.assert_called_once_with( 'No books found in the Bibleserver response.') self.mock_send_error_message.assert_called_once_with('parse') self.assertIsNone( result, 'BSExtract.get_books_from_http should return None when get_soup_for_bible_ref returns a ' 'false value')
def get_books_from_http_content_test(self): """ Test the get_books_from_http method with sample HTML Also a regression test for bug #1184869. (The anchor tag in the second list item is empty) """ # GIVEN: An instance of BSExtract, and reset log, urllib & get_soup_for_bible_ref mocks and sample HTML data self.test_html = '<ul><li><a href="/overlay/selectChapter?tocBook=1">Genesis</a></li>' \ '<li><a href="/overlay/selectChapter?tocBook=2"></a></li>' \ '<li><a href="/overlay/selectChapter?tocBook=3">Leviticus</a></li></ul>' self.test_soup = BeautifulSoup(self.test_html) instance = BSExtract() self.mock_log.reset_mock() self.mock_urllib.reset_mock() self.mock_get_soup_for_bible_ref.reset_mock() self.mock_send_error_message.reset_mock() # WHEN: get_books_from_http is called with 'NIV' and get_soup_for_bible_ref returns tag object based on the # supplied test data. self.mock_urllib.parse.quote.return_value = 'NIV' self.mock_get_soup_for_bible_ref.return_value = self.test_soup result = instance.get_books_from_http('NIV') # THEN: The rest mocks should be called with known values and get_books_from_http should return the two books # in the test data self.mock_log.debug.assert_called_once_with('BSExtract.get_books_from_http("%s")', 'NIV') self.mock_urllib.parse.quote.assert_called_once_with(b'NIV') self.mock_get_soup_for_bible_ref.assert_called_once_with( 'http://m.bibleserver.com/overlay/selectBook?translation=NIV') self.assertFalse(self.mock_log.error.called, 'log.error should not have been called') self.assertFalse(self.mock_send_error_message.called, 'send_error_message should not have been called') self.assertEqual(result, ['Genesis', 'Leviticus'])
def get_books_from_http_no_content_test(self): """ Test the get_books_from_http method when the specified element cannot be found in the tag object returned from get_soup_for_bible_ref """ # GIVEN: An instance of BSExtract, and reset log, urllib, get_soup_for_bible_ref & soup mocks instance = BSExtract() self.mock_log.reset_mock() self.mock_urllib.reset_mock() self.mock_get_soup_for_bible_ref.reset_mock() self.mock_soup.reset_mock() # WHEN: get_books_from_http is called with 'NIV', get_soup_for_bible_ref returns a mocked_soup object and # mocked_soup.find returns None self.mock_urllib.parse.quote.return_value = 'NIV' self.mock_soup.find.return_value = None self.mock_get_soup_for_bible_ref.return_value = self.mock_soup result = instance.get_books_from_http('NIV') # THEN: The rest mocks should be called with known values and get_books_from_http should return None self.mock_log.debug.assert_called_once_with('BSExtract.get_books_from_http("%s")', 'NIV') self.mock_urllib.parse.quote.assert_called_once_with(b'NIV') self.mock_get_soup_for_bible_ref.assert_called_once_with( 'http://m.bibleserver.com/overlay/selectBook?translation=NIV') self.mock_soup.find.assert_called_once_with('ul') self.mock_log.error.assert_called_once_with('No books found in the Bibleserver response.') self.mock_send_error_message.assert_called_once_with('parse') self.assertIsNone(result, 'BSExtract.get_books_from_http should return None when get_soup_for_bible_ref returns a ' 'false value')
def get_books_from_http_no_soup_test(self): """ Test the get_books_from_http method when get_soup_for_bible_ref returns a falsey value """ # GIVEN: An instance of BSExtract, and reset log, urllib & get_soup_for_bible_ref mocks instance = BSExtract() self.mock_log.debug.reset_mock() self.mock_urllib.reset_mock() self.mock_get_soup_for_bible_ref.reset_mock() # WHEN: get_books_from_http is called with 'NIV' and get_soup_for_bible_ref returns a None value self.mock_urllib.parse.quote.return_value = 'NIV' self.mock_get_soup_for_bible_ref.return_value = None result = instance.get_books_from_http('NIV') # THEN: The rest mocks should be called with known values and get_books_from_http should return None self.mock_log.debug.assert_called_once_with('BSExtract.get_books_from_http("%s")', 'NIV') self.mock_urllib.parse.quote.assert_called_once_with(b'NIV') self.mock_get_soup_for_bible_ref.assert_called_once_with( 'http://m.bibleserver.com/overlay/selectBook?translation=NIV') self.assertIsNone(result, 'BSExtract.get_books_from_http should return None when get_soup_for_bible_ref returns a ' 'false value')