Exemplo n.º 1
0
def test_start_game():
    rooms = client.get("/rooms", headers=owner)
    real_rooms = rooms.json().get("room_list")
    room_names = []
    for room in real_rooms:
        room_names.append(room.get("name"))

    start_game(owner, room_names[0])
    rooms = client.get("/rooms", headers=owner)
    rooms_json = rooms.json()
    print("\n\nStarted first room: " + rooms_json.__str__())
Exemplo n.º 2
0
def test_all_for_10():
    response_get_pregame1 = client.get("/test-game-10/game_state",
                                       headers=p[0])
    # print(response_get_pregame1.json())
    assert response_get_pregame1.status_code == 200

    response_start = start_game(p[0], "test-game-10")
    print(response_start.json())
    #assert response_start.status_code == 201

    voldemort_uname = ""
    for k in range(0, 10):
        response_get_game = client.get("/test-game-10/game_state",
                                       headers=p[k])
        assert response_get_game.status_code == 200
        rta: dict = response_get_game.json()

        if rta['my_role'] == "Voldemort":
            voldemort_uname = unames[k]
        else:
            pass
    # print(f"Voldemort is: {voldemort_uname}")

    round_count = 0
    game_is_not_over = True
    de_score = 0
    fo_score = 0
    imperio_casted = False
    crucio_availables = 2
    avadas_avaliables = 2

    while game_is_not_over:
        round_count += 1
        response_get_ingame = client.get("/test-game-10/game_state",
                                         headers=p[0])
        assert response_get_ingame.status_code == 200

        rta: dict = response_get_ingame.json()
        # print(f"\nStart of round {round_count}")
        # print(rta)
        minister_uname: str = rta["minister"]
        minister_index = unames.index(minister_uname)
        alive_lads = rta["player_list"]

        director_index = (minister_index + 1) % 10
        director_uname: str = unames[director_index]
        while (director_uname not in alive_lads):
            director_index = (director_index + 1) % 10
            director_uname: str = unames[director_index]

        response_propose = client.put("/test-game-10/director",
                                      json={"director_uname": director_uname},
                                      headers=p[minister_index])
        if (response_propose.status_code != 201):
            print(response_propose.json())
        assert response_propose.status_code == 201

        for i in range(0, 10):
            if unames[i] in alive_lads:
                response = vote(header=p[i],
                                vote="Lumos",
                                room_name="test-game-10")
                assert response.status_code == 200
            else:
                response = vote(header=p[i],
                                vote="Nox",
                                room_name="test-game-10")
                assert response.status_code == 409

        response_get_ingame2 = client.get("/test-game-10/game_state",
                                          headers=p[0])
        assert response_get_ingame2.status_code == 200

        if de_score > 2 and voldemort_uname == director_uname:
            print("Death eaters won, voldi runs hogwarts")
            game_is_not_over = False
            break

        response_get_cards1 = client.get("test-game-10/cards",
                                         headers=p[minister_index])
        assert response_get_cards1.status_code == 200

        response_discard1 = client.put("test-game-10/discard",
                                       json={"card_index": 0},
                                       headers=p[minister_index])
        assert response_discard1.status_code == 201

        response_get_cards2 = client.get("test-game-10/cards",
                                         headers=p[director_index])
        assert response_get_cards2.status_code == 200

        response_discard2 = client.put("test-game-10/discard",
                                       json={"card_index": 0},
                                       headers=p[director_index])
        assert response_discard2.status_code == 201

        response_post_proclamation = client.get("/test-game-10/game_state",
                                                headers=p[0])
        assert response_post_proclamation.status_code == 200
        scores_state: dict = response_post_proclamation.json()
        de_score = scores_state["de_procs"]
        fo_score = scores_state["fo_procs"]

        if de_score == 6:
            print("Death eaters won")
            game_is_not_over = False
            break
        elif fo_score == 5:
            print("Phoenix order won")
            game_is_not_over = False
            break
        else:
            pass
            # print(f"Death Eaters: {de_score} , Phoenix Order: {fo_score}")

        if (de_score == 1 and crucio_availables > 1):
            response_cast_crucio = client.put(
                "/test-game-10/cast/crucio",
                headers=p[minister_index],
                json={"target_uname": unames[(minister_index - 2) % 10]})
            # print(response_cast_crucio.json())
            assert response_cast_crucio.status_code == 200
        elif (de_score == 2 and crucio_availables > 0):
            response_cast_crucio = client.put(
                "/test-game-10/cast/crucio",
                headers=p[minister_index],
                json={"target_uname": unames[(minister_index - 2) % 10]})
            # print(response_cast_crucio.json())
            assert response_cast_crucio.status_code == 200
        else:
            pass

        if (de_score == 1 and crucio_availables > 1):
            response_confirm_crucio = client.put(
                "/test-game-10/cast/confirm-crucio", headers=p[minister_index])
            # print(response_confirm_crucio.json())
            assert response_confirm_crucio.status_code == 200
            crucio_availables -= 1
        elif (de_score == 2 and crucio_availables > 0):
            response_confirm_crucio = client.put(
                "/test-game-10/cast/confirm-crucio", headers=p[minister_index])
            # print(response_confirm_crucio.json())
            assert response_confirm_crucio.status_code == 200
            crucio_availables -= 1
        else:
            pass

        if de_score == 3 and not imperio_casted:
            # ----------TESTING IMPERIUS BAD BEGIN-------------------------
            response_cast_imperio_bad1 = client.put(
                "/test-game-10/cast/imperius",
                headers=p[(minister_index + 1) % 10],
                json={"target_uname": unames[(minister_index - 2) % 10]})
            response_cast_imperio_bad2 = client.put(
                "/test-game-10/cast/imperius",
                headers=p[minister_index],
                json={"target_uname": unames[minister_index]})
            response_cast_imperio_bad3 = client.put(
                "/test-game-10/cast/imperius",
                headers=p[minister_index],
                json={"target_uname": "James Bond"})
            assert response_cast_imperio_bad1.status_code == 405
            assert response_cast_imperio_bad2.status_code == 409
            assert response_cast_imperio_bad3.status_code == 404
            # ----------TESTING IMPERIUS BAD END-------------------------
            response_cast_imperio_good = client.put(
                "/test-game-10/cast/imperius",
                headers=p[minister_index],
                json={"target_uname": unames[(minister_index - 2) % 10]})
            # print(response_cast_imperio_good.json())
            assert response_cast_imperio_good.status_code == 200

            imperio_casted = True

        if ((de_score == 4 and avadas_avaliables == 2)
                or (de_score == 5 and avadas_avaliables == 1)):
            victim_index = (minister_index - 1) % 10
            victim_uname = unames[victim_index]
            response_cast_avada = client.put(
                "/test-game-10/cast/avada-kedavra",
                headers=p[minister_index],
                json={"target_uname": victim_uname})
            # print(response_cast_avada.json())
            assert response_cast_avada.status_code == 200
            avadas_avaliables -= 1
            if victim_uname == voldemort_uname:
                print("Voldemort died, F")
                game_is_not_over = False
