Make bible text parsing a bit more rebust, fixes bug 1404865.

Fixes: https://launchpad.net/bugs/1404865
This commit is contained in:
Tomas Groth 2014-12-23 22:09:34 +00:00
parent 35de35103b
commit 795977b094
2 changed files with 15 additions and 2 deletions

View File

@ -93,10 +93,10 @@ class BGExtract(RegistryProperties):
"""
if isinstance(tag, NavigableString):
return None, str(tag)
elif tag.get('class')[0] == "versenum" or tag.get('class')[0] == 'versenum mid-line':
elif tag.get('class') and (tag.get('class')[0] == 'versenum' or tag.get('class')[0] == 'versenum mid-line'):
verse = str(tag.string).replace('[', '').replace(']', '').strip()
return verse, None
elif tag.get('class')[0] == 'chapternum':
elif tag.get('class') and tag.get('class')[0] == 'chapternum':
verse = '1'
return verse, None
else:

View File

@ -85,6 +85,19 @@ class TestBibleHTTP(TestCase):
# THEN: We should get back a valid service item
assert len(results.verse_list) == 36, 'The book of John should not have had any verses added or removed'
def bible_gateway_extract_verse_nkjv_test(self):
"""
Test the Bible Gateway retrieval of verse list for NKJV bible John 3
"""
# GIVEN: A new Bible Gateway extraction class
handler = BGExtract()
# WHEN: The Books list is called
results = handler.get_bible_chapter('NKJV', 'John', 3)
# THEN: We should get back a valid service item
assert len(results.verse_list) == 36, 'The book of John should not have had any verses added or removed'
def crosswalk_extract_books_test(self):
"""
Test Crosswalk retrieval of book list for NIV bible