def test_inform_player(ladder_service: LadderService): p1 = mock.create_autospec(Player('Dostya', id=1)) p1.ladder_rating = (1500, 500) ladder_service.inform_player(p1) # Message is sent after the first call p1.lobby_connection.sendJSON.assert_called_once() ladder_service.inform_player(p1) p1.lobby_connection.sendJSON.reset_mock() # But not after the second p1.lobby_connection.sendJSON.assert_not_called() ladder_service.on_connection_lost(p1) ladder_service.inform_player(p1) # But it is called if the player relogs p1.lobby_connection.sendJSON.assert_called_once()
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()