def testGetItemNoPageTextNoParamsUrlNoSubItems(self): xml = """ <item url="aafafs">A page</item> """ element = ElementTree.fromstring(xml) result = Navigator().getItem(element) self.assertEqual(None, result.pageId) self.assertEqual("A page", result.text) self.assertEqual("aafafs", result.url) self.assertEqual({}, result.pageParams) self.assertEqual(0, len(result.items))
def testGetItemPageNoTextNoParamsUrlNoSubItems(self): xml = """ <item pageId="hello" url="aafafs"/> """ element = ElementTree.fromstring(xml) result = Navigator().getItem(element) self.assertEqual("hello", result.pageId) self.assertEqual("Hello", result.text) self.assertEqual("aafafs", result.url) self.assertEqual({}, result.pageParams) self.assertEqual(0, len(result.items))
def testGetItemNoPageNoTextNoParamsNoUrlNoSubItems(self): xml = """ <item/> """ element = ElementTree.fromstring(xml) result = Navigator().getItem(element) self.assertEqual(None, result.pageId) self.assertEqual(None, result.text) self.assertEqual(None, result.url) self.assertEqual({}, result.pageParams) self.assertEqual(0, len(result.items))
def testGetItemPageTextNoParamsNoUrlNoSubItems(self): xml = """ <item pageId="hello"> Another page </item> """ element = ElementTree.fromstring(xml) result = Navigator().getItem(element) self.assertEqual("hello", result.pageId) self.assertEqual("Another page", result.text) self.assertEqual(None, result.url) self.assertEqual({}, result.pageParams) self.assertEqual(0, len(result.items))
def testGetItemNoPageNoTextParamsUrlNoSubItems(self): xml = """ <item name="Jeremy" surname="Hicks" url="aafafs"/> """ element = ElementTree.fromstring(xml) result = Navigator().getItem(element) self.assertEqual(None, result.pageId) self.assertEqual(None, result.text) self.assertEqual("aafafs", result.url) self.assertEqual({ "name": "Jeremy", "surname": "Hicks" }, result.pageParams) self.assertEqual(0, len(result.items))
def testGetItemPageNoTextParamsNoUrlNoSubItems(self): xml = """ <item pageId="hello" name="Rachel" surname="Hicks"/> """ element = ElementTree.fromstring(xml) result = Navigator().getItem(element) self.assertEqual("hello", result.pageId) self.assertEqual("Hello", result.text) self.assertEqual(None, result.url) self.assertEqual({ "name": "Rachel", "surname": "Hicks" }, result.pageParams) self.assertEqual(0, len(result.items))
def testGetItemNoPageTextNoParamsNoUrlSubItems(self): xml = """ <item>A page <item pageId="1"/> <item pageId="2"/> <item pageId="3"/> </item> """ element = ElementTree.fromstring(xml) result = Navigator().getItem(element) self.assertEqual(None, result.pageId) self.assertEqual("A page", result.text) self.assertEqual(None, result.url) self.assertEqual({}, result.pageParams) self.assertEqual(3, len(result.items))
def testGetItemPageTextNoParamsUrlSubItems(self): xml = """ <item pageId="hello" url="aafafs"> Another page <item pageId="1"/> <item pageId="2"/> <item pageId="3"/> </item> """ element = ElementTree.fromstring(xml) result = Navigator().getItem(element) self.assertEqual("hello", result.pageId) self.assertEqual("Another page", result.text) self.assertEqual("aafafs", result.url) self.assertEqual({}, result.pageParams) self.assertEqual(3, len(result.items))
def testGetItemPageTextParamsUrlNoSubItems(self): xml = """ <item pageId="hello" name="Jeremy" surname="Hicks" url="aafafs"> Another page </item> """ element = ElementTree.fromstring(xml) result = Navigator().getItem(element) self.assertEqual("hello", result.pageId) self.assertEqual("Another page", result.text) self.assertEqual("aafafs", result.url) self.assertEqual({ "name": "Jeremy", "surname": "Hicks" }, result.pageParams) self.assertEqual(0, len(result.items))
def testGetItemPageNoTextParamsUrlSubItems(self): xml = """ <item pageId="hello" name="Rachel" surname="Hicks" url="aafafs"> <item pageId="1"/> <item pageId="2"/> <item pageId="3"/> </item> """ element = ElementTree.fromstring(xml) result = Navigator().getItem(element) self.assertEqual("hello", result.pageId) self.assertEqual("Hello", result.text) self.assertEqual("aafafs", result.url) self.assertEqual({ "name": "Rachel", "surname": "Hicks" }, result.pageParams) self.assertEqual(3, len(result.items))
def testGetItemNoPageNoTextParamsNoUrlSubItems(self): xml = """ <item name="Jeremy" surname="Hicks"> <item pageId="1"/> <item pageId="2"/> <item pageId="3"/> </item> """ element = ElementTree.fromstring(xml) result = Navigator().getItem(element) self.assertEqual(None, result.pageId) self.assertEqual(None, result.text) self.assertEqual(None, result.url) self.assertEqual({ "name": "Jeremy", "surname": "Hicks" }, result.pageParams) self.assertEqual(3, len(result.items))
def testGetHtml(self): xml = """ <navigator> <item pageId="hello" name="Jeremy" surname="Hicks" url="aafafs"> Another page <item pageId="1">Item 1</item> <item pageId="2">Item 2</item> <item pageId="3">Item 3</item> </item> <item pageId="goodbye">Goodbye</item> </navigator> """ page = self.getPage("1", {"session": 123}) result = Navigator(xml).getHtml(page) expectedResult = """ <ul class="navigator"> <li> <a href="aafafs" target="_blank">Another page</a> <ul id="currentMenu"> <li> <span class="current">Item 1</span> </li> <li> <a href="/cgi-bin/page.py?id=2&session=123">Item 2</a> </li> <li> <a href="/cgi-bin/page.py?id=3&session=123">Item 3</a> </li> </ul> </li> <li> <a href="/cgi-bin/page.py?id=goodbye&session=123">Goodbye</a> </li> </ul> """ self.assertMultiLineEqual(expectedResult, result)
def getNavigator(self): navigator = Navigator() answer = navigator.getHtml(self) return answer