示例#1
0
def test_GameForm_process_chat_message(initpatch):
    form = GameForm()

    form.widgets = {"message": Mock()}
    form.widgets["message"].value = None
    form.widgets["message"].height = 100

    state = tests.create_default_gamestate(nb_messages=0)
    form.parentApp = Mock(state=state)

    form.process_chat_message()

    assert form.widgets["message"].value is None

    state = tests.create_default_gamestate(nb_messages=4)
    form.parentApp.state = state

    form.process_chat_message()
    messages = form.widgets["message"].value.split("\n")
    assert len(messages) == 4

    form.widgets["message"].height = 4
    form.process_chat_message()
    messages = form.widgets["message"].value.split("\n")
    assert len(messages) == 2
示例#2
0
def test_WaitingForm_while_waiting(displaypatch, initpatch):
    form = WaitingForm()
    form.widgets = {"text": Mock(), "players": Mock()}
    form.ok_button = Mock()

    state = tests.create_default_gamestate(nb_players=4)
    state.room.status = "WAITING"
    form.parentApp = Mock(state=state)

    form.while_waiting()

    assert "roomname" in form.widgets["text"].value
    players = form.widgets["players"].values
    assert len(players) == 4 and players == ["name0", "name1", "name2", "name3"]
    assert form.ok_button.hidden is True
    displaypatch.assert_called_once_with()

    state.room.status = "PLAYING"
    displaypatch.reset_mock()
    form.while_waiting()

    form.parentApp.switchForm.assert_called_once_with("GAME")
    assert form.ok_button.hidden is True

    state.room.status = "READY"
    form.while_waiting()

    assert form.ok_button.hidden is False
示例#3
0
def test_GameForm_process_player_state(utilspatch, initpatch):
    form = GameForm()
    form.widgets = {"cards_user": Mock(), "cut": Mock()}

    state = tests.create_default_gamestate(nb_players=4, ind_me=2, ind_cutter=1)
    state.me.team = "Moriarty"
    state.me.hand = ["A", "B", "C"]
    form.parentApp = Mock(state=state)

    form.process_player_state()

    utilspatch.assert_called_once_with(["A", "B", "C"])
    assert form.widgets["cards_user"].value == "deck"
    assert form.color == "DANGER"
    assert form.widgets["cut"].hidden is True
    assert form.name == "Time Bomb ── name2 ── Team Moriarty"

    state.me.team = "Sherlock"
    utilspatch.reset_mock()
    form.process_player_state()

    utilspatch.assert_called_once_with(["A", "B", "C"])
    assert form.color == "NO_EDIT"
    assert form.name == "Time Bomb ── name2 ── Team Sherlock"

    state.room.cutter.id = "id2"
    form.process_player_state()
    assert form.widgets["cut"].hidden is False
示例#4
0
def test_NotifForm_on_ok(initpatch):
    form = NotifForm()
    state = tests.create_default_gamestate()
    form.parentApp = Mock(state=state)
    assert not state.notification.read

    form.on_ok()
    assert state.notification.read
    form.parentApp.setNextFormPrevious.assert_called_once_with()
示例#5
0
def test_CutForm_get_targets(initpatch):
    form = CutForm()

    state = tests.create_default_gamestate(nb_players=3, ind_me=1)
    form.parentApp = Mock(state=state)

    targets = form.get_targets()

    assert (len(targets) == 2 and targets[0] == state.room.players[0]
            and targets[1] == state.room.players[2])
示例#6
0
def test_NotifForm_while_waiting(initpatch):
    form = NotifForm()
    form.text = Mock()

    state = tests.create_default_gamestate()
    form.parentApp = Mock(state=state)
    assert state.notification.content == "notif"

    form.while_waiting()
    assert form.text.value == "notif"
    form.text.update.assert_called_once_with()
示例#7
0
def test_LoginForm_while_waiting(initpatch):
    form = LoginForm()
    state = tests.create_default_gamestate()
    form.parentApp = Mock(state=state)

    form.while_waiting()
    form.parentApp.switchForm.assert_called_once_with("WAIT")

    state.room = None
    form.parentApp.switchForm.reset_mock()
    form.while_waiting()
    form.parentApp.switchForm.assert_not_called()