def test_expelliarmus():
    response_get_pregame1 = client.get("/test-expelliarmus/game_state",
                                       headers=p[0])
    # print(response_get_pregame1.json())
    assert response_get_pregame1.status_code == 200

    response_start = start_game(p[0], "test-expelliarmus")
    # print(response_start.json())
    #assert response_start.status_code == 201

    voldemort_uname = ""
    for k in range(0, 10):
        response_get_game = client.get("/test-expelliarmus/game_state",
                                       headers=p[k])
        assert response_get_game.status_code == 200
        rta: dict = response_get_game.json()

        if rta['my_role'] == "Voldemort":
            voldemort_uname = unames[k]
        else:
            pass
    # print(f"Voldemort is: {voldemort_uname}")

    round_count = 0
    game_is_not_over = True
    de_score = 0
    fo_score = 0
    imperio_casted = False
    expelliarmus_cast = False
    crucio_availables = 2
    avadas_avaliables = 2

    while game_is_not_over:
        round_count += 1
        expelliarmus_cast = False
        response_get_ingame = client.get("/test-expelliarmus/game_state",
                                         headers=p[0])
        assert response_get_ingame.status_code == 200

        rta: dict = response_get_ingame.json()
        # print(f"\nStart of round {round_count}")
        # print(rta)
        minister_uname: str = rta["minister"]
        minister_index = unames.index(minister_uname)
        alive_lads = rta["player_list"]

        director_index = (minister_index + 1) % 10
        director_uname: str = unames[director_index]
        while (director_uname not in alive_lads):
            director_index = (director_index + 1) % 10
            director_uname: str = unames[director_index]

        response_propose = client.put("/test-expelliarmus/director",
                                      json={"director_uname": director_uname},
                                      headers=p[minister_index])
        if (response_propose.status_code != 201):
            print(response_propose.json())
        assert response_propose.status_code == 201

        for i in range(0, 10):
            if unames[i] in alive_lads:
                if (voldemort_uname != director_uname):
                    response = vote(header=p[i],
                                    vote="Lumos",
                                    room_name="test-expelliarmus")
                    assert response.status_code == 200
                else:
                    response = vote(header=p[i],
                                    vote="Nox",
                                    room_name="test-expelliarmus")
                    assert response.status_code == 200
        if (voldemort_uname == director_uname):
            continue

        response_get_ingame2 = client.get("/test-expelliarmus/game_state",
                                          headers=p[0])
        assert response_get_ingame2.status_code == 200

        if de_score > 2 and voldemort_uname == director_uname:
            print("Death eaters won, voldi runs hogwarts")
            game_is_not_over = False
            break

        # ---------------------------------
        if (round_count == 2):
            assert (client.put("test-expelliarmus/discard",
                               json={"card_index": 3},
                               headers=p[director_index])).status_code == 405
        # ---------------------------------

        response_get_cards1 = client.get("test-expelliarmus/cards",
                                         headers=p[minister_index])
        assert response_get_cards1.status_code == 200

        response_discard1 = client.put("test-expelliarmus/discard",
                                       json={"card_index": 0},
                                       headers=p[minister_index])
        assert response_discard1.status_code == 201

        response_get_cards2 = client.get("test-expelliarmus/cards",
                                         headers=p[director_index])
        assert response_get_cards2.status_code == 200

        # ---------------------- EXPELLIARMUS TESTING
        if (round_count == 2):
            assert (client.put("test-expelliarmus/discard",
                               json={"card_index": 3},
                               headers=p[director_index])).status_code == 403

        if (de_score == 5 and not expelliarmus_cast):
            response_expelliarmus_director = client.put(
                "test-expelliarmus/discard",
                json={"card_index": 3},
                headers=p[director_index])
            # print(response_expelliarmus_director.json())
            assert response_expelliarmus_director.status_code == 201

            expelliarmus_cast = True

            if (round_count % 2):
                response_expelliarmus_minister = client.put(
                    f"/test-expelliarmus/expelliarmus",
                    headers=p[minister_index],
                    json={"vote": "Lumos"})
                assert response_expelliarmus_minister.status_code == 200
                # print(response_expelliarmus_minister.json())
                continue  # With this it should come back to the while statement
            else:
                response_expelliarmus_minister = client.put(
                    f"/test-expelliarmus/expelliarmus",
                    headers=p[minister_index],
                    json={"vote": "Nox"})
                # print(response_expelliarmus_minister.json())
                assert response_expelliarmus_minister.status_code == 200
        # ---------------EXPELLIARMUS TESTING END------------------

        response_discard2 = client.put("test-expelliarmus/discard",
                                       json={"card_index": 0},
                                       headers=p[director_index])
        assert response_discard2.status_code == 201

        response_post_proclamation = client.get(
            "/test-expelliarmus/game_state", headers=p[0])
        assert response_post_proclamation.status_code == 200
        scores_state: dict = response_post_proclamation.json()
        de_score = scores_state["de_procs"]
        fo_score = scores_state["fo_procs"]

        if de_score == 6:
            print("Death eaters won")
            game_is_not_over = False
            break
        elif fo_score == 5:
            print("Phoenix order won")
            break
        else:
            pass
            # print(f"Death Eaters: {de_score} , Phoenix Order: {fo_score}")

        if de_score == 1 and crucio_availables > 1:
            response_cast_crucio = client.put(
                "/test-expelliarmus/cast/crucio",
                headers=p[minister_index],
                json={"target_uname": unames[(minister_index - 2) % 10]})
            assert response_cast_crucio.status_code == 200
        elif de_score == 2 and crucio_availables > 0:
            response_cast_crucio = client.put(
                "/test-expelliarmus/cast/crucio",
                headers=p[minister_index],
                json={"target_uname": unames[(minister_index - 2) % 10]})
            assert response_cast_crucio.status_code == 200
        else:
            pass

        if de_score == 1 and crucio_availables > 1:
            response_confirm_crucio = client.put(
                "/test-expelliarmus/cast/confirm-crucio",
                headers=p[minister_index])
            assert response_confirm_crucio.status_code == 200
            crucio_availables -= 1
        elif de_score == 2 and crucio_availables > 0:
            response_confirm_crucio = client.put(
                "/test-expelliarmus/cast/confirm-crucio",
                headers=p[minister_index])
            assert response_confirm_crucio.status_code == 200
            crucio_availables -= 1
        else:
            pass

        if de_score == 3 and not imperio_casted:
            response_cast_imperio_good = client.put(
                "/test-expelliarmus/cast/imperius",
                headers=p[minister_index],
                json={"target_uname": unames[(minister_index - 2) % 10]})
            # print(response_cast_imperio_good.json())
            assert response_cast_imperio_good.status_code == 200

            imperio_casted = True

        if ((de_score == 4 and avadas_avaliables == 2)
                or (de_score == 5 and avadas_avaliables == 1)):
            victim_index = (minister_index - 1) % 10
            victim_uname = unames[victim_index]
            response_cast_avada = client.put(
                "/test-expelliarmus/cast/avada-kedavra",
                headers=p[minister_index],
                json={"target_uname": victim_uname})
            # print(response_cast_avada.json())
            assert response_cast_avada.status_code == 200
            avadas_avaliables -= 1
            if victim_uname == voldemort_uname:
                print("Voldemort died, F")
                game_is_not_over = False
