def test_game_session_admin_kick_last(clean_database, flask_app, mocker): mock_emit = mocker.patch("flask_socketio.emit") user = database.User.create(id=1234, discord_id=5678, name="The Name") sio = MagicMock() sio.get_current_user.return_value = user game_session.create_game_session(sio, "My Room") session = database.GameSession.get_by_id(1) database.GameSessionTeamAction.create(session=session, provider_row=0, provider_location_index=0, receiver_row=0, time=datetime.datetime(2020, 5, 2, 10, 20, tzinfo=datetime.timezone.utc)) # Run with flask_app.test_request_context(): game_session.game_session_admin_player(sio, 1, 1234, SessionAdminUserAction.KICK.value, None) # Assert for table in [database.GameSession, database.GameSessionPreset, database.GameSessionMembership, database.GameSessionTeamAction]: assert list(table.select()) == [] assert database.User.get_by_id(1234) == user mock_emit.assert_called_once_with( 'game_session_update', {'id': 1, 'name': 'My Room', 'state': 'setup', 'players': [], 'presets': [], 'actions': [], 'spoiler': None, 'word_hash': None, 'seed_hash': None, 'permalink': None, 'generation_in_progress': None}, room='game-session-1')
def test_create_game_session(clean_database, preset_manager): # Setup user = database.User.create(id=1234, discord_id=5678, name="The Name") sio = MagicMock() sio.get_current_user.return_value = user # Run result = game_session.create_game_session(sio, "My Room") # Assert session = database.GameSession.get(1) assert session.name == "My Room" assert result == { 'id': 1, 'state': GameSessionState.SETUP.value, 'name': 'My Room', 'players': [{'admin': True, 'id': 1234, 'name': 'The Name', 'row': 0, 'inventory': None, 'connection_state': 'Online, Unknown'}], 'presets': [preset_manager.default_preset.as_json], 'actions': [], 'seed_hash': None, 'spoiler': None, 'word_hash': None, 'permalink': None, 'generation_in_progress': None, }