def _load_topic_children(topic): from passage_list import PassageList from passage_entry import PassageEntry child_query = "select %s from %s where parent = ? order by order_number" subtopics = [] fields = ", ".join('"%s"' % name for name in ["id",] + PassageList.__fields_to_store__) for row in connection.execute(child_query % (fields, "topic"), (topic.id,)): subtopic = PassageList("") _load_record(subtopic, row) subtopic.parent = topic _load_topic_children(subtopic) subtopics.append(subtopic) topic.subtopics = subtopics fields = ", ".join(["id",] + PassageEntry.__fields_to_store__) passages = [] for row in connection.execute(child_query % (fields, "passage"), (topic.id,)): passage = PassageEntry(None) passage.parent = topic _load_record(passage, row) passage.parent = topic passages.append(passage) topic.passages = passages
class TestPassageEntry(unittest.TestCase): def setUp(self): self._passage_entry = PassageEntry("gen 2:2") self._passage_entry2 = PassageEntry("gen 3:5 - 10") def testConstructorShouldCreateEmptyComment(self): self.assertEqual(self._passage_entry.comment, "") def testPassageCanBeSetFromStringInConstructor(self): passage_entry = PassageEntry("gen 2:3 - 5") self.assertEqual(str(passage_entry), "Genesis 2:3-5") def testConstructorShouldAllowSettingComment(self): self._passage_entry = PassageEntry("gen 3:2", "some comment") self.assertEqual(self._passage_entry.comment, "some comment") def testContainsVerseWorksWithSingleVerse(self): self.assert_(self._passage_entry.contains_verse(VK("gen 2:2"))) self.assert_(not self._passage_entry.contains_verse(VK("gen 2:1"))) def testContainsVerseWorksWithRange(self): self.assert_(self._passage_entry2.contains_verse(VK("gen 3:5"))) self.assert_(self._passage_entry2.contains_verse(VK("gen 3:6"))) self.assert_(self._passage_entry2.contains_verse(VK("gen 3:9"))) self.assert_(self._passage_entry2.contains_verse(VK("gen 3:10"))) self.assert_(not self._passage_entry2.contains_verse(VK("gen 3:4"))) self.assert_(not self._passage_entry2.contains_verse(VK("gen 3:11"))) def testStringMethodWorksOnVerses(self): self.assertEqual(str(self._passage_entry), "Genesis 2:2") def testStringMethodWorksOnRanges(self): self.assertEqual(str(self._passage_entry2), "Genesis 3:5-10") def testStringMethodWorksOnEmptyPassage(self): self.assertEqual(str(PassageEntry(None)), "") def testPassageCanBeSetFromString(self): self._passage_entry.passage = "exodus 4:4" self.assertEquals(str(self._passage_entry), "Exodus 4:4") def testPassageRangeCanBeSetFromString(self): self._passage_entry.passage = "exodus 4:4 - 5:7" self.assertEquals(str(self._passage_entry), "Exodus 4:4-5:7") def testPassageCannotBeSetFromInvalidString(self): self.assertRaises(InvalidPassageError, self._setPassage, "invalid reference") def testPassageCanBeSetFromStringWithMultiplePassages(self): self._setPassage("gen 3:5 - 7, 9, 11") def testPassageGlobalLookup(self): passage_entry = lookup_passage_entry(self._passage_entry.get_id()) self.assert_(passage_entry is self._passage_entry) def _setPassage(self, passage): self._passage_entry.passage = passage
def create_from_verse_list(name, verse_list, description="", comment="", display_tag=True): """Creates a passage list with the given name. verse_list: The list of verses to create the passage list from. description: The description for the passage list. comment: The comment to attach to every passage entry. display_tag: Should the tag be displayed for this topic. """ passage_list = PassageList(name, description, display_tag=display_tag) for verse in verse_list: passage_list.add_passage(PassageEntry(VerseList([verse]), comment)) return passage_list
def setUp(self): self._passage_entry = PassageEntry("gen 2:2") self._passage_entry2 = PassageEntry("gen 3:5 - 10")
def testStringMethodWorksOnEmptyPassage(self): self.assertEqual(str(PassageEntry(None)), "")
def testConstructorShouldAllowSettingComment(self): self._passage_entry = PassageEntry("gen 3:2", "some comment") self.assertEqual(self._passage_entry.comment, "some comment")
def testPassageCanBeSetFromStringInConstructor(self): passage_entry = PassageEntry("gen 2:3 - 5") self.assertEqual(str(passage_entry), "Genesis 2:3-5")
def testAddPassageShouldCallObserver(self): self._passage_list.add_passage(PassageEntry(None)) self._checkObserverHasBeenCalled()