class TestClient(unittest.TestCase): client: 'APIClient' = None token = get_token_from_config(section='amasend') @async_test def test__01__initialize__setup_APIClient__all_parameters_set_correctly( self) -> None: TestClient.client = APIClient(token=self.token, loop=asyncio.get_event_loop()) self.assertIsInstance(self.client._client, BaseClient, msg="BaseClient incorrectly set.") self.assertIsInstance(self.client.account, Account, msg="Account incorrectly set.") self.assertIsInstance(self.client.broadcast, Broadcast, msg="Broadcast incorrectly set.") self.assertIsInstance(self.client.challenges, Challenges, msg="Challenges incorrectly set.") self.assertIsInstance(self.client.chess_bot, ChessBot, msg="ChessBot incorrectly set.") self.assertIsInstance(self.client.games, Games, msg="Games incorrectly set.") self.assertIsInstance(self.client.messaging, Messaging, msg="Messaging incorrectly set.") self.assertIsInstance(self.client.relations, Relations, msg="Relations incorrectly set.") self.assertIsInstance(self.client.simulations, Simulations, msg="Simulations incorrectly set.") self.assertIsInstance(self.client.studies, Studies, msg="Studies incorrectly set.") self.assertIsInstance(self.client.teams, Teams, msg="Teams incorrectly set.") self.assertIsInstance(self.client.tournaments, Tournaments, msg="Tournaments incorrectly set.") self.assertIsInstance(self.client.users, Users, msg="Users incorrectly set.") self.assertIsInstance(self.client.bots, Bots, msg="Bots incorrectly set.") self.assertIsInstance(self.client.boards, Boards, msg="Boards incorrectly set.")
class TestChallengesEndpoint(unittest.TestCase): client = None token = get_token_from_config('amasend') @classmethod def setUp(cls) -> None: cls.client = APIClient(token=cls.token) @unittest.SkipTest @async_test async def test_01__create_a_challenge__sent_challenge_invitation__response_object_returned_with_success( self): response = await self.client.challenges.create(username='******') print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @unittest.SkipTest @async_test async def test_02__accept_a_challenge__accepting_a_challenge__response_object_returned_with_success( self): response = await self.client.challenges.accept(username='******') print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @unittest.SkipTest @async_test async def test_03__decline_a_challenge__declining_a_challenge__response_object_returned_with_success( self): response = await self.client.challenges.decline(username='******') print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.")
class TestSimulationsEndpoint(unittest.TestCase): client = None token = get_token_from_config('amasend') @classmethod def setUp(cls) -> None: cls.client = APIClient(token=cls.token) @async_test async def test_01__get_current__fetching_current_simulations__response_object_returned_with_success( self): response = await self.client.simulations.get_current() print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.")
class TestMessagesEndpoint(unittest.TestCase): client = None token = get_token_from_config('amasend') @classmethod def setUp(cls) -> None: cls.client = APIClient(token=cls.token) @async_test async def test_01__send__sending_a_message__response_object_returned_with_success( self): response = await self.client.messaging.send(username="******", text="hi there!") print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.")
class TestBotsEndpoint(unittest.TestCase): client = None token = get_token_from_config('connector_123') @classmethod def setUp(cls) -> None: cls.client = APIClient(token=cls.token) @unittest.SkipTest @async_test async def test_01__stream_incoming_events__fetching_information_about_incoming_game__response_object_returned_with_success( self): response = await self.client.bots.stream_incoming_events() print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.")
class TestBaseClient(unittest.TestCase): event_loop = None client: 'BaseClient' = None token = get_token_from_config(section='amasend') @classmethod def setUp(cls) -> None: cls.event_loop = asyncio.get_event_loop() @async_test async def test_01__initialization__init_of_BaseClient_class__all_arguments_stored( self): TestBaseClient.client = BaseClient(token=self.token, loop=self.event_loop) self.assertEqual(self.client._token, self.token, msg="Token incorrectly stored.") self.assertEqual(self.client.loop, self.event_loop, msg="Event loop incorrectly stored.") @async_test async def test_02__is_authorized__check_if_async_request_works__authorized( self): response = await self.client.is_authorized() self.assertTrue(response, msg="Not authorized.") @unittest.expectedFailure @async_test async def test_03__is_authorized__check_if_async_request_works__not_authorized( self): client = BaseClient(token="not_so_random_characters", loop=self.event_loop) response = await client.is_authorized() self.assertTrue(response, msg="Not authorized.")
class TestStudiesEndpoint(unittest.TestCase): client = None token = get_token_from_config('amasend') study_id = "IeZmXDxM" chapter_id = "gTHhjLX4" @classmethod def setUp(cls) -> None: cls.client = APIClient(token=cls.token) @async_test async def test_01__export_chapter__downloading_one_study_chapter__response_object_returned_with_success( self): response = await self.client.studies.export_chapter( study_id=self.study_id, chapter_id=self.chapter_id) print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @async_test async def test_02__export_all_chapters__downloading_a_study__response_object_returned_with_success( self): response = await self.client.studies.export_all_chapters( study_id=self.study_id) print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.")
class TestAccountEndpoint(unittest.TestCase): client = None token = get_token_from_config('amasend') @classmethod def setUp(cls) -> None: cls.client = APIClient(token=cls.token) @async_test async def test_01__get_my_profile__fetching_profile_info__response_object_returned_with_success( self): response = await self.client.account.get_my_profile() print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @async_test async def test_02__get_my_email_address__fetching_email__response_object_returned_with_success( self): response = await self.client.account.get_my_email_address() print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @async_test async def test_03__get_my_preferences__fetching_preferences__response_object_returned_with_success( self): response = await self.client.account.get_my_preferences() print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @async_test async def test_04__get_my_kid_mode_status__fetching_kid_status__response_object_returned_with_success( self): response = await self.client.account.get_my_kid_mode_status() print(response.metadata.timestamp) print(response.entity.content) print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @async_test async def test_05__set_my_kid_mode_status__setting_kid_status__response_object_returned_with_success( self): response_1 = await self.client.account.set_my_kid_mode_status( turned_on=True) time.sleep(2) response_2 = await self.client.account.get_my_kid_mode_status() print(f"Setting kid mode: {response_1}") print(f"Kid mode set to: {response_2.entity.content['kid']}") self.assertIsInstance(response_1, Response, msg="Response in not of type \"Response\"") self.assertEqual(response_1.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") self.assertTrue(response_2.entity.content['kid'], msg="Kid mode status was not set correctly.") await self.client.account.set_my_kid_mode_status(turned_on=False) time.sleep(2) response_3 = await self.client.account.get_my_kid_mode_status() print(f"Kid mode set to: {response_3.entity.content['kid']}")
class TestBoardsEndpoint(unittest.TestCase): client = None token = get_token_from_config('amasend') game_id = 'IxJ26EAH' @classmethod def setUp(cls) -> None: cls.client = APIClient(token=cls.token) @unittest.SkipTest @async_test async def test_01__stream_incoming_events__fetching_information_about_incoming_game__response_object_returned_with_success(self): async for response in self.client.boards.stream_incoming_events(): print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @unittest.SkipTest @async_test async def test_02__create_a_seek__seeking_the_game__response_object_returned_with_success(self): response = await self.client.boards.create_a_seek(time=15, increment=15, rated=True) print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @unittest.SkipTest @async_test async def test_03__stream_game_state__fetching_current_game_state__response_object_returned_with_success(self): async for response in self.client.boards.stream_game_state(game_id=self.game_id): print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @unittest.SkipTest @async_test async def test_04__make_move__send_a_move__response_object_returned_with_success(self): response = await self.client.boards.make_move(game_id=self.game_id, move='g8f6') print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @unittest.SkipTest @async_test async def test_05__abort_game__aborting_a_game__response_object_returned_with_success(self): response = await self.client.boards.abort_game(game_id=self.game_id) print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @unittest.SkipTest @async_test async def test_06__resign_game__resigning_a_game__response_object_returned_with_success(self): response = await self.client.boards.resign_game(game_id=self.game_id) print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @unittest.SkipTest @async_test async def test_07__write_in_chat__posting_user_message__response_object_returned_with_success(self): response = await self.client.boards.write_in_chat(game_id=self.game_id, message="Hello!") print(response) from lichess_client.utils.enums import RoomTypes response = await self.client.boards.write_in_chat(game_id=self.game_id, message="Hi all!", room=RoomTypes.SPECTATOR) print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.")
class TestBroadcastEndpoint(unittest.TestCase): client = None token = get_token_from_config('amasend') broadcast_id = None games = None @classmethod def setUp(cls) -> None: cls.client = APIClient(token=cls.token) @async_test async def test_01__create__broadcast_creation__response_object_returned_with_success( self): response = await self.client.broadcast.create( name="Test broadcast", description="This is desc.") print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") TestBroadcastEndpoint.broadcast_id = response.entity.content[ 'broadcast']['id'] @async_test async def test_02__get__get_info_about_created_broadcast__response_object_returned_with_success( self): response = await self.client.broadcast.get( broadcast_id=self.broadcast_id) print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @unittest.SkipTest @async_test async def test_03__update__updating_broadcast__response_object_returned_with_success( self): response = await self.client.broadcast.update( broadcast_id=self.broadcast_id, name="Updated broadcast", description="Ohh a new description!") print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @async_test async def test_04__push_pgn__pushing_games_info__response_object_returned_with_success( self): response = await self.client.broadcast.push_pgn( broadcast_id=self.broadcast_id, games=self.games) print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.")
class TestAccountEndpoint(unittest.TestCase): client = None token = get_token_from_config('amasend') @classmethod def setUp(cls) -> None: cls.client = APIClient(token=cls.token) @async_test async def test_01__export_one_game__fetching_finished_game_details__response_object_returned_with_success( self): response = await self.client.games.export_one_game(game_id='j5wCnxuX') print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") self.assertIsInstance(response.entity.content, Game, msg="Game was incorrectly loaded.") @async_test async def test_02__export_user_games__fetching_finished_user_games_details__response_object_returned_with_success( self): response = await self.client.games.export_games_of_a_user( username='******') print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") # TODO: add more tests for export_user_games with different parameters @async_test async def test_03__export_games_by_ids__fetching_list_of_games__response_object_returned_with_success( self): response = await self.client.games.export_games_by_ids( game_ids=['q7zvsdUF', 'ILwozzRZ', '4OtIh2oh']) print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @unittest.expectedFailure @async_test async def test_04__stream_current_games__fetching_list_of_games__response_object_returned_with_success( self): response = await self.client.games.stream_current_games( users=['amasend', 'ProfessorOak15']) print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @async_test async def test_05__get_ongoing_games__fetching_list_of_games__response_object_returned_with_success( self): response = await self.client.games.get_ongoing_games(limit=2) print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @async_test async def test_06__get_current_tv_games__fetching_list_of_games__response_object_returned_with_success( self): response = await self.client.games.get_current_tv_games() print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.")
class TestTeamsEndpoint(unittest.TestCase): client = None token = get_token_from_config('amasend') @classmethod def setUp(cls) -> None: cls.client = APIClient(token=cls.token) @unittest.expectedFailure @async_test async def test_01__get_members_of_a_team__fetching_team_members__not_implemented_raises( self): response = await self.client.teams.get_members_of_a_team() self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @unittest.expectedFailure @async_test async def test_02__join_a_team__joining_to_a_team__response_object_returned_with_success( self): response = await self.client.teams.join_a_team(team_id='some_team') print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @unittest.expectedFailure @async_test async def test_03__leave_a_team__leaving_a_team__response_object_returned_with_success( self): response = await self.client.teams.leave_a_team(team_id='some_team') print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @unittest.expectedFailure @async_test async def test_04__kick_a_user_from_your_team__kicking_user_from_team__response_object_returned_with_success( self): response = await self.client.teams.kick_a_user_from_your_team( team_id='some_team', user_id='amasend') print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.")
class TestTournamentsEndpoint(unittest.TestCase): client = None token = get_token_from_config('amasend') @classmethod def setUp(cls) -> None: cls.client = APIClient(token=cls.token) @unittest.SkipTest @async_test async def test_01__get_current__fetching_current_tournament_info__response_object_returned_with_success( self): response = await self.client.tournaments.get_current() print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @unittest.SkipTest @async_test async def test_02__create__posting_a_tournament__response_object_returned_with_success( self): response = await self.client.tournaments.create(clock_time=1, clock_increment=1, minutes=60) print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @async_test async def test_03__export_games__download_tournament_games_info__response_object_returned_with_success( self): response = await self.client.tournaments.export_games( tournament_id='QITRjufu') print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @async_test async def test_04__get_results__download_tournament_results__response_object_returned_with_success( self): response = await self.client.tournaments.get_results( tournament_id='QITRjufu') print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.") @async_test async def test_05__get_tournaments_created_by_a_user__download_details__response_object_returned_with_success( self): response = await self.client.tournaments.get_tournaments_created_by_a_user( username='******') print(response) self.assertIsInstance(response, Response, msg="Response in not of type \"Response\"") self.assertEqual(response.entity.status, StatusTypes.SUCCESS, msg="Request was unsuccessful.")