Skip to content

Commit

Permalink
Merge branch 'master' into new-features
Browse files Browse the repository at this point in the history
  • Loading branch information
201st-Luka authored Aug 24, 2023
2 parents 7b93e7a + fcfbd3a commit 1f5f07e
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 16 deletions.
1 change: 1 addition & 0 deletions pyclasher/api/requests/leagues.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class LeaguesRequest(IterRequestModel):
def _async_request(self) -> LeaguesRequest:
...

@property
def items(self) -> _list_rtype:
...

Expand Down
9 changes: 7 additions & 2 deletions pyclasher/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from .request_queue import PConsumer, PQueue
from .utils.login import Login
from .exceptions import (InvalidType, ClientIsRunning, ClientIsNotRunning,
NoneToken, MISSING, ClientAlreadyInitialised)
NoneToken, MISSING, ClientAlreadyInitialised,
PyClasherException)


global_client_id = 0
Expand Down Expand Up @@ -201,7 +202,11 @@ def client_id(self, new_id):
if client.client_id == new_id:
raise ValueError(f"`new_id` {new_id} has already been taken "
f"and must be different")
self._client_id = new_id

if isinstance(new_id, str):
if " " in new_id:
raise PyClasherException("`new_id` must not contain spaces")

return

@classmethod
Expand Down
3 changes: 3 additions & 0 deletions tests/requests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ def event_loop():
@pytest_asyncio.fixture(scope="package")
async def pyclasher_client(event_loop):
print("Setting PyClasherClient ...")

client = await Client.from_login(CLASH_OF_CLANS_LOGIN_EMAIL,
CLASH_OF_CLANS_LOGIN_PASSWORD)
client.client_id = "test_client"

await client.start()

yield client
Expand Down
18 changes: 9 additions & 9 deletions tests/requests/test_clan.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
async def test_clan(event_loop, pyclasher_client):
clan = ClanRequest(TEST_CLAN_TAG)

await clan.request()
await clan.request("test_client")

assert isinstance(clan.to_dict(), dict)
assert clan.tag == clan.clan_tag == TEST_CLAN_TAG
Expand Down Expand Up @@ -61,7 +61,7 @@ async def test_clan(event_loop, pyclasher_client):
async def test_clan_member(event_loop, pyclasher_client):
clan_members = ClanMembersRequest(TEST_CLAN_TAG)

await clan_members.request()
await clan_members.request("test_client")

assert isinstance(clan_members.to_dict(), dict)
assert clan_members.clan_tag == TEST_CLAN_TAG
Expand Down Expand Up @@ -92,7 +92,7 @@ async def test_clan_member(event_loop, pyclasher_client):
async def test_clan_current_war(event_loop, pyclasher_client):
current_war = ClanCurrentWarRequest(TEST_CLAN_TAG)

await current_war.request()
await current_war.request("test_client")

assert isinstance(current_war.to_dict(), dict)
assert current_war.clan_tag == TEST_CLAN_TAG
Expand All @@ -113,7 +113,7 @@ async def test_clan_current_war(event_loop, pyclasher_client):
async def test_clan_war_log(event_loop, pyclasher_client):
war_log = ClanWarLogRequest(TEST_CLAN_TAG)

await war_log.request()
await war_log.request("test_client")

assert isinstance(war_log.to_dict(), dict)
assert war_log.clan_tag == TEST_CLAN_TAG
Expand All @@ -135,7 +135,7 @@ async def test_clan_war_log(event_loop, pyclasher_client):
async def test_clan_search(event_loop, pyclasher_client):
clans = ClanSearchRequest(TEST_CLAN_NAME)

await clans.request()
await clans.request("test_client")

assert isinstance(clans.to_dict(), dict)
assert clans.clan_name == TEST_CLAN_NAME
Expand Down Expand Up @@ -178,7 +178,7 @@ async def test_clan_search(event_loop, pyclasher_client):
async def test_clan_capital_raid_season(event_loop, pyclasher_client):
raid_seasons = ClanCapitalRaidSeasonsRequest(TEST_CLAN_TAG)

