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"]
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
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
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"
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
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 == {}
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
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"
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
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
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"
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
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"
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"
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"
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
def test_game_init_ok(self, mocker): mock_clear_hotseat = mocker.patch("qwazzock.Game.clear_hotseat") game = Game() mock_clear_hotseat.assert_called_once()
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