diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 09c6d9e..400a1e1 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.11", "3.10", "3.9", "3.8"] + python-version: ["3.11", "3.10"] steps: - uses: actions/checkout@v3 diff --git a/README.md b/README.md index 1492a70..05be1e0 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ password of the ClashOfClans developer portal - Control over the number of requests per second and the number of used tokens - Open source - Type hinted - - Sopports Python 3.8 -> 3.11 + - Supports Python 3.8 -> 3.11 --- @@ -58,7 +58,6 @@ I'm planning to keep the API wrapper up to date and improve it as good as I can. ### Planned features - more bulk requests -- pytests for the models - events ### Planned utils diff --git a/pyclasher/api/bulk_requests/__init__.py b/pyclasher/api/bulk_requests/__init__.py index 832923a..4a0b6dd 100644 --- a/pyclasher/api/bulk_requests/__init__.py +++ b/pyclasher/api/bulk_requests/__init__.py @@ -1,5 +1,5 @@ from .b_player import PlayerBulkRequest -from .b_request_model import BulkRequestModel +from .abc import BulkRequestModel __all__ = ( "PlayerBulkRequest", diff --git a/pyclasher/api/bulk_requests/b_request_model.py b/pyclasher/api/bulk_requests/abc.py similarity index 77% rename from pyclasher/api/bulk_requests/b_request_model.py rename to pyclasher/api/bulk_requests/abc.py index 091236e..be43097 100644 --- a/pyclasher/api/bulk_requests/b_request_model.py +++ b/pyclasher/api/bulk_requests/abc.py @@ -3,7 +3,6 @@ class BulkRequestModel: _request_model = ... - _main_attribute = None _requests = None @property @@ -21,19 +20,11 @@ def __get_properties(self): if isinstance(prop, property) } - async def _async_request(self): - self._tasks = [request.request() for request in self._requests] + async def request(self, client_id=None): + self._tasks = [request.request(client_id) for request in self._requests] await gather(*self._tasks) return self - def request(self): - try: - get_running_loop() - except RuntimeError: - return run(self._async_request()) - else: - return self._async_request() - def __len__(self): return len(self._requests) @@ -54,7 +45,7 @@ def __next__(self): return next(self._iter) def __str__(self): - return f"{self.__class__.__name__}({self._main_attribute})" + return f"{self.__class__.__name__}()" def __repr__(self): props = ', '.join( diff --git a/pyclasher/api/bulk_requests/b_request_model.pyi b/pyclasher/api/bulk_requests/abc.pyi similarity index 69% rename from pyclasher/api/bulk_requests/b_request_model.pyi rename to pyclasher/api/bulk_requests/abc.pyi index f2fba2c..9e811e0 100644 --- a/pyclasher/api/bulk_requests/b_request_model.pyi +++ b/pyclasher/api/bulk_requests/abc.pyi @@ -9,14 +9,11 @@ class BulkRequestModel: :cvar _request_model: the request model that is used to make the bulk request :type _request_model: Any - :cvar _main_attribute: the main attribute used for the string representation (default is None) - :type _main_attribute: Any :cvar _requests: list of requests :type _requests: list """ _request_model: Any = ... - _main_attribute: Any = None _requests: list = None @property @@ -52,26 +49,14 @@ class BulkRequestModel: """ ... - async def _async_request(self) -> BulkRequestModel: + async def request(self, client_id: int | str = None) -> BulkRequestModel: """ asynchronous method that executes the requests :return: the instance of the bulk request model :rtype: BulkRequestModel """ - self._tasks = [request.request() for request in self._requests] - ... - - def request(self) -> BulkRequestModel | Coroutine[Any, Any, BulkRequestModel]: - """ - method that executes the request - - this method can be used in an asynchronous context using the ``await`` keyword - but can also be used in non-asynchronous context without awaiting the method - - :return: the instance of the model - :rtype: BulkRequestModel | Coroutine[Any, Any, BulkRequestModel] - """ + self._tasks = [request.request(client_id) for request in self._requests] ... def __len__(self) -> int: diff --git a/pyclasher/api/bulk_requests/b_player.py b/pyclasher/api/bulk_requests/b_player.py index 6976fb0..0a9e5c2 100644 --- a/pyclasher/api/bulk_requests/b_player.py +++ b/pyclasher/api/bulk_requests/b_player.py @@ -1,6 +1,6 @@ from asyncio import get_running_loop, run -from .b_request_model import BulkRequestModel +from .abc import BulkRequestModel from ..models import BaseClan from ..models import Clan from ..requests import PlayerRequest, ClanMembersRequest @@ -13,7 +13,6 @@ class PlayerBulkRequest(BulkRequestModel): def __init__(self, tags): self._tags = tags self._requests = list(self._request_model(tag) for tag in self.tags) - self._main_attribute = self.tags return @property @@ -21,24 +20,15 @@ def tags(self): return self._tags @classmethod - async def _async_from_clan(cls, clan): + async def from_clan(cls, clan, client_id=None): if isinstance(clan, Clan) and clan.member_list is not MISSING: members = clan.member_list elif isinstance(clan, BaseClan): - members = await ClanMembersRequest(clan.tag).request() + members = await ClanMembersRequest(clan.tag).request(client_id) else: - members = await ClanMembersRequest(clan).request() + members = await ClanMembersRequest(clan).request(client_id) return cls.from_member_list(members) - @classmethod - def from_clan(cls, clan): - try: - get_running_loop() - except RuntimeError: - return run(cls._async_from_clan(clan)) - else: - return cls._async_from_clan(clan) - @classmethod def from_member_list(cls, member_list): return cls((member.tag for member in member_list)) diff --git a/pyclasher/api/bulk_requests/b_player.pyi b/pyclasher/api/bulk_requests/b_player.pyi index 60fc3d7..ea22bac 100644 --- a/pyclasher/api/bulk_requests/b_player.pyi +++ b/pyclasher/api/bulk_requests/b_player.pyi @@ -1,6 +1,6 @@ from typing import Iterable, Coroutine, Any, Iterator -from .b_request_model import BulkRequestModel +from .abc import BulkRequestModel from ..models import BaseClan, ClanMemberList, ClanWarMemberList, \ ClanWarLeagueClanMemberList, \ ClanCapitalRaidSeasonMemberList @@ -43,13 +43,13 @@ class PlayerBulkRequest(BulkRequestModel): ... @classmethod - def from_clan(cls, clan: BaseClan | str) -> PlayerBulkRequest | Coroutine[Any, Any, PlayerBulkRequest]: + async def from_clan(cls, clan: BaseClan | str, client_id: int | str = None) -> PlayerBulkRequest: """ class method to create an instance using a clan or a clan tag :param cls: PlayerBulkRequest :param clan: clan or clan tag - :rtype: PlayerBulkRequest | Coroutine[Any, Any, PlayerBulkRequest] + :rtype: PlayerBulkRequest """ ... diff --git a/pyclasher/api/models/base_models.py b/pyclasher/api/models/base_models.py index 4a00721..01db6d8 100644 --- a/pyclasher/api/models/base_models.py +++ b/pyclasher/api/models/base_models.py @@ -41,7 +41,6 @@ class IconUrl(ImageUrl): class IconUrls(BaseModel): def __init__(self, data: dict): super().__init__(data) - self._main_attribute = self.small return @property diff --git a/pyclasher/api/models/clan.py b/pyclasher/api/models/clan.py index 469e186..8c859f3 100644 --- a/pyclasher/api/models/clan.py +++ b/pyclasher/api/models/clan.py @@ -11,7 +11,6 @@ class ClanDistrictData(BaseModel): def __init__(self, data): super().__init__(data) - self._main_attribute = self.id return @property @@ -34,7 +33,6 @@ class ClanDistrictDataList(IterBaseModel): class ClanCapital(BaseModel): def __init__(self, data): super().__init__(data) - self._main_attribute = self.capital_hall_level return @property diff --git a/pyclasher/api/models/clan_capital_raid_seasons.py b/pyclasher/api/models/clan_capital_raid_seasons.py index 3919745..be4c8f8 100644 --- a/pyclasher/api/models/clan_capital_raid_seasons.py +++ b/pyclasher/api/models/clan_capital_raid_seasons.py @@ -5,7 +5,6 @@ class ClanCapitalRaidSeasonClanInfo(BaseModel): def __init__(self, data): super().__init__(data) - self._main_attribute = self.tag return @property @@ -28,7 +27,6 @@ def badge_urls(self): class ClanCapitalRaidSeasonAttacker(BaseModel): def __init__(self, data): super().__init__(data) - self._main_attribute = self.tag return @property @@ -43,7 +41,6 @@ def name(self): class ClanCapitalRaidSeasonAttack(BaseModel): def __init__(self, data): super().__init__(data) - self._main_attribute = self.destruction_percent return @property @@ -66,7 +63,6 @@ class ClanCapitalRaidSeasonAttackList(IterBaseModel): class ClanCapitalRaidSeasonDistrict(BaseModel): def __init__(self, data): super().__init__(data) - self._main_attribute = self.name return @property @@ -192,7 +188,6 @@ def average_resources_looted(self): class ClanCapitalRaidSeason(BaseModel): def __init__(self, data): super().__init__(data) - self._main_attribute = self.raids_completed return @property diff --git a/pyclasher/api/models/clan_war_league_group.py b/pyclasher/api/models/clan_war_league_group.py index 53f3c0b..f184978 100644 --- a/pyclasher/api/models/clan_war_league_group.py +++ b/pyclasher/api/models/clan_war_league_group.py @@ -38,7 +38,6 @@ def __next__(self): class ClanWarLeagueClan(BaseClan): def __init__(self, data): super().__init__(data) - self._main_attribute = self.tag return @property @@ -63,7 +62,6 @@ def __next__(self): class ClanWarLeagueGroup(BaseModel): def __init__(self, data): super().__init__(data) - self._main_attribute = self.tag return @property diff --git a/pyclasher/api/models/labels.py b/pyclasher/api/models/labels.py index 057640a..56dc42c 100644 --- a/pyclasher/api/models/labels.py +++ b/pyclasher/api/models/labels.py @@ -5,7 +5,6 @@ class Label(BaseModel): def __init__(self, data): super().__init__(data) - self._main_attribute = self.id return @property diff --git a/pyclasher/api/models/language.py b/pyclasher/api/models/language.py index 9a901d9..d657aff 100644 --- a/pyclasher/api/models/language.py +++ b/pyclasher/api/models/language.py @@ -4,7 +4,6 @@ class Language(BaseModel): def __init__(self, data: dict): super().__init__(data) - self._main_attribute = self.id return @property diff --git a/pyclasher/api/models/leagues.py b/pyclasher/api/models/leagues.py index 95ad556..1470d43 100644 --- a/pyclasher/api/models/leagues.py +++ b/pyclasher/api/models/leagues.py @@ -45,7 +45,6 @@ class WarLeagueList(IterBaseModel): class LeagueSeason(BaseModel): def __init__(self, data): super().__init__(data) - self._main_attribute = self.id return @property diff --git a/pyclasher/api/models/location.py b/pyclasher/api/models/location.py index 7292c9b..f03eb25 100644 --- a/pyclasher/api/models/location.py +++ b/pyclasher/api/models/location.py @@ -4,7 +4,6 @@ class Location(BaseModel): def __init__(self, data): super().__init__(data) - self._main_attribute = self.id if data is not None else None return @property diff --git a/pyclasher/api/models/login/login_models.py b/pyclasher/api/models/login/login_models.py index df05cc3..e455190 100644 --- a/pyclasher/api/models/login/login_models.py +++ b/pyclasher/api/models/login/login_models.py @@ -22,7 +22,6 @@ def detail(self): class Auth(BaseModel): def __init__(self, data): super().__init__(data) - self._main_attribute = self.uid return @property diff --git a/pyclasher/api/models/misc/api.py b/pyclasher/api/models/misc/api.py index a59f15a..2016ff2 100644 --- a/pyclasher/api/models/misc/api.py +++ b/pyclasher/api/models/misc/api.py @@ -4,7 +4,6 @@ class ClientError(BaseModel): def __init__(self, data): super().__init__(data) - self._main_attribute = self.reason return @property @@ -29,7 +28,6 @@ class Replay(BaseModel): def __init__(self, data): super().__init__(data) - self._main_attribute = self.replay_tag return @property @@ -46,7 +44,6 @@ class ServiceVersion(BaseModel): def __init__(self, data): super().__init__(data) - self._main_attribute = (self.major, self.minor) return @property diff --git a/pyclasher/api/models/misc/responses.py b/pyclasher/api/models/misc/responses.py index 28c4b3d..b6545a0 100644 --- a/pyclasher/api/models/misc/responses.py +++ b/pyclasher/api/models/misc/responses.py @@ -5,7 +5,6 @@ class VerifyTokenResponse(BaseModel): def __init__(self, data): super().__init__(data) - self._main_attribute = self.tag return @property @@ -24,7 +23,6 @@ def status(self): class DeepLinkCreationResponse(BaseModel): def __init__(self, data): super().__init__(data) - self._main_attribute = self.link return @property diff --git a/pyclasher/api/models/misc/war_status.py b/pyclasher/api/models/misc/war_status.py index f8153e1..59211bd 100644 --- a/pyclasher/api/models/misc/war_status.py +++ b/pyclasher/api/models/misc/war_status.py @@ -6,7 +6,6 @@ class WarStatus(BaseModel): def __init__(self, data): super().__init__(data) - self._main_attribute = self.clan_tag return @property diff --git a/pyclasher/api/models/player.py b/pyclasher/api/models/player.py index 994f208..4ba54ca 100644 --- a/pyclasher/api/models/player.py +++ b/pyclasher/api/models/player.py @@ -15,7 +15,6 @@ def clan_level(self): class LegendLeagueTournamentSeasonResult(BaseModel): def __init__(self, data): super().__init__(data) - self._main_attribute = self.id return @property @@ -136,7 +135,6 @@ class PlayerAchievementProgressList(IterBaseModel): class Player(BaseModel): def __init__(self, data): super().__init__(data) - self._main_attribute = self.tag return @property diff --git a/pyclasher/api/models/player_house.py b/pyclasher/api/models/player_house.py index 4aa2ea5..dd64cb2 100644 --- a/pyclasher/api/models/player_house.py +++ b/pyclasher/api/models/player_house.py @@ -5,7 +5,6 @@ class PlayerHouseElement(BaseModel): def __init__(self, data): super().__init__(data) - self._main_attribute = self.id return @property diff --git a/pyclasher/api/models/war_clan.py b/pyclasher/api/models/war_clan.py index fca37a5..fd9a037 100644 --- a/pyclasher/api/models/war_clan.py +++ b/pyclasher/api/models/war_clan.py @@ -5,7 +5,6 @@ class ClanWarAttack(BaseModel): def __init__(self, data): super().__init__(data) - self._main_attribute = self.attacker_tag return @property diff --git a/pyclasher/api/requests/abc.py b/pyclasher/api/requests/abc.py index 5d34aeb..52d2a2a 100644 --- a/pyclasher/api/requests/abc.py +++ b/pyclasher/api/requests/abc.py @@ -17,7 +17,6 @@ class for requesting """ _data = MISSING - _main_attribute = None _url = None _url_kwargs = None _len = None diff --git a/pyclasher/api/requests/abc.pyi b/pyclasher/api/requests/abc.pyi index 6e31d90..27f5939 100644 --- a/pyclasher/api/requests/abc.pyi +++ b/pyclasher/api/requests/abc.pyi @@ -11,7 +11,6 @@ request_id: int = 0 class RequestModel(ABC): _data: dict = MISSING - _main_attribute: Any = None _url: str = None _url_kwargs: dict | None = None _len: int = None diff --git a/pyclasher/api/requests/builder_base_league.py b/pyclasher/api/requests/builder_base_league.py index 19ef260..a141ce7 100644 --- a/pyclasher/api/requests/builder_base_league.py +++ b/pyclasher/api/requests/builder_base_league.py @@ -9,5 +9,4 @@ def __init__(self, league_id): league_id=league_id) BuilderBaseLeague.__init__(self, None) self.league_id = league_id - self._main_attribute = self.league_id return diff --git a/pyclasher/api/requests/builder_base_leagues.py b/pyclasher/api/requests/builder_base_leagues.py index 2fb5254..13d1921 100644 --- a/pyclasher/api/requests/builder_base_leagues.py +++ b/pyclasher/api/requests/builder_base_leagues.py @@ -13,10 +13,8 @@ def __init__(self, limit=None, after=None, before=None): 'after': after, 'before': before }) - self._main_attribute = self._len return async def request(self, client_id=None): await super().request(client_id) - self._main_attribute = len(self) return self diff --git a/pyclasher/api/requests/capital_league.py b/pyclasher/api/requests/capital_league.py index 45384dd..a4fc524 100644 --- a/pyclasher/api/requests/capital_league.py +++ b/pyclasher/api/requests/capital_league.py @@ -8,5 +8,4 @@ def __init__(self, league_id): league_id=league_id) CapitalLeague.__init__(self, None) self.league_id = league_id - self._main_attribute = self.league_id return diff --git a/pyclasher/api/requests/capital_league_seasons.py b/pyclasher/api/requests/capital_league_seasons.py index e70daf0..8ea1025 100644 --- a/pyclasher/api/requests/capital_league_seasons.py +++ b/pyclasher/api/requests/capital_league_seasons.py @@ -13,5 +13,4 @@ def __init__(self, limit=None, after=None, before=None): 'after': after, 'before': before }) - self._main_attribute = self._len return diff --git a/pyclasher/api/requests/clan.py b/pyclasher/api/requests/clan.py index 5301c5a..28ca197 100644 --- a/pyclasher/api/requests/clan.py +++ b/pyclasher/api/requests/clan.py @@ -22,7 +22,6 @@ def __init__(self, clan_tag): "clans/{clan_tag}", clan_tag=self.clan_tag) Clan.__init__(self, None) - self._main_attribute = self.clan_tag return @classmethod diff --git a/pyclasher/api/requests/clan_builder_base_rankings.py b/pyclasher/api/requests/clan_builder_base_rankings.py index 4a2b6f5..5467445 100644 --- a/pyclasher/api/requests/clan_builder_base_rankings.py +++ b/pyclasher/api/requests/clan_builder_base_rankings.py @@ -18,5 +18,4 @@ def __init__(self, location_id, 'after': after, 'before': before }) - self._main_attribute = self.location_id return diff --git a/pyclasher/api/requests/clan_capital_raid_seasons.py b/pyclasher/api/requests/clan_capital_raid_seasons.py index 801c7f8..f245fcc 100644 --- a/pyclasher/api/requests/clan_capital_raid_seasons.py +++ b/pyclasher/api/requests/clan_capital_raid_seasons.py @@ -34,7 +34,6 @@ def __init__(self, clan_tag, limit=None, after=None, before=None): 'after': after, 'before': before }) - self._main_attribute = self.clan_tag return @property diff --git a/pyclasher/api/requests/clan_current_war.py b/pyclasher/api/requests/clan_current_war.py index dcfa3b4..2941a75 100644 --- a/pyclasher/api/requests/clan_current_war.py +++ b/pyclasher/api/requests/clan_current_war.py @@ -1,5 +1,5 @@ from .abc import RequestModel -from ..models import ClanWar, BaseClan +from ..models import ClanWar, BaseClan, ClanWarState class ClanCurrentWarRequest(RequestModel, ClanWar): @@ -20,7 +20,6 @@ def __init__(self, clan_tag): "clans/{clan_tag}/currentwar", clan_tag=self.clan_tag) ClanWar.__init__(self, None) - self._main_attribute = self.clan_tag return @classmethod @@ -38,11 +37,16 @@ async def from_base_clan(cls, base_clan): async def request(self, client_id=None): await super().request(client_id) - self._data['clan']['members'] = sorted( - self._data['clan']['members'], - key=lambda member: member['mapPosition'] - ) - self._data['opponent']['members'] = sorted( - self._data['opponent']['members'], - key=lambda member: member['mapPosition'] - ) + if (self.state == ClanWarState.IN_WAR + or self.state == ClanWarState.WAR + or self.state == ClanWarState.PREPARATION + or self.state == ClanWarState.ENDED + ): + self._data['clan']['members'] = sorted( + self._data['clan']['members'], + key=lambda member: member['mapPosition'] + ) + self._data['opponent']['members'] = sorted( + self._data['opponent']['members'], + key=lambda member: member['mapPosition'] + ) diff --git a/pyclasher/api/requests/clan_currentwar_leaguegroup.py b/pyclasher/api/requests/clan_currentwar_leaguegroup.py index 3d79a2b..7aef9f4 100644 --- a/pyclasher/api/requests/clan_currentwar_leaguegroup.py +++ b/pyclasher/api/requests/clan_currentwar_leaguegroup.py @@ -20,7 +20,6 @@ def __init__(self, clan_tag): "clans/{clan_tag}/currentwar/leaguegroup", clan_tag=self.clan_tag) ClanWarLeagueGroup.__init__(self, None) - self._main_attribute = self.clan_tag return @classmethod diff --git a/pyclasher/api/requests/clan_labels.py b/pyclasher/api/requests/clan_labels.py index e612041..e467462 100644 --- a/pyclasher/api/requests/clan_labels.py +++ b/pyclasher/api/requests/clan_labels.py @@ -8,5 +8,4 @@ class ClanLabelsRequest(IterRequestModel): def __init__(self): super().__init__("labels/clans") - self._main_attribute = "" return diff --git a/pyclasher/api/requests/clan_members.py b/pyclasher/api/requests/clan_members.py index f4b3e99..2fbbf35 100644 --- a/pyclasher/api/requests/clan_members.py +++ b/pyclasher/api/requests/clan_members.py @@ -34,7 +34,6 @@ def __init__(self, clan_tag, limit=None, after=None, before=None): 'after': after, 'before': before }) - self._main_attribute = self.clan_tag return @property diff --git a/pyclasher/api/requests/clan_rankings.py b/pyclasher/api/requests/clan_rankings.py index 121770d..3bd386c 100644 --- a/pyclasher/api/requests/clan_rankings.py +++ b/pyclasher/api/requests/clan_rankings.py @@ -17,5 +17,4 @@ def __init__(self, location_id, 'after': after, 'before': before }) - self._main_attribute = self.location_id return diff --git a/pyclasher/api/requests/clan_search.py b/pyclasher/api/requests/clan_search.py index f61984a..2b18d11 100644 --- a/pyclasher/api/requests/clan_search.py +++ b/pyclasher/api/requests/clan_search.py @@ -80,5 +80,4 @@ def __init__( 'before': before } ) - self._main_attribute = self.clan_name return diff --git a/pyclasher/api/requests/clan_war_log.py b/pyclasher/api/requests/clan_war_log.py index bce99fa..430d5b0 100644 --- a/pyclasher/api/requests/clan_war_log.py +++ b/pyclasher/api/requests/clan_war_log.py @@ -40,7 +40,6 @@ def __init__(self, clan_tag, limit=None, after=None, before=None): 'after': after, 'before': before }) - self._main_attribute = self.clan_tag return @staticmethod diff --git a/pyclasher/api/requests/clan_warleagues_wars.py b/pyclasher/api/requests/clan_warleagues_wars.py index 824e757..826dffb 100644 --- a/pyclasher/api/requests/clan_warleagues_wars.py +++ b/pyclasher/api/requests/clan_warleagues_wars.py @@ -1,15 +1,16 @@ from .abc import RequestModel -from ..models import ClanWarLeagueGroup +from ..models import ClanWar -class ClanWarleaguesWarsRequest(RequestModel, ClanWarLeagueGroup): +class ClanWarleaguesWarsRequest(RequestModel, ClanWar): """ Retrieve information about individual clan war league war """ def __init__(self, war_tag): self.war_tag = war_tag - super().__init__("clanwarleagues/wars/{war_tag}", - war_tag=self.war_tag) - self._main_attribute = self.war_tag + RequestModel.__init__(self, + "clanwarleagues/wars/{war_tag}", + war_tag=self.war_tag) + ClanWar.__init__(self, None) return diff --git a/pyclasher/api/requests/clan_warleagues_wars.pyi b/pyclasher/api/requests/clan_warleagues_wars.pyi index 9ddda2f..f558b64 100644 --- a/pyclasher/api/requests/clan_warleagues_wars.pyi +++ b/pyclasher/api/requests/clan_warleagues_wars.pyi @@ -1,13 +1,12 @@ from .abc import RequestModel -from ..models import ClanWarLeagueGroup +from ..models import ClanWar -class ClanWarleaguesWarsRequest(RequestModel, ClanWarLeagueGroup): +class ClanWarleaguesWarsRequest(RequestModel, ClanWar): """ Retrieve information about individual clan war league war """ def __init__(self, war_tag) -> None: self.war_tag: str = ... - self._main_attribute: str = ... ... diff --git a/pyclasher/api/requests/gold_pass.py b/pyclasher/api/requests/gold_pass.py index dea66fb..2d0d5e5 100644 --- a/pyclasher/api/requests/gold_pass.py +++ b/pyclasher/api/requests/gold_pass.py @@ -6,5 +6,4 @@ class GoldPassRequest(RequestModel, GoldPassSeason): def __init__(self): RequestModel.__init__(self, "goldpass/seasons/current") GoldPassSeason.__init__(self) - self._main_attribute = "" return diff --git a/pyclasher/api/requests/league.py b/pyclasher/api/requests/league.py index 9b2557b..377ad4a 100644 --- a/pyclasher/api/requests/league.py +++ b/pyclasher/api/requests/league.py @@ -9,5 +9,4 @@ def __init__(self, league_id): league_id=league_id) League.__init__(self, None) self.league_id = league_id - self._main_attribute = self.league_id return diff --git a/pyclasher/api/requests/league_season.py b/pyclasher/api/requests/league_season.py index 562476b..5739977 100644 --- a/pyclasher/api/requests/league_season.py +++ b/pyclasher/api/requests/league_season.py @@ -22,5 +22,4 @@ def __init__(self, 'after': after, 'before': before }) - self._main_attribute = league_id return diff --git a/pyclasher/api/requests/leagues.py b/pyclasher/api/requests/leagues.py index 6567637..10c61d9 100644 --- a/pyclasher/api/requests/leagues.py +++ b/pyclasher/api/requests/leagues.py @@ -16,5 +16,4 @@ def __init__(self, 'after': after, 'before': before }) - self._main_attribute = self._len return diff --git a/pyclasher/api/requests/location.py b/pyclasher/api/requests/location.py index 25d4d61..95a6ddf 100644 --- a/pyclasher/api/requests/location.py +++ b/pyclasher/api/requests/location.py @@ -9,5 +9,4 @@ def __init__(self, location_id): location_id=location_id) Location.__init__(self, None) self.location_id = location_id - self._main_attribute = self.location_id return diff --git a/pyclasher/api/requests/locations.py b/pyclasher/api/requests/locations.py index 80acabb..f466ae8 100644 --- a/pyclasher/api/requests/locations.py +++ b/pyclasher/api/requests/locations.py @@ -13,5 +13,4 @@ def __init__(self, limit=None, after=None, before=None): 'after': after, 'before': before }) - self._main_attribute = self._len return diff --git a/pyclasher/api/requests/player.py b/pyclasher/api/requests/player.py index 5cdf19e..3476ad8 100644 --- a/pyclasher/api/requests/player.py +++ b/pyclasher/api/requests/player.py @@ -17,7 +17,6 @@ class PlayerRequest(RequestModel, Player): def __init__(self, player_tag): self.player_tag = player_tag super().__init__("players/{player_tag}", player_tag=self.player_tag) - self._main_attribute = self.player_tag return async def verify_token(self, player_token): diff --git a/pyclasher/api/requests/player_builder_base_rankings.py b/pyclasher/api/requests/player_builder_base_rankings.py index 419b244..64a017a 100644 --- a/pyclasher/api/requests/player_builder_base_rankings.py +++ b/pyclasher/api/requests/player_builder_base_rankings.py @@ -18,5 +18,4 @@ def __init__(self, location_id, 'after': after, 'before': before }) - self._main_attribute = self.location_id return diff --git a/pyclasher/api/requests/player_rankings.py b/pyclasher/api/requests/player_rankings.py index 47cbcc8..5cccfa7 100644 --- a/pyclasher/api/requests/player_rankings.py +++ b/pyclasher/api/requests/player_rankings.py @@ -17,5 +17,4 @@ def __init__(self, location_id, 'after': after, 'before': before }) - self._main_attribute = self.location_id return diff --git a/pyclasher/api/requests/war_league.py b/pyclasher/api/requests/war_league.py index 6ab647e..e235972 100644 --- a/pyclasher/api/requests/war_league.py +++ b/pyclasher/api/requests/war_league.py @@ -8,5 +8,4 @@ def __init__(self, league_id): league_id=league_id) WarLeague.__init__(self, None) self.league_id = league_id - self._main_attribute = self.league_id return diff --git a/pyclasher/api/requests/war_leagues.py b/pyclasher/api/requests/war_leagues.py index dc7965c..a10e4b7 100644 --- a/pyclasher/api/requests/war_leagues.py +++ b/pyclasher/api/requests/war_leagues.py @@ -13,5 +13,4 @@ def __init__(self, limit=None, after=None, before=None): 'after': after, 'before': before }) - self._main_attribute = self._len return diff --git a/tests/bulk_requests/__init__.py b/tests/bulk_requests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/bulk_requests/test_player_bulk.py b/tests/bulk_requests/test_player_bulk.py new file mode 100644 index 0000000..82065cf --- /dev/null +++ b/tests/bulk_requests/test_player_bulk.py @@ -0,0 +1,58 @@ +from typing import Generator + +import pytest + +from pyclasher.api import League +from pyclasher.api.bulk_requests import PlayerBulkRequest +from pyclasher.api.models import ( + WarPreference, PlayerItemLevelList, PlayerHouse, PlayerLegendStatistics, + LabelList, ClanRole, BuilderBaseLeague, PlayerAchievementProgressList, + PlayerClan +) +from pyclasher.exceptions import Missing + +from ..constants import TEST_CLAN_TAG + + +@pytest.mark.asyncio +async def test_player_bulk(pyclasher_client): + player_bulk = await PlayerBulkRequest.from_clan(TEST_CLAN_TAG, + "test_client") + + assert isinstance(player_bulk.tags, Generator) + for tag in player_bulk.tags: + assert isinstance(tag, str) + + await player_bulk.request("test_client") + + assert isinstance(player_bulk.requests, list) + for player in player_bulk: + assert isinstance(player.to_dict(), dict) + assert isinstance(player.role, ClanRole) + assert isinstance(player.clan, PlayerClan) + assert isinstance(player.name, str) + assert isinstance(player.trophies, int) + assert isinstance(player.achievements, PlayerAchievementProgressList) + assert isinstance(player.attack_wins, int) + assert isinstance(player.best_builder_base_trophies, int) + assert isinstance(player.best_trophies, int) + assert isinstance(player.builder_base_league, BuilderBaseLeague) + assert isinstance(player.builder_base_trophies, int) + assert isinstance(player.builder_hall_level, int) + assert isinstance(player.clan_capital_contributions, int) + assert isinstance(player.defense_wins, int) + assert isinstance(player.donations, int) + assert isinstance(player.donations_received, int) + assert isinstance(player.exp_level, int) + assert isinstance(player.heroes, PlayerItemLevelList) + assert isinstance(player.labels, LabelList) + assert isinstance(player.league, (League, Missing)) + assert isinstance(player.legend_statistics, + (Missing, PlayerLegendStatistics)) + assert isinstance(player.player_house, (Missing, PlayerHouse)) + assert isinstance(player.spells, PlayerItemLevelList) + assert isinstance(player.town_hall_level, int) + assert isinstance(player.troops, PlayerItemLevelList) + assert isinstance(player.town_hall_weapon_level, (Missing, int)) + assert isinstance(player.versus_battle_wins, int) + assert isinstance(player.war_preference, WarPreference) diff --git a/tests/requests/conftest.py b/tests/conftest.py similarity index 76% rename from tests/requests/conftest.py rename to tests/conftest.py index 8e4d1d3..ac3df5a 100644 --- a/tests/requests/conftest.py +++ b/tests/conftest.py @@ -4,8 +4,8 @@ from pyclasher import Client -from ..constants import (CLASH_OF_CLANS_LOGIN_EMAIL, - CLASH_OF_CLANS_LOGIN_PASSWORD) +from tests.constants import (CLASH_OF_CLANS_LOGIN_EMAIL, + CLASH_OF_CLANS_LOGIN_PASSWORD) @pytest.fixture(scope="package") @@ -26,7 +26,8 @@ async def pyclasher_client(event_loop): client = await Client.from_login(CLASH_OF_CLANS_LOGIN_EMAIL, CLASH_OF_CLANS_LOGIN_PASSWORD, requests_per_second=5, - request_timeout=30) + request_timeout=30, + login_count=2) client.client_id = "test_client" await client.start() diff --git a/tests/requests/test_clan.py b/tests/requests/test_clan.py index 628f424..5662443 100644 --- a/tests/requests/test_clan.py +++ b/tests/requests/test_clan.py @@ -4,7 +4,8 @@ ClanRequest, ClanMembersRequest, Missing, ClanCurrentWarRequest, ClanWarLogRequest, ClanSearchRequest, ClanCapitalRaidSeasonsRequest, ClanCurrentwarLeaguegroupRequest, - RequestNotDone, ClanWarleaguesWarsRequest + RequestNotDone, ClanWarleaguesWarsRequest, + MISSING ) from pyclasher.api.models import ( ClanType, WarFrequency, BadgeUrls, WarLeague, CapitalLeague, Language, @@ -243,6 +244,9 @@ async def test_clan_warleagues_wars(event_loop, pyclasher_client): else: for league_round in league_group.rounds: for war in league_round.war_tags: + if war == "#0": + continue + group = ClanWarleaguesWarsRequest(war) await group.request("test_client") @@ -250,7 +254,12 @@ async def test_clan_warleagues_wars(event_loop, pyclasher_client): assert isinstance(group.to_dict(), dict) assert group.war_tag == war - assert isinstance(group.state, ClanWarLeagueGroupState) - assert isinstance(group.clans, ClanWarLeagueClanList) - assert isinstance(group.rounds, ClanWarLeagueRoundList) - assert isinstance(group.season, str) + assert isinstance(group.state, ClanWarState) + assert isinstance(group.clan, WarClan) + assert isinstance(group.opponent, WarClan) + + assert group.attacks_per_member == MISSING + assert isinstance(group.end_time, Time) + assert isinstance(group.team_size, int) + assert isinstance(group.preparation_start_time, Time) + assert isinstance(group.start_time, Time) diff --git a/tests/requests/test_player.py b/tests/requests/test_player.py index c2942bb..1203178 100644 --- a/tests/requests/test_player.py +++ b/tests/requests/test_player.py @@ -37,11 +37,12 @@ async def test_player(event_loop, pyclasher_client): assert isinstance(player.heroes, PlayerItemLevelList) assert isinstance(player.labels, LabelList) assert isinstance(player.league, (League, Missing)) - assert isinstance(player.legend_statistics, PlayerLegendStatistics) - assert isinstance(player.player_house, PlayerHouse) + assert isinstance(player.legend_statistics, (Missing, + PlayerLegendStatistics)) + assert isinstance(player.player_house, (Missing, PlayerHouse)) assert isinstance(player.spells, PlayerItemLevelList) assert isinstance(player.town_hall_level, int) assert isinstance(player.troops, PlayerItemLevelList) - assert isinstance(player.town_hall_weapon_level, int) + assert isinstance(player.town_hall_weapon_level, (Missing, int)) assert isinstance(player.versus_battle_wins, int) assert isinstance(player.war_preference, WarPreference)