async def test_write_rating_progress_other_rating( ladder_service: LadderService, player_factory): player = player_factory(ladder_rating=(1500, 500), global_rating=(1500, 400.1235)) player.write_message = CoroutineMock() # There's no reason we would call it with global, but the logic is the same # and global is an available rating that's not ladder ladder_service.write_rating_progress(player, RatingType.GLOBAL) player.write_message.assert_called_once() assert player.write_message.call_args[0][0].get("command") == "notice" assert player.write_message.call_args[0][0].get("style") == "info" assert "40%" in player.write_message.call_args[0][0].get("text", "")
async def test_start_game_called_on_match(ladder_service: LadderService, player_factory): p1 = player_factory( "Dostya", player_id=1, ladder_rating=(2300, 64), ladder_games=0, with_lobby_connection=True ) p2 = player_factory( "QAI", player_id=2, ladder_rating=(2350, 125), ladder_games=0, with_lobby_connection=True ) ladder_service.start_game = CoroutineMock() ladder_service.write_rating_progress = CoroutineMock() ladder_service.start_search([p1], "ladder1v1") ladder_service.start_search([p2], "ladder1v1") await asyncio.sleep(2) ladder_service.write_rating_progress.assert_called() ladder_service.start_game.assert_called_once()
async def test_write_rating_progress_message_2( ladder_service: LadderService, player_factory ): player = player_factory(ladder_rating=(1500, 400.1235)) player.write_message = CoroutineMock() ladder_service.write_rating_progress(player, RatingType.LADDER_1V1) player.write_message.assert_called_once_with({ "command": "notice", "style": "info", "text": ( "The system is still learning you.<b><br><br>" "The learning phase is 40% complete<b>" ) })
async def test_write_rating_progress_message(ladder_service: LadderService, player_factory): player = player_factory(ladder_rating=(1500, 500)) player.write_message = CoroutineMock() ladder_service.write_rating_progress(player, RatingType.LADDER_1V1) player.write_message.assert_called_once_with({ "command": "notice", "style": "info", "text": ("<i>Welcome to the matchmaker</i><br><br><b>Until " "you've played enough games for the system to learn " "your skill level, you'll be matched randomly.</b><br>" "Afterwards, you'll be more reliably matched up with " "people of your skill level: so don't worry if your " "first few games are uneven. This will improve as you " "play!</b>") })
async def test_write_rating_progress_other_rating( ladder_service: LadderService, player_factory ): player = player_factory( ladder_rating=(1500, 500), global_rating=(1500, 400.1235) ) player.write_message = CoroutineMock() # There's no reason we would call it with global, but the logic is the same # and global is an available rating that's not ladder ladder_service.write_rating_progress(player, RatingType.GLOBAL) player.write_message.assert_called_once_with({ "command": "notice", "style": "info", "text": ( "The system is still learning you.<b><br><br>" "The learning phase is 40% complete<b>" ) })
async def test_write_rating_progress(ladder_service: LadderService, player_factory): p1 = player_factory("Dostya", player_id=1, ladder_rating=(1500, 500), with_lobby_connection=True) ladder_service.write_rating_progress(p1, RatingType.LADDER_1V1) # Message is sent after the first call p1.lobby_connection.write.assert_called_once() ladder_service.write_rating_progress(p1, RatingType.LADDER_1V1) p1.lobby_connection.write.reset_mock() # But not after the second p1.lobby_connection.write.assert_not_called() ladder_service.on_connection_lost(p1.lobby_connection) ladder_service.write_rating_progress(p1, RatingType.LADDER_1V1) # But it is called if the player relogs p1.lobby_connection.write.assert_called_once()