def test_reset_turn(self):
     # Test if function returns the leaderboard_len() decremnted by 1 in str format #
     init_game()
     add_to_leaderboard("Jason", 'data/leaderboard.json')
     add_to_leaderboard("Zebra", 'data/leaderboard.json')
     assert type(reset_turn('3')) is str
     self.assertEqual((int(reset_turn('2'))), 1)
 def test_get_player_name(self):
     # Test if function gets a players name #
     setup_leaderboard()
     add_to_leaderboard("Jason", 'data/leaderboard.json')
     add_to_leaderboard("Zebra", 'data/leaderboard.json')
     self.assertEqual(get_player_name(0), "Jason")
     self.assertEqual(get_player_name(1), "Zebra")
 def test_get_player_score(self):
     # Test if function gets a players name #
     init_game()
     add_to_leaderboard("Jason", 'data/leaderboard.json')
     add_to_leaderboard("Zebra", 'data/leaderboard.json')
     increase_user_score("Zebra", '2')
     self.assertEqual(get_player_score(1), 0)
     self.assertEqual(get_player_score(0), 10)
 def test_increase_user_score(self):
     # Test if function increases the users score on the leaderboard #
     clear_global_leaderboard()
     init_game()
     add_to_leaderboard("Petey", 'data/leaderboard.json')
     decrement_score('3')
     self.assertEqual(increase_user_score("Petey", '1'), 10)
     self.assertEqual(increase_user_score("Petey", '3'), 19)
 def test_add_to_leaderboard(self):
     # Test if function adds a new user to leaderboard #
     init_game()
     self.assertEqual(add_to_leaderboard('Jon', 'data/leaderboard.json'),
                      True)
     self.assertEqual(add_to_leaderboard('Paul', 'data/leaderboard.json'),
                      True)
     self.assertEqual(add_to_leaderboard('Sarah', 'data/leaderboard.json'),
                      True)
def username(playernum):
    # User(s) enter their desired usernames #
    
    instruct_num = str(leaderboard_len("data/leaderboard.json") + 1)
    if request.method == "POST":
        
        if not (check_in_file("data/global_users.txt", request.form["username"].title())):
            
            # If not in global leaderboard #
            
            write_to_file("data/users.txt", request.form["username"].title() + "\n")
            write_to_file("data/global_users.txt", request.form["username"].title() + "\n")
            add_to_leaderboard(request.form["username"].title(), 'data/leaderboard.json')
            add_to_leaderboard_global(request.form["username"].title(), 'data/global_leaderboard.json')
            
            new_num = str(int(playernum) - 1)
            playernum = new_num
            
        
        else:
            
            if not (check_in_file("data/users.txt", request.form["username"].title())):
                
                # If in global but not in local leaderboard #
                
                write_to_file("data/users.txt", request.form["username"].title() + "\n")
                add_to_leaderboard(request.form["username"].title(), 'data/leaderboard.json')
                
                new_num = str(int(playernum) - 1)
                playernum = new_num
            
            else:
                
                # If in global and local leaderboards #
                
                flash("Sorry Your Chosen Username Is Unavailable. Please Try Another")
                
            
        if int(playernum) == 0:
            
                qnumber = str(
                    leaderboard_len("data/leaderboard.json") - 1
                    )
                question = random_number_generator()
                return redirect(
                    request.form["username"] + 
                    '/' + '1' + '/' + qnumber + 
                    '/' + question
                    )
        
        else:
            return redirect("setup" + '/' + playernum)
            
    return render_template("username.html", player=instruct_num)
 def test_order_leaderboard(self):
     # Test if function returns a rearranged version of the leaderboard list #
     init_game()
     add_to_leaderboard("Jamie", 'data/leaderboard.json')
     add_to_leaderboard("Petey", 'data/leaderboard.json')
     increase_user_score("Petey", '1')
     with open("data/leaderboard.json", "r") as json_file:
         loaded_json = json.load(json_file)
         original_leaderboard = loaded_json['leaderboard']
         assert type(order_leaderboard()) is list
         self.assertNotEqual(order_leaderboard(), original_leaderboard)
 def test_right_or_wrong(self):
     # Test if function checks if an answer is right or wrong #
     init_game()
     add_to_leaderboard("Jason", 'data/leaderboard.json')
     add_to_leaderboard("Paul", 'data/leaderboard.json')
     add_to_leaderboard("Eva", 'data/leaderboard.json')
     self.assertEqual(right_or_wrong("Jason", "Telephone", '0'), True)
     self.assertEqual(right_or_wrong("Paul", "The wrong answer", '2'), None)
     self.assertEqual(right_or_wrong("Eva", "Fall", '1'), True)
 def test_next_player(self):
     # Test that function returns the next username #
     init_game()
     add_to_leaderboard("Jason", 'data/leaderboard.json')
     add_to_leaderboard("Zebra", 'data/leaderboard.json')
     self.assertEqual(next_player('Jason', '1'), 'Zebra')