await raid_seasons.request()
await raid_seasons.request("test_client")

assert isinstance(raid_seasons.to_dict(), dict)
assert raid_seasons.clan_tag == TEST_CLAN_TAG
Expand Down Expand Up @@ -206,7 +206,7 @@ async def test_clan_currentwar_leaguegroup(event_loop, pyclasher_client):
try:
league_group = ClanCurrentwarLeaguegroupRequest(TEST_CLAN_TAG)

await league_group.request()
await league_group.request("test_client")
except RequestNotDone:
pass
else:
Expand All @@ -224,15 +224,15 @@ async def test_clan_warleagues_wars(event_loop, pyclasher_client):
try:
league_group = ClanCurrentwarLeaguegroupRequest(TEST_CLAN_TAG)

await league_group.request()
await league_group.request("test_client")
except RequestNotDone:
pass
else:
for league_round in league_group.rounds:
for war in league_round.war_tags:
group = ClanWarleaguesWarsRequest(war)

await group.request()
await group.request("test_client")

assert isinstance(group.to_dict(), dict)
assert group.war_tag == war
Expand Down
2 changes: 1 addition & 1 deletion tests/requests/test_goldpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
async def test_goldpass(event_loop, pyclasher_client):
goldpass = GoldPassRequest()

await goldpass.request()
await goldpass.request("test_client")

assert isinstance(goldpass.to_dict(), dict)
assert isinstance(goldpass.start_time, Time)
Expand Down
4 changes: 2 additions & 2 deletions tests/requests/test_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
async def test_clan_labels(event_loop, pyclasher_client):
clan_labels = ClanLabelsRequest()

await clan_labels.request()
await clan_labels.request("test_client")

assert isinstance(clan_labels.to_dict(), dict)
assert isinstance(clan_labels.items, LabelList)
Expand All @@ -25,7 +25,7 @@ async def test_clan_labels(event_loop, pyclasher_client):
async def test_clan_labels(event_loop, pyclasher_client):
player_labels = PlayerLabelsRequest()

await player_labels.request()
await player_labels.request("test_client")

assert isinstance(player_labels.to_dict(), dict)
assert isinstance(player_labels.items, LabelList)
Expand Down
20 changes: 20 additions & 0 deletions tests/requests/test_leagues.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest

from pyclasher.api.models import LeagueList, Paging, IconUrls
from pyclasher import LeaguesRequest


@pytest.mark.asyncio
async def test_leagues(event_loop, pyclasher_client):
leagues = LeaguesRequest()

await leagues.request("test_client")

assert isinstance(leagues.to_dict(), dict)
assert isinstance(leagues.items, LeagueList)
assert isinstance(leagues.paging, Paging)

for league in leagues:
assert isinstance(league.name, str)
assert isinstance(league.id, int)
assert isinstance(league.icon_urls, IconUrls)
2 changes: 1 addition & 1 deletion tests/requests/test_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
async def test_locations(event_loop, pyclasher_client):
locations = LocationsRequest()

await locations.request()
await locations.request("test_client")

assert isinstance(locations.to_dict(), dict)
assert isinstance(locations.items, LocationList)
Expand Down
2 changes: 1 addition & 1 deletion tests/requests/test_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
async def test_player(event_loop, pyclasher_client):
player = PlayerRequest(TEST_PLAYER_TAG)

await player.request()
await player.request("test_client")

assert isinstance(player.to_dict(), dict)
assert player.player_tag == player.tag == TEST_PLAYER_TAG
Expand Down
4 changes: 4 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@
@pytest.mark.tryfirst
@pytest.mark.asyncio
async def test_client():
TEST_CLIENT_ID = "test_client_id"

assert not Client.initialized()

client = await Client.from_login(CLASH_OF_CLANS_LOGIN_EMAIL,
CLASH_OF_CLANS_LOGIN_PASSWORD)
client.client_id = TEST_CLIENT_ID

assert client.client_id == TEST_CLIENT_ID
assert Client.initialized()
assert not client.is_running
assert isinstance(client.queue, Queue)
Expand Down

0 comments on commit 1f5f07e

Please sign in to comment.