Exemplo n.º 4
0
def test_all_for_5():
    response_get_pregame1 = client.get("/test-game-5/game_state", headers=p[0])
    print(response_get_pregame1.json())
    assert response_get_pregame1.status_code == 200

    response_start = start_game(p[0], "test-game-5")
    print(response_start.json())
    #assert response_start.status_code == 201

    voldemort_uname = ""
    for k in range(0, 5):
        response_get_game = client.get("/test-game-5/game_state", headers=p[k])
        assert response_get_game.status_code == 200
        rta: dict = response_get_game.json()

        if rta['my_role'] == "Voldemort":
            voldemort_uname = unames[k]
        else:
            pass
    # print(f"Voldemort is: {voldemort_uname}")

    round_count = 0
    game_is_not_over = True
    de_score = 0
    fo_score = 0
    divination_casted = False
    avadas_avaliables = 2

    while game_is_not_over:
        round_count += 1
        response_get_ingame = client.get("/test-game-5/game_state",
                                         headers=p[0])
        assert response_get_ingame.status_code == 200

        rta: dict = response_get_ingame.json()
        # print(f"\nStart of round {round_count}")
        # print(rta)
        minister_uname: str = rta["minister"]
        minister_index = unames.index(minister_uname)
        director_index = (minister_index + 1) % 5
        director_uname: str = unames[director_index]
        alive_lads = rta["player_list"]

        response_propose = client.put("/test-game-5/director",
                                      json={"director_uname": director_uname},
                                      headers=p[minister_index])
        if (response_propose.status_code != 201):
            print(response_propose.json())
        assert response_propose.status_code == 201

        for i in range(0, 5):
            if unames[i] in alive_lads:
                response = vote(header=p[i],
                                vote="Lumos",
                                room_name="test-game-5")
                assert response.status_code == 200
            else:
                response = vote(header=p[i],
                                vote="Nox",
                                room_name="test-game-5")
                assert response.status_code == 409

        response_get_ingame2 = client.get("/test-game-5/game_state",
                                          headers=p[0])
        assert response_get_ingame2.status_code == 200

        if de_score > 2 and voldemort_uname == director_uname:
            print("Death eaters won, voldi runs hogwarts")
            game_is_not_over = False
            break

        response_get_cards1 = client.get("test-game-5/cards",
                                         headers=p[minister_index])
        assert response_get_cards1.status_code == 200

        response_discard1 = client.put("test-game-5/discard",
                                       json={"card_index": 0},
                                       headers=p[minister_index])
        assert response_discard1.status_code == 201

        response_get_cards2 = client.get("test-game-5/cards",
                                         headers=p[director_index])
        assert response_get_cards2.status_code == 200

        response_discard2 = client.put("test-game-5/discard",
                                       json={"card_index": 0},
                                       headers=p[director_index])
        assert response_discard2.status_code == 201

        response_post_proclamation = client.get("/test-game-5/game_state",
                                                headers=p[0])
        assert response_post_proclamation.status_code == 200
        scores_state: dict = response_post_proclamation.json()
        de_score = scores_state["de_procs"]
        fo_score = scores_state["fo_procs"]

        if de_score == 6:
            print("Death eaters won")
            game_is_not_over = False
            break
        elif fo_score == 5:
            print("Phoenix order won")
            break
        else:
            pass

        if de_score == 3:
            response_cast_divination = client.get(
                "/test-game-5/cast/divination", headers=p[minister_index])
            if not divination_casted:
                assert response_cast_divination.status_code == 200
                # print("\n Next 3 cards:")
                # print(response_cast_divination.json())
            else:
                assert response_cast_divination.status_code == 405
            response_confirm_divination = client.put(
                "/test-game-5/cast/confirm_divination",
                headers=p[minister_index])
            if not divination_casted:
                assert response_confirm_divination.status_code == 200
            else:

                assert response_confirm_divination.status_code == 405

            divination_casted = True

        if (de_score == 4 or de_score == 5) and avadas_avaliables >= 1:
            victim_index = (minister_index - 1) % 5
            victim_uname = unames[victim_index]
            response_cast_avada = client.put(
                "/test-game-5/cast/avada-kedavra",
                headers=p[minister_index],
                json={"target_uname": victim_uname})
            # print(response_cast_avada.json())
            assert response_cast_avada.status_code == 200
            avadas_avaliables -= 1
            if victim_uname == voldemort_uname:
                print("Voldemort died, F")
                game_is_not_over = False
