def testContainsSelectedItemIsNotSelectedAndHasAnIdThatDoesNotMatchPageAndHasAMatchingItem(self): items = [NavigatorItem(pageId="asfsdf"), NavigatorItem(pageId="aaaaa"), NavigatorItem("hello")] item = NavigatorItem(itemId="fixtures", pageId="sagsd", params={"text": "bonjour"}, items=items) page = self.getPage("hello", {"param": "param", "text": "bonjour"}) result = item.containsSelected(page) expectedResult = True self.assertEqual(expectedResult, result)
def testContainsSelectedItemIsNotSelectedAndHasNoIdAndHasNoMatchingItems(self): items = [NavigatorItem(pageId="asfsdf"), NavigatorItem(pageId="aaaaa")] item = NavigatorItem(pageId="sagsd", params={"text": "bonjour"}, items=items) page = self.getPage("hello", {"param": "param", "text": "bonjour"}) result = item.containsSelected(page) expectedResult = False self.assertEqual(expectedResult, result)
def testGetHtmlItemHasContainedItemsIncludesSelected(self): subSubItem = NavigatorItem(pageId="asdgasgsa", text="Sub-sub-item") subItems = [] subItems.append(NavigatorItem(pageId="aasaassasa", text="Sub-item 1", items=[subSubItem])) subItems.append(NavigatorItem(pageId="asasdasfa", text="Sub-item 2")) item = NavigatorItem(pageId="hello", text="Hello", params={"hello": 0}, items=subItems) page = self.getPage("asdgasgsa", {"session": "12412"}) result = item.getHtml(page) expectedResult = """ <li> <a href="/cgi-bin/page.py?id=hello&session=12412&hello=0">Hello</a> <ul id="currentMenu"> <li> <a href="/cgi-bin/page.py?id=aasaassasa&session=12412">Sub-item 1</a> <ul id="currentMenu"> <li> <span class="current">Sub-sub-item</span> </li> </ul> </li> <li> <a href="/cgi-bin/page.py?id=asasdasfa&session=12412">Sub-item 2</a> </li> </ul> </li> """ self.assertMultiLineEqual(expectedResult, result)
def testIsSelectedItemHasPageIdAndParamsPageHasSameIdAndDifferentParams( self): item = NavigatorItem(pageId="hello", params={"text": "bonjour"}) page = self.getPage("hello", {"param": "param"}) result = item.isSelected(page) expectedResult = False self.assertEqual(expectedResult, result)
def testGetItemLinkItemIsNotCurrentWithSession(self): item = NavigatorItem(pageId="hello", text="Home", params={"hello": 0}) page = self.getPage("goodbye", {"session": 53436}) result = item.getItemLink(page) expectedResult = """ <a href="/cgi-bin/page.py?id=hello&session=53436&hello=0">Home</a> """ self.assertMultiLineEqual(expectedResult, result)
def testGetItemLinkItemIsNotCurrentNoSession(self): item = NavigatorItem(pageId="hello", text="Home") page = self.getPage("goodbye") result = item.getItemLink(page) expectedResult = """ <a href="/cgi-bin/page.py?id=hello">Home</a> """ self.assertMultiLineEqual(expectedResult, result)
def testGetItemLinkItemIsCurrent(self): item = NavigatorItem(pageId="hello", text="Home") page = self.getPage("hello") result = item.getItemLink(page) expectedResult = """ <span class="current">Home</span> """ self.assertMultiLineEqual(expectedResult, result)
def testGetItemLinkItemIsNotCurrentUrlIsSpecified(self): item = NavigatorItem(url="http://sehicl.org.uk", text="Home") page = self.getPage("goodbye", {"session": 53436}) result = item.getItemLink(page) expectedResult = """ <a href="http://sehicl.org.uk" target="_blank">Home</a> """ self.assertMultiLineEqual(expectedResult, result)
def testContainsSelectedItemIsNotSelectedAndHasAnIdThatDoesNotMatchPageAndHasNoItems( self): item = NavigatorItem(itemId="fixtures", pageId="sagsd", params={"text": "bonjour"}) page = self.getPage("hello", {"param": "param", "text": "bonjour"}) result = item.containsSelected(page) expectedResult = False self.assertEqual(expectedResult, result)
def testGetHtmlItemIsCurrentHasNoContainedItems(self): item = NavigatorItem(pageId="hello", text="Hello", params={"hello": 0}) page = self.getPage("hello", {"hello": 0}) result = item.getHtml(page) expectedResult = """ <li> <span class="current">Hello</span> </li> """ self.assertMultiLineEqual(expectedResult, result)
def testGetHtmlItemIsNotCurrentHasNoContainedItemsNoSession(self): item = NavigatorItem(pageId="hello", text="Hello", params={"hello": 0}) page = self.getPage("afaasfsa") result = item.getHtml(page) expectedResult = """ <li> <a href="/cgi-bin/page.py?id=hello&hello=0">Hello</a> </li> """ self.assertMultiLineEqual(expectedResult, result)
def testContainsSelectedItemIsNotSelectedAndHasNoIdAndHasNoMatchingItems( self): items = [NavigatorItem(pageId="asfsdf"), NavigatorItem(pageId="aaaaa")] item = NavigatorItem(pageId="sagsd", params={"text": "bonjour"}, items=items) page = self.getPage("hello", {"param": "param", "text": "bonjour"}) result = item.containsSelected(page) expectedResult = False self.assertEqual(expectedResult, result)
def testContainsSelectedItemIsNotSelectedAndHasAnIdThatMatchesPage(self): item = NavigatorItem(itemId="fixtures", pageId="sagsd", params={"text": "bonjour"}) page = self.getPage("leagueFixtures", { "param": "param", "text": "bonjour" }) result = item.containsSelected(page) expectedResult = True self.assertEqual(expectedResult, result)
def testGetHtmlItemHasContainedItemsIsSelected(self): subItems = [] subItems.append(NavigatorItem(pageId="aasda", text="Item1")) subItems.append(NavigatorItem(pageId="aadsgasgas", text="Item2")) item = NavigatorItem(pageId="aadgas", text="Hello", params={"hello": 0}, items=subItems) page = self.getPage("aadgas", params={"hello": 0, "session": "12412"}) result = item.getHtml(page) expectedResult = """ <li> <span class="current">Hello</span> <ul id="currentMenu"> <li> <a href="/cgi-bin/page.py?id=aasda&session=12412">Item1</a> </li> <li> <a href="/cgi-bin/page.py?id=aadsgasgas&session=12412">Item2</a> </li> </ul> </li> """ self.assertMultiLineEqual(expectedResult, result)
def testGetHtmlItemHasContainedItemsIncludesSelected(self): subSubItem = NavigatorItem(pageId="asdgasgsa", text="Sub-sub-item") subItems = [] subItems.append( NavigatorItem(pageId="aasaassasa", text="Sub-item 1", items=[subSubItem])) subItems.append(NavigatorItem(pageId="asasdasfa", text="Sub-item 2")) item = NavigatorItem(pageId="hello", text="Hello", params={"hello": 0}, items=subItems) page = self.getPage("asdgasgsa", {"session": "12412"}) result = item.getHtml(page) expectedResult = """ <li> <a href="/cgi-bin/page.py?id=hello&session=12412&hello=0">Hello</a> <ul id="currentMenu"> <li> <a href="/cgi-bin/page.py?id=aasaassasa&session=12412">Sub-item 1</a> <ul id="currentMenu"> <li> <span class="current">Sub-sub-item</span> </li> </ul> </li> <li> <a href="/cgi-bin/page.py?id=asasdasfa&session=12412">Sub-item 2</a> </li> </ul> </li> """ self.assertMultiLineEqual(expectedResult, result)
def testContainsSelectedItemIsNotSelectedAndHasAnIdThatDoesNotMatchPageAndHasAMatchingItem( self): items = [ NavigatorItem(pageId="asfsdf"), NavigatorItem(pageId="aaaaa"), NavigatorItem("hello") ] item = NavigatorItem(itemId="fixtures", pageId="sagsd", params={"text": "bonjour"}, items=items) page = self.getPage("hello", {"param": "param", "text": "bonjour"}) result = item.containsSelected(page) expectedResult = True self.assertEqual(expectedResult, result)
def getItem(self, itemElement): itemId = itemElement.get("id", None) pageId = itemElement.get("pageId", None) text = itemElement.text if text is not None: text = strip(text) if text == "": text = None url = itemElement.get("url") params = {} for k in itemElement.keys(): if k not in ("pageId", "url", "id"): params[k] = itemElement.get(k) items = self.getItems(itemElement) answer = NavigatorItem(itemId=itemId, pageId=pageId, params=params, text=text, items=items, url=url) return answer
def testIsSelectedItemHasPageIdAndParamsPageHasNoIdNoParams(self): item = NavigatorItem(pageId="hello", params={"text": "bonjour"}) page = self.getPage(None) result = item.isSelected(page) expectedResult = False self.assertEqual(expectedResult, result)
def testIsSelectedItemHasNoPageIdNoParamsPageHasIdAndParams(self): item = NavigatorItem(url="http://sehicl.org.uk") page = self.getPage("hello", {"param": "param"}) result = item.isSelected(page) expectedResult = False self.assertEqual(expectedResult, result)
def testContainsSelectedItemIsNotSelectedAndHasAnIdThatMatchesPage(self): item = NavigatorItem(itemId="fixtures", pageId="sagsd", params={"text": "bonjour"}) page = self.getPage("leagueFixtures", {"param": "param", "text": "bonjour"}) result = item.containsSelected(page) expectedResult = True self.assertEqual(expectedResult, result)
def testContainsSelectedItemIsNotSelectedAndHasAnIdThatDoesNotMatchPageAndHasNoItems(self): item = NavigatorItem(itemId="fixtures", pageId="sagsd", params={"text": "bonjour"}) page = self.getPage("hello", {"param": "param", "text": "bonjour"}) result = item.containsSelected(page) expectedResult = False self.assertEqual(expectedResult, result)
def testIsSelectedItemHasPageIdNoParamsPageHasSameIdNoParams(self): item = NavigatorItem(pageId="hello") page = self.getPage("hello") result = item.isSelected(page) expectedResult = True self.assertEqual(expectedResult, result)
def testIsSelectedItemHasPageIdAndParamsPageHasNoIdAndParams(self): item = NavigatorItem(pageId="hello", params={"text": "bonjour"}) page = self.getPage(None, {"param": "param"}) result = item.isSelected(page) expectedResult = False self.assertEqual(expectedResult, result)
def testContainsSelectedItemIsSelected(self): item = NavigatorItem(pageId="hello", params={"text": "bonjour"}) page = self.getPage("hello", {"param": "param", "text": "bonjour"}) result = item.containsSelected(page) expectedResult = True self.assertEqual(expectedResult, result)
def testIsSelectedItemHasPageIdNoParamsPageHasDifferentIdAndParams(self): item = NavigatorItem(pageId="hello") page = self.getPage("hej", {"param": "param"}) result = item.isSelected(page) expectedResult = False self.assertEqual(expectedResult, result)
def testIsSelectedItemHasPageIdAndParamsPageHasSameIdAndExtraParams(self): item = NavigatorItem(pageId="hello", params={"text": "bonjour"}) page = self.getPage("hello", {"param": "param", "text": "bonjour"}) result = item.isSelected(page) expectedResult = True self.assertEqual(expectedResult, result)