コード例 #1
0
def test_kill_input():
    good_kill_msg = {"text": "!kill nick", "user": "******"}
    no_target_msg = {"text": "!kill", "user": "******"}
    too_many_targets_msg = {"text": "!kill you me and this", "user": "******"}
    invalid_target_msg = {"text": "!kill yolo", "user": "******"}
    not_wolf_msg = {"text": "!kill not_nick", "user": "******"}

    night_g = get_fake_game_state()

    setup_users(night_g)
    message = app.process_message(too_many_targets_msg, g=night_g)
    assert message == "Not a valid command."

    message = app.process_message(no_target_msg, g=night_g)
    assert message == "Not a valid command."

    message = app.process_message(invalid_target_msg, g=night_g)
    assert message == "User not in the game."

    message = app.process_message(not_wolf_msg, g=night_g)
    assert message == "Not allowed."

    message_str = app.process_message(good_kill_msg, g=night_g)
    message_list = message_str.split("\n")
    assert message_list[0] == "nick was eaten."

    tear_down()
コード例 #2
0
def test_vote_user_not_in_game_input():
    fake_message = {"text": "!vote cd", "user": "******"}
    night_g = get_fake_game_state()
    setup_users(night_g)
    message = app.process_message(fake_message, g=night_g)
    assert message == "User not in the game."

    tear_down()
コード例 #3
0
def test_no_vote_target_input():
    fake_message = {"text": "!vote", "user": "******"}
    night_g = get_fake_game_state()
    setup_users(night_g)
    result = app.process_message(fake_message, g=night_g)
    assert result == "Not a valid command."

    tear_down()
コード例 #4
0
def test_basic_input():
    fake_message = {"text": "sup noob", "user": "******"}
    night_g = get_fake_game_state()
    result = app.process_message(fake_message, night_g)

    assert result == None

    tear_down()
コード例 #5
0
def test_night_vote_input():
    fake_message = {"text": "!vote not_nick", "user": "******"}
    night_g = get_fake_game_state()

    setup_users(night_g)
    message = app.process_message(fake_message, g=night_g)
    assert message == "It is not day."

    tear_down()
コード例 #6
0
def test_day_voting_input():
    fake_message = {"text": "!vote not_nick", "user": "******"}
    user_name = "nick"
    target_name = "not_nick"

    day_g = get_fake_game_state()
    day_g["ROUND"] = "day"
    setup_users(day_g)

    assert day_g["votes"] == {}

    message = app.process_message(fake_message, g=day_g)
    assert day_g["votes"] == {}  # shouldn't mutate day_g

    assert message == user_name + " voted for " + target_name
    new_day_g = get_game_state()
    assert new_day_g["votes"] == {"ab": "cd"}  # now it should be mutated

    # shouldn't be allowed to vote again.
    fake_message = {"text": "!vote not_nick", "user": "******"}
    message = app.process_message(fake_message, g=new_day_g)
    assert message == "You have already voted."

    tear_down()
コード例 #7
0
def test_reset_game():
    g = all_vote_but_one_state()
    setup_users(g)

    vote_lock_msg = {"text": "!vote nick", "user": "******"}
    # g has all votes except for "cd" vote
    # "cd" is werewolf once he locks vote, game should be
    # over for the village.

    message_str = app.process_message(vote_lock_msg, g=g)
    message_list = message_str.split("\n")

    assert message_list == "not_nick was lynched."

    new_g = get_game_state()
    print(new_g)
    assert new_g["STATUS"] == "INACTIVE"
    assert new_g["votes"] == {}
    assert new_g["players"] == {}
    assert new_g["ROUND"] == None

    tear_down()