def testSetWinLossInfoGamePlayedPlayedAndWonByMoreThan1Run(self): xml = """ <match> <homeTeam id="HavantA"/> <awayTeam id="HavantB"/> <playedMatch> <teamInMatch> <battingFirst>true</battingFirst> <teamRef id="HavantA"/> <innings> <runsScored>114</runsScored> </innings> </teamInMatch> <teamInMatch> <battingFirst>false</battingFirst> <teamRef id="HavantB"/> <innings> <runsScored>112</runsScored> </innings> </teamInMatch> </playedMatch> </match> """ teamId = "HavantA" generator = TeamFixturesReportGenerator() matchElement = ElementTree.fromstring(xml) match = MatchInReport() match.result = None match.margin = None result = generator.setWinLossInfoGamePlayed(teamId, matchElement, match) self.assertTrue(result) self.assertEquals("Won", match.result) self.assertEquals("2 runs", match.margin)
def testSetWinLossInfoGamePlayed(self): xml = """ <match> <homeTeam id="HavantA"/> <awayTeam id="HavantB"/> <playedMatch> <teamInMatch> <battingFirst>false</battingFirst> <teamRef id="HavantA"/> <innings> <runsScored>104</runsScored> <wicketsLost>4</wicketsLost> </innings> </teamInMatch> <teamInMatch> <battingFirst>true</battingFirst> <teamRef id="HavantB"/> <innings> <runsScored>112</runsScored> </innings> </teamInMatch> </playedMatch> </match> """ matchElement = ElementTree.fromstring(xml) teamId = "HavantA" generator = TeamFixturesReportGenerator() match = MatchInReport() match.result = None match.margin = None generator.setWinLossInfo(teamId, matchElement, match) self.assertEquals("Lost", match.result) self.assertEquals("8 runs", match.margin)
def testSetWinLossInfoGamePlayed(self): xml = """ <match> <homeTeam id="HavantA"/> <awayTeam id="HavantB"/> <playedMatch> <teamInMatch> <battingFirst>false</battingFirst> <teamRef id="HavantA"/> <innings> <runsScored>104</runsScored> <wicketsLost>4</wicketsLost> </innings> </teamInMatch> <teamInMatch> <battingFirst>true</battingFirst> <teamRef id="HavantB"/> <innings> <runsScored>112</runsScored> </innings> </teamInMatch> </playedMatch> </match> """ matchElement = ElementTree.fromstring(xml) teamId = "HavantA" generator = TeamFixturesReportGenerator() match = MatchInReport() match.result = None match.margin = None generator.setWinLossInfo(teamId, matchElement, match); self.assertEquals("Lost", match.result) self.assertEquals("8 runs", match.margin)
def testSetWinLossInfoGamePlayedPlayedAndLostByMoreThan1Run(self): xml = """ <match> <homeTeam id="HavantA"/> <awayTeam id="HavantB"/> <playedMatch> <teamInMatch> <battingFirst>false</battingFirst> <teamRef id="HavantA"/> <innings> <runsScored>114</runsScored> </innings> </teamInMatch> <teamInMatch> <battingFirst>true</battingFirst> <teamRef id="HavantB"/> <innings> <runsScored>116</runsScored> </innings> </teamInMatch> </playedMatch> </match> """ teamId = "HavantA" generator = TeamFixturesReportGenerator() matchElement = ElementTree.fromstring(xml) match = MatchInReport() match.result = None match.margin = None result = generator.setWinLossInfoGamePlayed(teamId, matchElement, match) self.assertTrue(result) self.assertEquals("Lost", match.result) self.assertEquals("2 runs", match.margin)
def testSetWinLossInfoGameNotPlayedOrAwarded(self): xml = """ <match/> """ matchElement = ElementTree.fromstring(xml) teamId = "HavantA" generator = TeamFixturesReportGenerator() match = MatchInReport() match.result = None match.margin = None generator.setWinLossInfo(teamId, matchElement, match) self.assertEquals(None, match.result) self.assertEquals(None, match.margin)
def testSetWinLossInfoGameNotPlayedOrAwarded(self): xml = """ <match/> """ matchElement = ElementTree.fromstring(xml) teamId = "HavantA" generator = TeamFixturesReportGenerator() match = MatchInReport() match.result = None match.margin = None generator.setWinLossInfo(teamId, matchElement, match); self.assertEquals(None, match.result) self.assertEquals(None, match.margin)
def testSetWinLossInfoGameAwarded(self): xml = """ <match> <awardedMatch> <winner id="HavantB"/> </awardedMatch> </match> """ matchElement = ElementTree.fromstring(xml) teamId = "HavantA" generator = TeamFixturesReportGenerator() match = MatchInReport() match.result = None match.margin = None generator.setWinLossInfo(teamId, matchElement, match) self.assertEquals("Lost", match.result) self.assertEquals("default", match.margin)
def testSetWinLossInfoGameAwarded(self): xml = """ <match> <awardedMatch> <winner id="HavantB"/> </awardedMatch> </match> """ matchElement = ElementTree.fromstring(xml) teamId = "HavantA" generator = TeamFixturesReportGenerator() match = MatchInReport() match.result = None match.margin = None generator.setWinLossInfo(teamId, matchElement, match); self.assertEquals("Lost", match.result) self.assertEquals("default", match.margin)
def testSetWinLossInfoGamePlayedNotPlayedOrAwarded(self): xml = """ <match> <homeTeam id="HavantA"/> <awayTeam id="HavantB"/> </match> """ teamId = "HavantA" generator = TeamFixturesReportGenerator() matchElement = ElementTree.fromstring(xml) match = MatchInReport() match.result = None match.margin = None result = generator.setWinLossInfoGamePlayed(teamId, matchElement, match) self.assertFalse(result) self.assertEquals(None, match.result) self.assertEquals(None, match.margin)
def testSetOpponentInfoTeamIsAway(self): xml = """ <match> <awayTeam id="IBMSouthHants"/> <homeTeam id="PortsmouthB"/> </match> """ teamId = "IBMSouthHants" generator = TeamFixturesReportGenerator() matchElement = ElementTree.fromstring(xml) match = MatchInReport() teams = {"PortsmouthB": "Portsmouth B"} generator.setOpponentInfo(teamId, matchElement, match, teams) self.assertFalse(match.home) self.assertEqual("PortsmouthB", match.opponentId) self.assertEqual("Portsmouth B", match.opponentName)
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 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)