def testGetContentTeamIdSpecifiedNoFixtures(self): page = TeamFixtures("") page.allParams = { "team": "IBMSouthHants", "xmlFile": "testData/2013-14.xml" } result = page.getContent() self.assertNotEqual(None, result)
def testGetReportContent(self): report = TeamFixturesReport() report.teamId = "IBMSouthHants" report.teamName = "IBM South Hants" report.leagueId = "Division3" report.leagueName = "Division 3" report.matches = [] match = MatchInReport() match.datetime = datetime.datetime(2013, 1, 20, 21, 15) match.opponentId = "Corinthians" match.opponentName = "Corinthians" match.court = "B" match.home = False match.result = "Lost" match.margin = "4 wickets" report.matches.append(match) match = MatchInReport() match.datetime = datetime.datetime(2012, 10, 7, 18, 15) match.opponentId = "PortsmouthB" match.opponentName = "Portsmouth B" match.court = "A" match.home = True match.result = None match.margin = None report.matches.append(match) result = TeamFixtures("").getReportContent(report) expectedResult = """ <h1>IBM South Hants (<a href="/cgi-bin/page.py?id=leagueFixtures&league=Division3">Division 3</a>)</h1> <table id="teamfix"> <thead> <tr> <th class="date">Date</th> <th class="time">Time</th> <th class="court">Court</th> <th class="opponent">Opponent</th> <th class="homeAway">H/A</th> </tr> </thead> <tbody> <tr> <td class="date">7th Oct 12</td> <td class="time">6:15</td> <td class="court">A</td> <td class="opponent"><a href="/cgi-bin/page.py?id=teamFixtures&team=PortsmouthB">Portsmouth B</a></td> <td class="homeAway">H</td> <td class="result"></td> </tr> <tr> <td class="date">20th Jan 13</td> <td class="time">9:15</td> <td class="court">B</td> <td class="opponent"><a href="/cgi-bin/page.py?id=teamFixtures&team=Corinthians">Corinthians</a></td> <td class="homeAway">A</td> <td class="result"><a href="/cgi-bin/page.py?id=leagueResults&league=Division3#CorinthiansIBMSouthHants">Lost by 4 wickets</a></td> </tr> </tbody> </table> """ self.assertMultiLineEqual(expectedResult, result)
def testGetContentNoTeamIdSpecified(self): try: TeamFixtures("").getContent() self.fail("Should have thrown an exception") except NameError: pass except: raise
def testGetMatchLineNotPlayed(self): teamId = "HavantA" leagueResLink = PageLink("leagueResults", TeamFixtures(""), {"league": "Division1"}) match = MatchInReport() match.opponentId = "FarehamCroftonB" match.opponentName = "Fareham & Crofton B" match.datetime = datetime.datetime(2012, 9, 30, 18, 15) match.court = "B" match.home = True match.result = None match.margin = None result = TeamFixtures("").getMatchLine(match, teamId, leagueResLink) expectedResult = """ <tr> <td class="date">30th Sep 12</td> <td class="time">6:15</td> <td class="court">B</td> <td class="opponent"><a href="/cgi-bin/page.py?id=teamFixtures&team=FarehamCroftonB">Fareham & Crofton B</a></td> <td class="homeAway">H</td> <td class="result"></td> </tr> """ self.assertMultiLineEqual(expectedResult, result)
def testGetContentTeamIdSpecified(self): page = TeamFixtures("") page.allParams = { "team": "IBMSouthHants", "xmlFile": "testData/2012-13.xml" } result = page.getContent() expectedResult = """ <h1>IBM South Hants (<a href="/cgi-bin/page.py?id=leagueFixtures&league=Division3">Division 3</a>)</h1> <table id="teamfix"> <thead> <tr> <th class="date">Date</th> <th class="time">Time</th> <th class="court">Court</th> <th class="opponent">Opponent</th> <th class="homeAway">H/A</th> </tr> </thead> <tbody> <tr> <td class="date">7th Oct 12</td> <td class="time">8:15</td> <td class="court">A</td> <td class="opponent"><a href="/cgi-bin/page.py?id=teamFixtures&team=PortsmouthB">Portsmouth B</a></td> <td class="homeAway">H</td> <td class="result"><a href="/cgi-bin/page.py?id=leagueResults&league=Division3#IBMSouthHantsPortsmouthB">Lost by 2 wickets</a></td> </tr> <tr> <td class="date">28th Oct 12</td> <td class="time">7:15</td> <td class="court">A</td> <td class="opponent"><a href="/cgi-bin/page.py?id=teamFixtures&team=FarehamCroftonC">Fareham & Crofton C</a></td> <td class="homeAway">A</td> <td class="result"><a href="/cgi-bin/page.py?id=leagueResults&league=Division3#FarehamCroftonCIBMSouthHants">Won by 5 wickets</a></td> </tr> <tr> <td class="date">18th Nov 12</td> <td class="time">8:15</td> <td class="court">A</td> <td class="opponent"><a href="/cgi-bin/page.py?id=teamFixtures&team=PortsmouthPriory">Portsmouth Priory</a></td> <td class="homeAway">H</td> <td class="result"><a href="/cgi-bin/page.py?id=leagueResults&league=Division3#IBMSouthHantsPortsmouthPriory">Won by 31 runs</a></td> </tr> <tr> <td class="date">2nd Dec 12</td> <td class="time">9:15</td> <td class="court">B</td> <td class="opponent"><a href="/cgi-bin/page.py?id=teamFixtures&team=WaterloovilleB">Waterlooville B</a></td> <td class="homeAway">A</td> <td class="result"><a href="/cgi-bin/page.py?id=leagueResults&league=Division3#WaterloovilleBIBMSouthHants">Lost by 37 runs</a></td> </tr> <tr> <td class="date">16th Dec 12</td> <td class="time">5:15</td> <td class="court">B</td> <td class="opponent"><a href="/cgi-bin/page.py?id=teamFixtures&team=Petersfield">Petersfield</a></td> <td class="homeAway">H</td> <td class="result"><a href="/cgi-bin/page.py?id=leagueResults&league=Division3#IBMSouthHantsPetersfield">Won by 24 runs</a></td> </tr> <tr> <td class="date">6th Jan 13</td> <td class="time">8:15</td> <td class="court">B</td> <td class="opponent"><a href="/cgi-bin/page.py?id=teamFixtures&team=Emsworth">Emsworth</a></td> <td class="homeAway">A</td> <td class="result"><a href="/cgi-bin/page.py?id=leagueResults&league=Division3#EmsworthIBMSouthHants">Won by 18 runs</a></td> </tr> <tr> <td class="date">20th Jan 13</td> <td class="time">9:15</td> <td class="court">B</td> <td class="opponent"><a href="/cgi-bin/page.py?id=teamFixtures&team=Corinthians">Corinthians</a></td> <td class="homeAway">A</td> <td class="result"><a href="/cgi-bin/page.py?id=leagueResults&league=Division3#CorinthiansIBMSouthHants">Lost by 4 wickets</a></td> </tr> <tr> <td class="date">10th Feb 13</td> <td class="time">6:15</td> <td class="court">B</td> <td class="opponent"><a href="/cgi-bin/page.py?id=teamFixtures&team=BedhamptonB">Bedhampton B</a></td> <td class="homeAway">H</td> <td class="result"><a href="/cgi-bin/page.py?id=leagueResults&league=Division3#IBMSouthHantsBedhamptonB">Won by 34 runs</a></td> </tr> <tr> <td class="date">10th Mar 13</td> <td class="time">9:15</td> <td class="court">A</td> <td class="opponent"><a href="/cgi-bin/page.py?id=teamFixtures&team=Denmead">Denmead</a></td> <td class="homeAway">A</td> <td class="result"><a href="/cgi-bin/page.py?id=leagueResults&league=Division3#DenmeadIBMSouthHants">Won by 1 wicket</a></td> </tr> </tbody> </table> """ self.assertMultiLineEqual(expectedResult, result)
class PageList: ''' classdocs ''' defaultPage = "home" pageList = [] pageList.append(HomePage("home")) pageList.append( StaticPage("notfound", "{0}/notfound.html".format(Settings.staticHtmlDirectory), "Page not found!")) pageList.append(UserAdmin("userAdmin", role="admin")) pageList.append(PartialContacts("contacts")) pageList.append(FullContacts("fullContacts", role="")) pageList.append( StaticPage( "presentation", "{0}/PresentationEvening.html".format( Settings.staticHtmlDirectory), "SEHICL Presentation Evening")) pageList.append(TeamFixtures("teamFixtures")) pageList.append(LeagueFixtures("allFixtures")) pageList.append(LeagueFixtures("leagueFixtures")) pageList.append(LeagueResults("leagueResults")) pageList.append(DateResults("latestResults")) pageList.append(DateResults("dateResults")) pageList.append(LeagueTable("tables")) pageList.append(LeagueTable("leagueTable")) pageList.append(AveragesIndex("averagesIndex")) pageList.append(BattingAverages("battingAverages")) pageList.append(BowlingAverages("bowlingAverages")) pageList.append(BattingAverages("leagueBattingAverages")) pageList.append(BowlingAverages("leagueBowlingAverages")) pageList.append(TeamAverages("teamAverages")) pageList.append(TeamAveragesIndex("teamAveragesIndex")) pageList.append( StaticPage("rules", "{0}/rules.html".format(Settings.staticHtmlDirectory), "SEHICL Rules and Playing Conditions")) pageList.append(DutyRota("fixturesDutyRota")) pageList.append( StaticPage("resources", "{0}/resources.html".format(Settings.staticHtmlDirectory), "SEHICL Resources")) pageList.append( RecordsIndex( "records", "{0}/records/recordsindex.html".format( Settings.staticHtmlDirectory))) pageList.append( StaticPage( "recordsPerformances", "{0}/records/recordperformances.html".format( Settings.staticHtmlDirectory), "SEHICL Records: Record Performances")) pageList.append( StaticPage( "recordsWinners", "{0}/records/divwinners.html".format(Settings.staticHtmlDirectory), "SEHICL Honours Board: Divisional Winners")) pageList.append( StaticPage( "recordsAwards", "{0}/records/individualawards.html".format( Settings.staticHtmlDirectory), "SEHICL Honours Board: Individual Awards")) pageList.append( StaticPage( "recordsFairplay", "{0}/records/fairplay.html".format(Settings.staticHtmlDirectory), "SEHICL Honours Board: Sporting and Efficiency")) lastArchiveSeason = 15 pageList.append(ArchiveIndex("archive", lastArchiveSeason)) additionalPromotions = {} additionalPromotions[6] = {"Division3": [3], "Division4": [3]} additionalPromotions[7] = {"Division3": [3, 4], "Division4": [3, 4]} additionalPromotions[10] = {"Division4": [4]} additionalPromotions[12] = {"Division4": [3, 4]} additionalPromotions[13] = {"Division3": [3], "Division4": [3]} additionalPromotions[14] = { "Division2": [3], "Division3": [3], "Division4": [3, 4] } additionalPromotions[15] = {"Division4": [3]} for s in range(4, lastArchiveSeason + 1): index = ArchiveSeasonIndex("archive{0}".format(s)) title = index.getTitle() pageList.append(index) for divName in ("Division 1", "Division 2", "Division 3", "Division 4", "Colts Under-16", "Colts Under-13"): divId = re.sub("[ -]", "", divName) pageId = "archive{0}{1}Table".format(s, divId) if s < 6: pageFile = "{2}/archive{0}/{1}.html".format( s, divId, Settings.staticHtmlDirectory) pageList.append(StaticPage(pageId, pageFile, title)) else: params = {"season": s, "league": divId, "archive": "yes"} ap = additionalPromotions.get(s, {}).get(divId, None) if ap is not None: params["additionalPromotions"] = ap pageList.append(LeagueTable(pageId, params)) for section in ("Senior", "Colts Under-16", "Colts Under-13"): for activity in ("Batting", "Bowling"): sectionId = re.sub("[ -]", "", section) pageId = "archive{0}{1}{2}".format(s, sectionId, activity) if s < 6: pageFile = "{3}/archive{0}/{1}{2}.html".format( s, sectionId, activity, Settings.staticHtmlDirectory) pageList.append(StaticPage(pageId, pageFile, title)) else: parms = {"season": s, "archive": "yes"} if (sectionId != "Senior"): parms["league"] = sectionId if activity == "Batting": pageList.append(BattingAverages(pageId, parms)) else: pageList.append(BowlingAverages(pageId, parms)) if index.presentation: pageId = "archive{0}Presentation".format(s) pageFile = "{0}/archive{1}/PresentationEvening.html".format( Settings.staticHtmlDirectory, s) pageList.append(StaticPage(pageId, pageFile, title)) pageList.append(UserRegistration("register")) pageList.append(UserActivation("activate")) pageList.append(UserLogin("login")) pages = {} for p in pageList: pages[p.pageId] = p
def testGetContentTeamIdSpecifiedNoFixtures(self): page = TeamFixtures("") page.allParams = {"team": "IBMSouthHants", "xmlFile": "testData/2013-14.xml"} result = page.getContent() self.assertNotEqual(None, result)
def testGetContentTeamIdSpecified(self): page = TeamFixtures("") page.allParams = {"team": "IBMSouthHants", "xmlFile": "testData/2012-13.xml"} result = page.getContent() expectedResult = """ <h1>IBM South Hants (<a href="/cgi-bin/page.py?id=leagueFixtures&league=Division3">Division 3</a>)</h1> <table id="teamfix"> <thead> <tr> <th class="date">Date</th> <th class="time">Time</th> <th class="court">Court</th> <th class="opponent">Opponent</th> <th class="homeAway">H/A</th> </tr> </thead> <tbody> <tr> <td class="date">7th Oct 12</td> <td class="time">8:15</td> <td class="court">A</td> <td class="opponent"><a href="/cgi-bin/page.py?id=teamFixtures&team=PortsmouthB">Portsmouth B</a></td> <td class="homeAway">H</td> <td class="result"><a href="/cgi-bin/page.py?id=leagueResults&league=Division3#IBMSouthHantsPortsmouthB">Lost by 2 wickets</a></td> </tr> <tr> <td class="date">28th Oct 12</td> <td class="time">7:15</td> <td class="court">A</td> <td class="opponent"><a href="/cgi-bin/page.py?id=teamFixtures&team=FarehamCroftonC">Fareham & Crofton C</a></td> <td class="homeAway">A</td> <td class="result"><a href="/cgi-bin/page.py?id=leagueResults&league=Division3#FarehamCroftonCIBMSouthHants">Won by 5 wickets</a></td> </tr> <tr> <td class="date">18th Nov 12</td> <td class="time">8:15</td> <td class="court">A</td> <td class="opponent"><a href="/cgi-bin/page.py?id=teamFixtures&team=PortsmouthPriory">Portsmouth Priory</a></td> <td class="homeAway">H</td> <td class="result"><a href="/cgi-bin/page.py?id=leagueResults&league=Division3#IBMSouthHantsPortsmouthPriory">Won by 31 runs</a></td> </tr> <tr> <td class="date">2nd Dec 12</td> <td class="time">9:15</td> <td class="court">B</td> <td class="opponent"><a href="/cgi-bin/page.py?id=teamFixtures&team=WaterloovilleB">Waterlooville B</a></td> <td class="homeAway">A</td> <td class="result"><a href="/cgi-bin/page.py?id=leagueResults&league=Division3#WaterloovilleBIBMSouthHants">Lost by 37 runs</a></td> </tr> <tr> <td class="date">16th Dec 12</td> <td class="time">5:15</td> <td class="court">B</td> <td class="opponent"><a href="/cgi-bin/page.py?id=teamFixtures&team=Petersfield">Petersfield</a></td> <td class="homeAway">H</td> <td class="result"><a href="/cgi-bin/page.py?id=leagueResults&league=Division3#IBMSouthHantsPetersfield">Won by 24 runs</a></td> </tr> <tr> <td class="date">6th Jan 13</td> <td class="time">8:15</td> <td class="court">B</td> <td class="opponent"><a href="/cgi-bin/page.py?id=teamFixtures&team=Emsworth">Emsworth</a></td> <td class="homeAway">A</td> <td class="result"><a href="/cgi-bin/page.py?id=leagueResults&league=Division3#EmsworthIBMSouthHants">Won by 18 runs</a></td> </tr> <tr> <td class="date">20th Jan 13</td> <td class="time">9:15</td> <td class="court">B</td> <td class="opponent"><a href="/cgi-bin/page.py?id=teamFixtures&team=Corinthians">Corinthians</a></td> <td class="homeAway">A</td> <td class="result"><a href="/cgi-bin/page.py?id=leagueResults&league=Division3#CorinthiansIBMSouthHants">Lost by 4 wickets</a></td> </tr> <tr> <td class="date">10th Feb 13</td> <td class="time">6:15</td> <td class="court">B</td> <td class="opponent"><a href="/cgi-bin/page.py?id=teamFixtures&team=BedhamptonB">Bedhampton B</a></td> <td class="homeAway">H</td> <td class="result"><a href="/cgi-bin/page.py?id=leagueResults&league=Division3#IBMSouthHantsBedhamptonB">Won by 34 runs</a></td> </tr> <tr> <td class="date">10th Mar 13</td> <td class="time">9:15</td> <td class="court">A</td> <td class="opponent"><a href="/cgi-bin/page.py?id=teamFixtures&team=Denmead">Denmead</a></td> <td class="homeAway">A</td> <td class="result"><a href="/cgi-bin/page.py?id=leagueResults&league=Division3#DenmeadIBMSouthHants">Won by 1 wicket</a></td> </tr> </tbody> </table> """ self.assertMultiLineEqual(expectedResult, result)