Exemplo n.º 5
0
def test_happy_path_9():
    response_get_pregame1 = get_game_state(room_name=TC9)
    assert response_get_pregame1.status_code == 200

    response_start = start_game(owner, TC9)
    #assert response_start.status_code == 201
    voldemort_uname = get_voldi(TC9)

    round_count = 0
    de_score = 0
    crucios = 2

    while de_score <= 2:
        round_count += 1
        # print("-------------------------------------\n")
        # print("Round count " + str(round_count))
        response_get_ingame = get_game_state(room_name=TC9)
        assert response_get_ingame.status_code == 200

        rta: dict = response_get_ingame.json()
        minister_uname: str = rta["minister"]
        minister_index = unames.index(minister_uname)
        director_index = (minister_index + 1) % 9
        director_uname: str = unames[director_index]
        alive_lads = rta["player_list"]
        de_procs = rta['de_procs']

        respone_propose = propose_director(director_uname,
                                           minister_index,
                                           room_name=TC9)
        assert respone_propose.status_code == 201

        if de_procs == 0 or de_procs == 1:
            approve_formula(alive_lads, TC9, 9)
        else:
            random_vote(alive_lads, TC9, 9)

        response_get_ingame2 = get_game_state(room_name=TC9)
        assert response_get_ingame2.status_code == 200
        # # print("\nAfter the voting")
        # # print(response_get_ingame2.json())

        if de_score > 2 and voldemort_uname == director_uname:
            # print("Death eaters won, voldi runs hogwarts")
            break

        response_get_cards1 = get_cards(minister_index, room_name=TC9)
        assert response_get_cards1.status_code == 200

        response_discard1 = discard(minister_index, room_name=TC9)
        assert response_discard1.status_code == 201

        response_get_cards2 = get_cards(director_index, room_name=TC9)
        assert response_get_cards2.status_code == 200

        response_discard2 = discard(director_index, room_name=TC9)
        assert response_discard2.status_code == 201

        response_post_proclamation = get_game_state(room_name=TC9)

        assert response_post_proclamation.status_code == 200
        scores_state: dict = response_post_proclamation.json()
        # print(f"SCORES_STATE {str(scores_state)}")

        poor_guy = minister_index
        while poor_guy == minister_index:
            poor_guy = randint(0, 8)

        de_score = scores_state["de_procs"]

        if (de_score == 1 and crucios > 1):
            response_cast_crucio = cast_crucio(minister_index, poor_guy, TC9)
            # print(response_cast_crucio.status_code)
            # print("LOYALTY: " + str(response_cast_crucio.json()))
            crucios -= 1
            # EDGE CASE, user was already investigated
            assert (response_cast_crucio.status_code == 200
                    or response_cast_crucio.status_code == 409)
        elif (de_score == 2 and crucios > 0):
            response_cast_crucio = cast_crucio(minister_index, poor_guy, TC9)
            # print(response_cast_crucio.status_code)
            # print("LOYALTY: " + str(response_cast_crucio.json()))
            crucios -= 1
            # EDGE CASE, user was already investigated
            assert (response_cast_crucio.status_code == 200
                    or response_cast_crucio.status_code == 409)

        confirm = confirm_crucio(minister_index, TC9)
