Exemple #1
0
 def test_value_of_key__in_game_obj_can_be_extracted(self):
     users.add_player_to_data("testUser11", "none", game_single.create_game())
     points = game_single.extract_value_from_game("testUser11", "points")
     question_number = game_single.extract_value_from_game("testUser11", "question_number")
     self.assertEqual(5, points)
     self.assertEqual(1, question_number)
     
     users.remove_player_from_data("testUser11")
Exemple #2
0
    def test_if_username_does_exist(self):
        users.add_player_to_data("testUser2", "ka10", "none")
        does_not_exist = users.check_if_username_exists("I-Dont-Exist")
        does_exist = users.check_if_username_exists("testUser2")
        self.assertFalse(does_not_exist)
        self.assertTrue(does_exist)

        users.remove_player_from_data("testUser2")
Exemple #3
0
    def test_if_can_add_user_when_username_exists(self):
        does_not_exist = users.check_if_username_exists("testUser5")
        self.assertFalse(does_not_exist)

        users.add_player_to_data("testUser5", "ka10", "none")
        does_exists = users.check_if_username_exists("testUser5")
        self.assertTrue(does_exists)

        users.remove_player_from_data("testUser5")
Exemple #4
0
    def test_if_password_matches_username(self):
        users.add_player_to_data("testUser4", "ka10", "none")
        user_one_password_not_match = users.check_if_password_matches(
            "testUser4", "ka9")
        user_one_password_matches = users.check_if_password_matches(
            "testUser4", "ka10")
        self.assertFalse(user_one_password_not_match)
        self.assertTrue(user_one_password_matches)

        users.remove_player_from_data("testUser4")
Exemple #5
0
 def test_if_win_state_can_be_set(self):
     users.add_player_to_data("testUser18", "none", game_single.create_game())
     win_state = game_single.extract_value_from_game("testUser18", "win")
     self.assertEqual("not", win_state)
     
     game_single.set_win_state("testUser18", "won")
     new_win_state = game_single.extract_value_from_game("testUser18", "win")
     self.assertEqual("won", new_win_state)
     
     users.remove_player_from_data("testUser18")
Exemple #6
0
 def test_that_question_number_can_be_increased(self):
     users.add_player_to_data("testUser12", "none", game_single.create_game())
     question_number = game_single.extract_value_from_game("testUser12", "question_number")
     self.assertEqual(1, question_number)
     
     game_single.increase_question_number("testUser12")
     question_number_updated = game_single.extract_value_from_game("testUser12", "question_number")
     self.assertEqual(2, question_number_updated)
     
     users.remove_player_from_data("testUser12")
Exemple #7
0
 def test_if_game_duration_can_be_set(self):
     users.add_player_to_data("testUser20", "none", game_single.create_game())
     time = game_single.extract_value_from_game("testUser20", "game_duration")
     self.assertEqual(0, time)
     
     game_single.set_game_duration("testUser20", 20)
     new_time = game_single.extract_value_from_game("testUser20", "game_duration")
     self.assertEqual(20, new_time)
     
     users.remove_player_from_data("testUser20")
Exemple #8
0
    def test_if_user_score_can_be_reset(self):
        users.add_player_to_data("testUser10", "none", {})
        users.increase_player_score("testUser10", 5)
        score = users.return_player_score("testUser10")
        self.assertEqual(5, score)

        users.reset_player_score("testUser10")
        reset_score = users.return_player_score("testUser10")
        self.assertEqual(0, reset_score)

        users.remove_player_from_data("testUser10")
Exemple #9
0
    def test_if_user_score_returned(self):
        users.add_player_to_data("testUser8", "none", {})
        users.reset_player_score("testUser8")
        reset_score = users.return_player_score("testUser8")
        self.assertEqual(0, reset_score)

        users.increase_player_score("testUser8", 200)
        increased_score = users.return_player_score("testUser8")
        self.assertEqual(200, increased_score)

        users.remove_player_from_data("testUser8")
Exemple #10
0
    def test_if_player_can_be_added(self):
        users.add_player_to_data("testUser1", "ka10", "none")
        data = files.read_data_file("users")
        user = {}

        for player in data:
            if player["username"] == "testUser1":
                user = player

        self.assertIn(user, data)

        users.remove_player_from_data("testUser1")
Exemple #11
0
 def test_if_incorrect_answer_can_be_appended(self):
     users.add_player_to_data("testUser14", "none", game_single.create_game())
     list_of_incorrect_answers = game_single.extract_value_from_game("testUser14", "incorrect_answers")
     self.assertEqual([], list_of_incorrect_answers)
     self.assertEqual(0, len(list_of_incorrect_answers))
     
     game_single.append_incorrect_answers("testUser14", "im-a-wrong-answer")
     list_of_incorrect_answers_updated = game_single.extract_value_from_game("testUser14", "incorrect_answers")
     self.assertIn("im-a-wrong-answer", list_of_incorrect_answers_updated)
     self.assertEqual(1, len(list_of_incorrect_answers_updated))
     
     users.remove_player_from_data("testUser14")