示例#8
0
def test_GameForm_cut_pressed(initpatch):
    form = GameForm()

    state = tests.create_default_gamestate(nb_players=4, ind_me=1, ind_cutter=0)
    form.parentApp = Mock(state=state)

    form.cut_pressed()
    form.parentApp.switchForm.assert_not_called()

    state.room.cutter.id = "id1"
    form.cut_pressed()
    form.parentApp.switchForm.assert_called_once_with("CUT")
示例#9
0
def test_CutForm_on_ok(self):
    form = CutForm()
    form.parentApp = Mock()
    form.widgets = {"players": Mock(value=[])}

    state = tests.create_default_gamestate(nb_players=2)
    form.get_targets = Mock(return_value=state.room.players)

    form.on_ok()

    form.parentApp.sio.cut.assert_not_called()
    form.parentApp.switchForm.assert_not_called()

    form.widgets = {"players": Mock(value=[1])}
    form.on_ok()

    form.parentApp.sio.cut.assert_called_once_with("id1")
    form.parentApp.switchForm.assert_called_once_with("GAME")
示例#10
0
def test_CutForm_while_waiting(initpatch):
    form = CutForm()
    state = tests.create_default_gamestate(nb_players=1)
    form.widgets = {"players": Mock(values=[])}
    form.get_targets = Mock(return_value=state.room.players)

    form.while_waiting()

    form.get_targets.assert_not_called()
    form.widgets["players"].update.assert_not_called()

    form.widgets = {"players": Mock(values=None)}
    form.while_waiting()

    form.get_targets.assert_called()
    form.widgets["players"].update.assert_called()

    values = form.widgets["players"].values
    assert len(values) == 1 and values[0] == "name0"
示例#11
0
def test_GameForm_process_room_state(utilspatch, initpatch):
    form = GameForm()
    form.widgets = {
        k: Mock() for k in ["players", "cards_found", "cards_left", "round"]
    }

    state = tests.create_default_gamestate(nb_players=4, ind_cutter=1)
    state.room.cards_found = {"A": 10}
    state.room.cards_left = {"B": 10}

    form.parentApp = Mock(state=state)

    utilspatch.summary_deck = lambda x: str(x)
    utilspatch.round_bar = lambda *x: str(x)

    form.process_room_state()

    assert form.widgets["players"].name == "Players [4]"
    assert form.widgets["players"].values == ["name0", "name1 [cut]", "name2", "name3"]

    assert form.widgets["cards_found"].value == "{'A': 10}"
    assert form.widgets["cards_left"].value == "{'B': 10}"
    assert form.widgets["round"].value == "(4, 10, 10)"
示例#12
0
def test_EndForm_while_waiting(displaypatch, initpatch):
    form = EndForm()
    form.widgets = {
        "text": Mock(),
        "team_moriarty": Mock(),
        "team_sherlock": Mock()
    }

    state = tests.create_default_gamestate(nb_players=4)
    for i, role in enumerate(["Moriarty", "Moriarty", "Sherlock", "Sherlock"]):
        state.room.players[i].team = role
    state.room.winning_team = None
    form.parentApp = Mock(state=state)

    form.while_waiting()

    displaypatch.assert_called_once_with()
    assert form.widgets["text"].value
    team_moriarty = form.widgets["team_moriarty"].values
    team_sherlock = form.widgets["team_sherlock"].values
    assert len(team_moriarty) == 2 and team_moriarty == ["name0", "name1"]
    assert len(team_sherlock) == 2 and team_sherlock == ["name2", "name3"]

    state.room.winning_team = ("Reason", "Moriarty")
    state.room.players[3].team = "Moriarty"
    displaypatch.reset_mock()
    form.while_waiting()

    displaypatch.assert_called_once_with()
    assert ("Reason" in form.widgets["text"].value
            and "Moriarty" in form.widgets["text"].value)
    team_moriarty = form.widgets["team_moriarty"].values
    team_sherlock = form.widgets["team_sherlock"].values
    assert len(team_moriarty) == 3 and team_moriarty == [
        "name0", "name1", "name3"
    ]
    assert len(team_sherlock) == 1 and team_sherlock == ["name2"]