Exemplo n.º 6
0
def test_kys_5():
    first = True
    response_get_pregame1 = get_game_state()
    assert response_get_pregame1.status_code == 200

    response_start = start_game(owner, TC)
    print(response_start.json())
    #assert response_start.status_code == 201
    voldemort_uname = get_voldi()

    round_count = 0
    de_score = 0

    while de_score <= 2:
        round_count += 1
        # print("Round count " + str(round_count))
        response_get_ingame = get_game_state(room_name=TC)
        assert response_get_ingame.status_code == 200

        rta: dict = response_get_ingame.json()
        minister_uname: str = rta["minister"]
        minister_index = unames.index(minister_uname)
        director_index = (minister_index + 1) % 7
        director_uname: str = unames[director_index]
        alive_lads = rta["player_list"]
        de_procs = rta['de_procs']

        response_propose = propose_director(director_uname, minister_index)
        if (response_propose.status_code != 201):
            print(response_propose.json())
        assert response_propose.status_code == 201

        if de_procs == 1:
            approve_formula(alive_lads)
        else:
            random_vote(alive_lads)

        response_get_ingame2 = get_game_state()
        assert response_get_ingame2.status_code == 200
        # # print("\nAfter the voting")
        # # print(response_get_ingame2.json())

        if de_score > 2 and voldemort_uname == director_uname:
            # print("Death eaters won, voldi runs hogwarts")
            break

        response_get_cards1 = get_cards(minister_index)
        assert response_get_cards1.status_code == 200

        response_discard1 = discard(minister_index)
        assert response_discard1.status_code == 201

        response_get_cards2 = get_cards(director_index)
        assert response_get_cards2.status_code == 200

        response_discard2 = discard(director_index)
        assert response_discard2.status_code == 201

        response_post_proclamation = get_game_state()

        assert response_post_proclamation.status_code == 200
        scores_state: dict = response_post_proclamation.json()

        response_cast_crucio = cast_crucio(minister_index, minister_index)

        de_score = scores_state["de_procs"]

        if (de_score == 2 and first):
            # print(response_cast_crucio.status_code)
            assert response_cast_crucio.status_code == 406
            first = False

        else:
            # print(response_cast_crucio.status_code)
            assert (response_cast_crucio.status_code == 400
                    or response_cast_crucio.status_code == 405)

        confirm = confirm_crucio(minister_index)