Exemple #12
0
 def test_if_incorrect_answer_list_can_be_reset(self):
     users.add_player_to_data("testUser15", "none", game_single.create_game())
     game_single.append_incorrect_answers("testUser15", "im-a-wrong-answer")
     game_single.append_incorrect_answers("testUser15", "im-a-wrong-answer-too")
     
     list_of_incorrect_answers = game_single.extract_value_from_game("testUser15", "incorrect_answers")
     self.assertEqual(["im-a-wrong-answer", "im-a-wrong-answer-too"], list_of_incorrect_answers)
     
     game_single.reset_incorrect_answers("testUser15")
     list_of_incorrect_answers_updated = game_single.extract_value_from_game("testUser15", "incorrect_answers")
     self.assertEqual([], list_of_incorrect_answers_updated)
     
     users.remove_player_from_data("testUser15")
Exemple #13
0
    def test_if_user_score_increases(self):
        users.add_player_to_data("testUser9", 0, "none")
        score_one = users.return_player_score("testUser9")
        self.assertEqual(0, score_one)

        users.increase_player_score("testUser9", 2)
        score_two = users.return_player_score("testUser9")
        self.assertEqual(2, score_two)

        users.increase_player_score("testUser9", 10)
        score_three = users.return_player_score("testUser9")
        self.assertEqual(12, score_three)

        users.remove_player_from_data("testUser9")
Exemple #14
0
 def test_if_can_reset_points(self):
     users.add_player_to_data("testUser17", "none", game_single.create_game())
     points = game_single.extract_value_from_game("testUser17", "points")
     self.assertEqual(5, points)
     
     game_single.decrease_round_points("testUser17")
     points_two = game_single.extract_value_from_game("testUser17", "points")
     self.assertEqual(3, points_two)
     
     game_single.reset_round_points("testUser17")
     points_two = game_single.extract_value_from_game("testUser17", "points")
     self.assertEqual(5, points_two)
     
     users.remove_player_from_data("testUser17")
    def test_if_can_create_leaderboard_player_obj(self):
        users.add_player_to_data("testUser24", "none",
                                 game_single.create_game())
        leaderboard_player = leaderboard_single.create_leaderboard_player(
            "testUser24")
        self.assertIn("username", leaderboard_player)
        self.assertIn("duration", leaderboard_player)
        self.assertIn("score", leaderboard_player)
        self.assertIn("rank", leaderboard_player)
        self.assertEqual("testUser24", leaderboard_player["username"])
        self.assertEqual(0, leaderboard_player["score"])
        self.assertEqual(0, leaderboard_player["rank"])
        self.assertEqual(0, leaderboard_player["duration"])

        users.remove_player_from_data("testUser24")
Exemple #16
0
    def test_if_can_remove_user_by_index(self):
        file_path = files.create_file_path("users")
        data = files.read_data_file("users")
        data_length = len(data)

        users.add_player_to_data("testUser6", "none", "none")
        users.add_player_to_data("testUser7", "none", "none")

        user_index_zero = users.create_player("testUser6", "none", 0, "none")
        user_index_one = users.create_player("testUser7", "none", 0, "none")

        data_two = files.read_data_file("users")
        self.assertEqual(data_two[data_length], user_index_zero)
        users.remove_player_from_data_by_index(data_length)

        data_three = files.read_data_file("users")
        self.assertEqual(data_three[data_length], user_index_one)
        users.remove_player_from_data_by_index(data_length)
def signUp():
    """
    Route for the sign up page where players can create a new account.
    Adds a player object to the users data.
    """
    username_error = None
    list_of_countries = []

    if request.method == "POST":
        if not users.check_if_username_exists(request.form["username"]):
            users.add_player_to_data(request.form["username"],
                                     request.form["password"],
                                     game_single.create_game())
            return redirect(
                url_for("gameMenu", username=request.form["username"]))
        else:
            username_error = "Username is taken"

    return render_template("sign-up.html", username_error=username_error)
Exemple #18
0
 def test_if_win_state_can_be_set_according_to_score(self):
     users.add_player_to_data("testUser19", "none", game_single.create_game())
     win_state = game_single.extract_value_from_game("testUser19", "win")
     score = users.return_player_score("testUser19")
     self.assertEqual("not", win_state)
     self.assertEqual(0, score)
     
     game_single.check_for_win(score, "testUser19")
     updated_win_state = game_single.extract_value_from_game("testUser19", "win")
     self.assertEqual("lost", updated_win_state)
     
     users.increase_player_score("testUser19", 100)
     updated_score = users.return_player_score("testUser19")
     self.assertEqual(100, updated_score)
     
     game_single.check_for_win(updated_score, "testUser19")
     updated_win_state_two = game_single.extract_value_from_game("testUser19", "win")
     self.assertEqual("won", updated_win_state_two)
     
     users.remove_player_from_data("testUser19")
Exemple #19
0
 def test_if_list_of_random_numbers_of_countries_in_game_obj_can_be_updated(self):
     users.add_player_to_data("testUser21", "none", game_single.create_game())
     list_of_numbers = game_single.extract_value_from_game("testUser21", "countries")
     
     def check_if_every_item_is_int_in_list(list_of_items):
         for item in list_of_items:
             if type(item) == int:
                 return True
             else:
                 return False
                 
     self.assertEqual(20, len(list_of_numbers))
     self.assertTrue(check_if_every_item_is_int_in_list(list_of_numbers))
     
     game_single.generate_new_list_of_random_countries("testUser21")
     new_list = game_single.extract_value_from_game("testUser21", "countries")
     self.assertEqual(20, len(new_list))
     self.assertTrue(check_if_every_item_is_int_in_list(new_list))
     self.assertNotEqual(list_of_numbers, new_list)
     
     users.remove_player_from_data("testUser21")