def testMultTournament(): # populate with 3 players split across 2 tournaments deleteMatches() deleteTournaments() deletePlayers() populate(); standings = playerStandings() [id1, id2, id3] = [row[0] for row in standings] # verify there are 2 tournaments conn = connect() c = conn.cursor() c.execute("SELECT * FROM tournaments") tourneys = c.fetchall() if len(tourneys) != 2: raise ValueError("There should be 2 tournaments") # verify there are 2 players registered for each tournament [t1, t2] = [row[0] for row in tourneys] c.execute('''SELECT player_id FROM tournament_registrations WHERE tournament_id = (%s)''', (t1,)) players = c.fetchall() if len(players) != 2: print "players: ", players raise ValueError("There should be 2 players") c.execute('''SELECT player_id FROM tournament_registrations WHERE tournament_id = (%s)''', (t2,)) players = c.fetchall() if len(players) != 2: raise ValueError("There should be 2 players") conn.close() # verify that results are correct for all tournament and specific # tournament standings standings = playerStandings(t1) [id1, id2] = [row[0] for row in standings] for (i, n, w, m) in standings: if i in (id1,) and (w != 1 and m != 1): raise ValueError("The top player should have 1 win & match recorded.") elif i in (id2,) and (w != 0 and m != 1) : raise ValueError("The 2nd player should have 0 wins & 1 match") standings = playerStandings(t2) [id1, id2] = [row[0] for row in standings] for (i, n, w, m) in standings: if i in (id1,) and (w != 1 and m != 1): raise ValueError("The top player should have 1 win & match recorded.") elif i in (id2,) and (w != 0 and m != 1) : raise ValueError("The 2nd player should have 0 wins & 1 match") print "10. With 2 tournaments players have the correct standings." # add another 2 players to first tournament to check that OMW works populate_more() standings = playerStandings(t1) [nid1, nid2, nid3, nid4] = [row[0] for row in standings] for (i, n, w, m) in standings: if i in (nid1,) and (w != 1 and m != 1 and i != id1): raise ValueError("The top player should be the same & have 1 win & match recorded.") elif i in (nid4,) and (w != 1 and n != "Fifth Player") : raise ValueError("Fifth Player should have 1 win but be in last place") print "11. With 4 players with 1 win each the players have the correct OMW standings."
def add_videos(request): name_list = [] context_dict = {} if request.method == 'POST': url = request.POST.get('youtube') populate(url) context_dict["message"] = "Playlist successfully added" return render(request, 'app/add_videos.html', context_dict)
def testCount(): # added a test of actual count = 2 players via populate.py populate() c = countPlayers() if c == '3': raise TypeError( "countPlayers() should return numeric two, not string '2'.") if c != 3: raise ValueError("Initially, countPlayers should return three.") print "3a. Initially, countPlayers() returns three." deleteMatches() deletePlayers() c = countPlayers() if c == '0': raise TypeError( "countPlayers() should return numeric zero, not string '0'.") if c != 0: raise ValueError("After deleting, countPlayers should return zero.") print "3b. After deleting, countPlayers() returns zero."
def testCount(): # added a test of actual count = 2 players via populate.py populate(); c = countPlayers() if c == '3': raise TypeError( "countPlayers() should return numeric two, not string '2'.") if c != 3: raise ValueError("Initially, countPlayers should return three.") print "3a. Initially, countPlayers() returns three." deleteMatches() deletePlayers() c = countPlayers() if c == '0': raise TypeError( "countPlayers() should return numeric zero, not string '0'.") if c != 0: raise ValueError("After deleting, countPlayers should return zero.") print "3b. After deleting, countPlayers() returns zero."
def testMultTournament(): # populate with 3 players split across 2 tournaments deleteMatches() deleteTournaments() deletePlayers() populate() standings = playerStandings() [id1, id2, id3] = [row[0] for row in standings] # verify there are 2 tournaments conn = connect() c = conn.cursor() c.execute("SELECT * FROM tournaments") tourneys = c.fetchall() if len(tourneys) != 2: raise ValueError("There should be 2 tournaments") # verify there are 2 players registered for each tournament [t1, t2] = [row[0] for row in tourneys] c.execute( '''SELECT player_id FROM tournament_registrations WHERE tournament_id = (%s)''', (t1, )) players = c.fetchall() if len(players) != 2: print "players: ", players raise ValueError("There should be 2 players") c.execute( '''SELECT player_id FROM tournament_registrations WHERE tournament_id = (%s)''', (t2, )) players = c.fetchall() if len(players) != 2: raise ValueError("There should be 2 players") conn.close() # verify that results are correct for all tournament and specific # tournament standings standings = playerStandings(t1) [id1, id2] = [row[0] for row in standings] for (i, n, w, m) in standings: if i in (id1, ) and (w != 1 and m != 1): raise ValueError( "The top player should have 1 win & match recorded.") elif i in (id2, ) and (w != 0 and m != 1): raise ValueError("The 2nd player should have 0 wins & 1 match") standings = playerStandings(t2) [id1, id2] = [row[0] for row in standings] for (i, n, w, m) in standings: if i in (id1, ) and (w != 1 and m != 1): raise ValueError( "The top player should have 1 win & match recorded.") elif i in (id2, ) and (w != 0 and m != 1): raise ValueError("The 2nd player should have 0 wins & 1 match") print "10. With 2 tournaments players have the correct standings." # add another 2 players to first tournament to check that OMW works populate_more() standings = playerStandings(t1) [nid1, nid2, nid3, nid4] = [row[0] for row in standings] for (i, n, w, m) in standings: if i in (nid1, ) and (w != 1 and m != 1 and i != id1): raise ValueError( "The top player should be the same & have 1 win & match recorded." ) elif i in (nid4, ) and (w != 1 and n != "Fifth Player"): raise ValueError( "Fifth Player should have 1 win but be in last place") print "11. With 4 players with 1 win each the players have the correct OMW standings."
#!/usr/bin/env python #encoding: utf8 from saidb import SAIDB def populate(): import populate populate.populate(saidb) saidb = SAIDB() try: populate() saidb.updateSources() finally: saidb.close() import evaluator