示例#1
0
def test_host_client_socket_team_event_ok(socketio_test_client, mocker):
    mock_socketio_emit = mocker.patch("qwazzock.server.SocketIO.emit")
    game = Game()
    game.locked_out_teams = []
    socketio_test_client_under_test = socketio_test_client(game)
    socketio_test_client_under_test.connect(namespace="/host_client_socket")
    socketio_test_client_under_test.emit(
        "team", {"team_name": "Oxford"}, namespace="/host_client_socket"
    )
    assert game.locked_out_teams == ["Oxford"]
示例#2
0
def test_host_client_socket_wrong_event_ok(socketio_test_client, mocker):
    mock_socketio_emit = mocker.patch("qwazzock.server.SocketIO.emit")
    game = Game()
    game.team_in_hotseat = "Oxford"
    socketio_test_client_under_test = socketio_test_client(game)
    socketio_test_client_under_test.connect(namespace="/host_client_socket")
    socketio_test_client_under_test.emit(
        "wrong", {"wrong_answer_penalty": 3}, namespace="/host_client_socket"
    )
    assert len(mock_socketio_emit.mock_calls) == 4
示例#3
0
def test_host_client_socket_right_event_ok(socketio_test_client, mocker):
    mock_socketio_emit = mocker.patch("qwazzock.server.SocketIO.emit")
    game = Game()
    game.team_in_hotseat = "Oxford"
    socketio_test_client_under_test = socketio_test_client(game)
    socketio_test_client_under_test.connect(namespace="/host_client_socket")
    socketio_test_client_under_test.emit(
        "right", {"score_value": 1}, namespace="/host_client_socket"
    )
    assert len(mock_socketio_emit.mock_calls) == 4
示例#4
0
def test_host_client_socket_picture_event_no_images(socketio_test_client, mocker):
    mock_socketio_emit = mocker.patch("qwazzock.server.SocketIO.emit")
    game = Game()
    game.question_type = "foo"
    game.selected_image_index = None
    socketio_test_client_under_test = socketio_test_client(game)
    socketio_test_client_under_test.connect(namespace="/host_client_socket")
    socketio_test_client_under_test.emit(
        namespace="/host_client_socket", event="picture"
    )
    assert game.question_type == "foo"
示例#5
0
def test_host_client_socket_pass_event_ok(socketio_test_client, mocker):
    mock_socketio_emit = mocker.patch("qwazzock.server.SocketIO.emit")
    game = Game()
    socketio_test_client_under_test = socketio_test_client(game)
    socketio_test_client_under_test.connect(namespace="/host_client_socket")
    socketio_test_client_under_test.emit(namespace="/host_client_socket", event="pass")
    assert len(mock_socketio_emit.mock_calls) == 4
示例#6
0
 def test_game_reset_ok(self):
     game = Game()
     game.player_in_hotseat = "Bob"
     game.team_in_hotseat = "Oxford"
     game.locked_out_teams = ["Bristol"]
     game.scores = {"Oxford": 1, "Cambridge": 3}
     game.reset()
     assert game.player_in_hotseat == "Pending"
     assert game.team_in_hotseat == "Pending"
     assert game.locked_out_teams == []
     assert game.scores == {}
示例#7
0
def test_player_client_socket_buzz_event_ok(socketio_test_client, mocker):
    mock_socketio_emit = mocker.patch("qwazzock.server.SocketIO.emit")
    game = Game()
    socketio_test_client_under_test = socketio_test_client(game)
    socketio_test_client_under_test.connect(namespace="/player_client_socket")
    socketio_test_client_under_test.emit(
        "buzz",
        {"player_name": "foo-name", "team_name": "foo-team"},
        namespace="/player_client_socket",
    )
    assert len(mock_socketio_emit.mock_calls) == 4
示例#8
0
 def test_game_next_question_ok(self, mocker):
     mocker.patch("qwazzock.Game.prepare_picture_round")
     game = Game()
     game.question_type = "picture"
     game.selected_image_index = 1
     game.question_images = ["foo.jpg", "bar.png", "blah.bmp"]
     game.next_question()
     assert game.selected_image_index == 2
     assert game.selected_image == "blah.bmp"
     assert game.question_type == "picture"
示例#9
0
 def test_game_wrong_answer_ok(self, mocker):
     mock_clear_hotseat = mocker.patch("qwazzock.Game.clear_hotseat")
     game = Game()
     game.team_in_hotseat = "Oxford"
     game.scores = {"Oxford": 1, "Cambridge": 3}
     game.locked_out_teams = ["Bristol"]
     game.wrong_answer(wrong_answer_penalty=2)
     assert game.scores == {"Oxford": -1, "Cambridge": 3}
     assert game.locked_out_teams == ["Bristol", "Oxford"]
     assert len(mock_clear_hotseat.mock_calls) == 2
示例#10
0
 def test_game_next_question_no_more_images(self, mocker):
     mock_prepare_picture_round = mocker.patch(
         "qwazzock.Game.prepare_picture_round")
     game = Game()
     game.question_type = "picture"
     game.selected_image_index = 2
     game.question_images = ["foo.jpg", "bar.png", "blah.bmp"]
     game.next_question()
     assert game.question_type == "standard"
     assert len(mock_prepare_picture_round.mock_calls) == 2
示例#11
0
 def test_game_clear_hotseat_ok(self):
     game = Game()
     game.player_in_hotseat = "Bob"
     game.team_in_hotseat = "Oxford"
     game.clear_hotseat()
     assert game.player_in_hotseat == "Pending"
     assert game.team_in_hotseat == "Pending"
示例#12
0
 def test_game_right_answer_ok(self, mocker):
     mock_clear_hotseat = mocker.patch("qwazzock.Game.clear_hotseat")
     game = Game()
     game.team_in_hotseat = "Oxford"
     game.scores = {"Oxford": 1, "Cambridge": 3}
     game.right_answer(5)
     assert game.scores == {"Oxford": 6, "Cambridge": 3}
     assert len(mock_clear_hotseat.mock_calls) == 2
示例#13
0
 def test_game_update_hotseat_ok(self):
     game = Game()
     game.update_hotseat(player_name="Bob", team_name="Oxford")
     assert game.player_in_hotseat == "Bob"
     assert game.team_in_hotseat == "Oxford"
示例#14
0
 def test_game_update_hotseat_trailing_spaces(self):
     game = Game()
     game.update_hotseat(player_name="Bob ", team_name="My Team  ")
     assert game.player_in_hotseat == "Bob"
     assert game.team_in_hotseat == "My Team"
示例#15
0
 def test_game_update_hotseat_locked_out(self):
     game = Game()
     game.locked_out_teams = ["Oxford"]
     game.update_hotseat(player_name="Bob", team_name="Oxford")
     assert game.team_in_hotseat == "Pending"
示例#16
0
 def test_game_prepare_picture_round_no_files(self, mocker):
     mock_os_listdir = mocker.patch("os.listdir")
     mock_os_listdir.return_value = []
     game = Game(content_path="/foo-content-path")
     assert game.selected_image_index is None
示例#17
0
 def test_game_init_ok(self, mocker):
     mock_clear_hotseat = mocker.patch("qwazzock.Game.clear_hotseat")
     game = Game()
     mock_clear_hotseat.assert_called_once()
示例#18
0
 def test_game_prepare_picture_round_ok(self, mocker):
     mock_os_listdir = mocker.patch("os.listdir")
     mock_os_listdir.return_value = ["foo.jpg", "bar.png", "blah.bmp"]
     game = Game(content_path="/foo-content-path")
     assert "bar.png" in game.question_images
     assert game.selected_image_index == 0