Exemple #1
0
def leaderboard():
    '''
    Show all player scores by song
    '''

    # generate_leaderboard with '0' option provides full results
    # generate_leaderboard with a interger greater than zero returns that
    # number of results or the total number availabe where
    # this is a lower number
    template_users_history = game_operations.generate_leaderboard(0)
    return render_template("leaderboard.html",
                           users_history=template_users_history)
    def test_leaderboard_page_names(self):
        '''test the names rendered on the leaderboard page match the names
            in the order and value from the file'''

        # collect the names, classes and song scores from the filename
        file_results = game_operations.generate_leaderboard(0)
        # convert keys to a list
        file_results_names = list(OrderedDict(file_results).keys())

        self.driver.get("http://localhost:5000/leaderboard")
        time.sleep(3)
        soup = BeautifulSoup(self.driver.page_source, 'html5lib')
        for line in soup.find_all('div', {'class': 'leaderboard-name'}):
            self.elements.append(line.contents[0])

        self.assertListEqual(file_results_names, self.elements)
    def test_leaderboard_page_second_name_song_scores(self):
        '''test the second player individual songs from the
            file match leaderbaord page'''

        # collect the names, classes and song scores from the filename
        file_results = game_operations.generate_leaderboard(0)
        # select the values as a list
        individual_songs = list(file_results.items())

        time.sleep(3)

        self.driver.get("http://localhost:5000/leaderboard")
        time.sleep(3)
        soup = BeautifulSoup(self.driver.page_source, 'html5lib')
        for line in soup.find(
                'div', {'id': 'individual-song-scores2'}).find_all('li'):
                self.elements.append(line.contents[0].strip())
        self.assertListEqual(individual_songs[1][1], self.elements)
Exemple #4
0
def index():
    '''
    Home page and the page to play the game
    '''

    # see README.md for google API code which would be used instead of below
    # in production version

    random_number = randint(0, len(pre_canned_videoId) - 1)

    try:
        raw_lyric = music.fetch_srt('xxx', pre_canned_videoId[random_number])
        lyric = music.convert_srt(raw_lyric)
        # get a list of 4 players and songs for the top scores section
        template_users_history = game_operations.generate_leaderboard(4)
        return render_template("index.html",
                               page_title="Home",
                               value=pre_canned_videoId[random_number],
                               lyrics=lyric,
                               users_history=template_users_history)
    except Exception as e:
        return render_template("504.html", error=str(e))