Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
takos22 committed Nov 19, 2023
1 parent cbd8278 commit 0efa19e
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 44 deletions.
20 changes: 7 additions & 13 deletions tests/async/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ async def create_client() -> AsyncClient:


@pytest.fixture(name="auth_client")
async def create_logged_in_client(
request: pytest.FixtureRequest,
) -> AsyncClient:
async def create_logged_in_client(mock_http) -> AsyncClient:
async with Client(is_async=True) as client:
if "mock_http" in request.fixturenames:
mock_http = request.getfixturevalue("mock_http")
mock_http(client._state.http, "login")
mock_http(client._state.http, "get_codingamer_from_id")
mock_http(client._state.http, "get_codingamer_from_handle")
mock_http(client._state.http, "login")
mock_http(client._state.http, "get_codingamer_from_id")
mock_http(client._state.http, "get_codingamer_from_handle")

await client.login(
remember_me_cookie=os.environ.get("TEST_LOGIN_REMEMBER_ME_COOKIE"),
Expand All @@ -34,12 +30,10 @@ async def create_logged_in_client(

@pytest.fixture(name="private_clash")
async def create_private_clash(
request: pytest.FixtureRequest, auth_client: AsyncClient
auth_client: AsyncClient, mock_http
) -> ClashOfCode:
if "mock_http" in request.fixturenames:
mock_http = request.getfixturevalue("mock_http")
mock_http(auth_client._state.http, "create_private_clash_of_code")
mock_http(auth_client._state.http, "get_clash_of_code_from_handle")
mock_http(auth_client._state.http, "create_private_clash_of_code")
mock_http(auth_client._state.http, "get_clash_of_code_from_handle")

clash_of_code = await auth_client.create_private_clash_of_code(
["Python3"], ["SHORTEST", "FASTEST"]
Expand Down
32 changes: 23 additions & 9 deletions tests/async/test_codingamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,35 @@


@pytest.fixture(name="codingamer")
async def get_codingamer(auth_client) -> CodinGamer:
async def get_codingamer(auth_client, mock_http) -> CodinGamer:
mock_http(auth_client._state.http, "get_codingamer_from_handle")
return await auth_client.get_codingamer(
os.environ.get("TEST_CODINGAMER_PUBLIC_HANDLE")
)


async def test_codingamer_avatar_and_cover_urls(client: AsyncClient):
codingamer = await client.get_codingamer("Takos")
async def test_codingamer_avatar_and_cover_urls(client: AsyncClient, mock_http):
mock_http(client._state.http, "get_codingamer_from_handle")
codingamer = await client.get_codingamer(
os.environ.get("TEST_CODINGAMER_PUBLIC_HANDLE")
)
assert isinstance(codingamer.avatar_url, str)

Check failure on line 25 in tests/async/test_codingamer.py

View workflow job for this annotation

GitHub Actions / build (3.7)

test_codingamer_avatar_and_cover_urls AssertionError: assert False + where False = isinstance(None, str) + where None = <CodinGamer id=*** pseudo='***'>.avatar_url

Check failure on line 25 in tests/async/test_codingamer.py

View workflow job for this annotation

GitHub Actions / build (3.9)

test_codingamer_avatar_and_cover_urls AssertionError: assert False + where False = isinstance(None, str) + where None = <CodinGamer id=*** pseudo='***'>.avatar_url

Check failure on line 25 in tests/async/test_codingamer.py

View workflow job for this annotation

GitHub Actions / build (3.10)

test_codingamer_avatar_and_cover_urls AssertionError: assert False + where False = isinstance(None, str) + where None = <CodinGamer id=*** pseudo='***'>.avatar_url
assert isinstance(codingamer.cover_url, str)
assert isinstance(codingamer.profile_url, str)


async def test_codingamer_eq(client: AsyncClient, codingamer: CodinGamer):
async def test_codingamer_eq(
client: AsyncClient, codingamer: CodinGamer, mock_http
):
mock_http(client._state.http, "get_codingamer_from_handle")
other_codingamer = await client.get_codingamer(
os.environ.get("TEST_CODINGAMER_PUBLIC_HANDLE")
)
assert codingamer == other_codingamer


async def test_codingamer_get_followers(codingamer: CodinGamer):
async def test_codingamer_get_followers(codingamer: CodinGamer, mock_http):
mock_http(codingamer._state.http, "get_codingamer_followers")
async for follower in codingamer.get_followers():
assert isinstance(follower, CodinGamer)

Expand All @@ -43,13 +51,15 @@ async def test_codingamer_get_followers_error(client: AsyncClient):
next(await codingamer.get_followers())


async def test_codingamer_get_followers_ids(codingamer: CodinGamer):
async def test_codingamer_get_followers_ids(codingamer: CodinGamer, mock_http):
mock_http(codingamer._state.http, "get_codingamer_follower_ids")
followers_ids = await codingamer.get_followers_ids()
assert isinstance(followers_ids, list)
assert all(isinstance(follower_id, int) for follower_id in followers_ids)


async def test_codingamer_get_followed(codingamer: CodinGamer):
async def test_codingamer_get_followed(codingamer: CodinGamer, mock_http):
mock_http(codingamer._state.http, "get_codingamer_following")
async for followed in codingamer.get_followed():
assert isinstance(followed, CodinGamer)

Expand All @@ -62,12 +72,16 @@ async def test_codingamer_get_followed_error(client: AsyncClient):
next(await codingamer.get_followed())


async def test_codingamer_get_followed_ids(codingamer: CodinGamer):
async def test_codingamer_get_followed_ids(codingamer: CodinGamer, mock_http):
mock_http(codingamer._state.http, "get_codingamer_following_ids")
followed_ids = await codingamer.get_followed_ids()
assert isinstance(followed_ids, list)
assert all(isinstance(followed_id, int) for followed_id in followed_ids)


async def test_codingamer_get_clash_of_code_rank(codingamer: CodinGamer):
async def test_codingamer_get_clash_of_code_rank(
codingamer: CodinGamer, mock_http
):
mock_http(codingamer._state.http, "get_codingamer_clash_of_code_rank")
rank = await codingamer.get_clash_of_code_rank()
assert isinstance(rank, int)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"rank": 1234, "totalPlayers": 123456}
1 change: 1 addition & 0 deletions tests/mock/responses/get_codingamer_follower_ids.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1234567]
13 changes: 13 additions & 0 deletions tests/mock/responses/get_codingamer_followers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"userId": 1234567,
"pseudo": "Pseudo123",
"countryId": "US",
"publicHandle": "0123456789abcdef0123456789abcdef7654321",
"rank": 12345,
"isFollowing": true,
"isFollower": true,
"points": 1234,
"level": 9
}
]
13 changes: 13 additions & 0 deletions tests/mock/responses/get_codingamer_following.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"userId": 1234567,
"pseudo": "Pseudo123",
"countryId": "US",
"publicHandle": "0123456789abcdef0123456789abcdef7654321",
"rank": 12345,
"isFollowing": true,
"isFollower": true,
"points": 1234,
"level": 9
}
]
1 change: 1 addition & 0 deletions tests/mock/responses/get_codingamer_following_ids.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1234567]
2 changes: 2 additions & 0 deletions tests/mock/responses/get_codingamer_from_handle.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"pseudo": "Pseudo123",
"countryId": "US",
"publicHandle": "0123456789abcdef0123456789abcdef7654321",
"avatar":12345678901234,
"cover":12345678901234,
"formValues": {},
"enable": false,
"rank": 12345,
Expand Down
20 changes: 7 additions & 13 deletions tests/sync/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ def create_client() -> SyncClient:


@pytest.fixture(name="auth_client")
def create_logged_in_client(request: pytest.FixtureRequest) -> SyncClient:
def create_logged_in_client(mock_http) -> SyncClient:
with Client() as client:
if "mock_http" in request.fixturenames:
mock_http = request.getfixturevalue("mock_http")
mock_http(client._state.http, "login")
mock_http(client._state.http, "get_codingamer_from_id")
mock_http(client._state.http, "get_codingamer_from_handle")
mock_http(client._state.http, "login")
mock_http(client._state.http, "get_codingamer_from_id")
mock_http(client._state.http, "get_codingamer_from_handle")

client.login(
remember_me_cookie=os.environ.get("TEST_LOGIN_REMEMBER_ME_COOKIE"),
Expand All @@ -31,13 +29,9 @@ def create_logged_in_client(request: pytest.FixtureRequest) -> SyncClient:


@pytest.fixture(name="private_clash")
def create_private_clash(
request: pytest.FixtureRequest, auth_client: SyncClient
) -> ClashOfCode:
if "mock_http" in request.fixturenames:
mock_http = request.getfixturevalue("mock_http")
mock_http(auth_client._state.http, "create_private_clash_of_code")
mock_http(auth_client._state.http, "get_clash_of_code_from_handle")
def create_private_clash(auth_client: SyncClient, mock_http) -> ClashOfCode:
mock_http(auth_client._state.http, "create_private_clash_of_code")
mock_http(auth_client._state.http, "get_clash_of_code_from_handle")

clash_of_code = auth_client.create_private_clash_of_code(
["Python3"], ["SHORTEST", "FASTEST"]
Expand Down
28 changes: 19 additions & 9 deletions tests/sync/test_codingamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,33 @@


@pytest.fixture(name="codingamer")
def get_codingamer(auth_client) -> CodinGamer:
def get_codingamer(auth_client, mock_http) -> CodinGamer:
mock_http(auth_client._state.http, "get_codingamer_from_handle")
return auth_client.get_codingamer(
os.environ.get("TEST_CODINGAMER_PUBLIC_HANDLE")
)


def test_codingamer_avatar_and_cover_urls(client: Client):
codingamer = client.get_codingamer("Takos")
def test_codingamer_avatar_and_cover_urls(client: Client, mock_http):
mock_http(client._state.http, "get_codingamer_from_handle")
codingamer = client.get_codingamer(
os.environ.get("TEST_CODINGAMER_PUBLIC_HANDLE")
)
assert isinstance(codingamer.avatar_url, str)

Check failure on line 23 in tests/sync/test_codingamer.py

View workflow job for this annotation

GitHub Actions / build (3.7)

test_codingamer_avatar_and_cover_urls AssertionError: assert False + where False = isinstance(None, str) + where None = <CodinGamer id=*** pseudo='***'>.avatar_url

Check failure on line 23 in tests/sync/test_codingamer.py

View workflow job for this annotation

GitHub Actions / build (3.9)

test_codingamer_avatar_and_cover_urls AssertionError: assert False + where False = isinstance(None, str) + where None = <CodinGamer id=*** pseudo='***'>.avatar_url

Check failure on line 23 in tests/sync/test_codingamer.py

View workflow job for this annotation

GitHub Actions / build (3.10)

test_codingamer_avatar_and_cover_urls AssertionError: assert False + where False = isinstance(None, str) + where None = <CodinGamer id=*** pseudo='***'>.avatar_url
assert isinstance(codingamer.cover_url, str)
assert isinstance(codingamer.profile_url, str)


def test_codingamer_eq(client: Client, codingamer: CodinGamer):
def test_codingamer_eq(client: Client, codingamer: CodinGamer, mock_http):
mock_http(client._state.http, "get_codingamer_from_handle")
other_codingamer = client.get_codingamer(
os.environ.get("TEST_CODINGAMER_PUBLIC_HANDLE")
)
assert codingamer == other_codingamer


def test_codingamer_get_followers(codingamer: CodinGamer):
def test_codingamer_get_followers(codingamer: CodinGamer, mock_http):
mock_http(codingamer._state.http, "get_codingamer_followers")
for follower in codingamer.get_followers():
assert isinstance(follower, CodinGamer)

Expand All @@ -41,13 +47,15 @@ def test_codingamer_get_followers_error(client: Client):
next(codingamer.get_followers())


def test_codingamer_get_followers_ids(codingamer: CodinGamer):
def test_codingamer_get_followers_ids(codingamer: CodinGamer, mock_http):
mock_http(codingamer._state.http, "get_codingamer_follower_ids")
followers_ids = codingamer.get_followers_ids()
assert isinstance(followers_ids, list)
assert all(isinstance(follower_id, int) for follower_id in followers_ids)


def test_codingamer_get_followed(codingamer: CodinGamer):
def test_codingamer_get_followed(codingamer: CodinGamer, mock_http):
mock_http(codingamer._state.http, "get_codingamer_following")
for followed in codingamer.get_followed():
assert isinstance(followed, CodinGamer)

Expand All @@ -60,12 +68,14 @@ def test_codingamer_get_followed_error(client: Client):
next(codingamer.get_followed())


def test_codingamer_get_followed_ids(codingamer: CodinGamer):
def test_codingamer_get_followed_ids(codingamer: CodinGamer, mock_http):
mock_http(codingamer._state.http, "get_codingamer_following_ids")
followed_ids = codingamer.get_followed_ids()
assert isinstance(followed_ids, list)
assert all(isinstance(followed_id, int) for followed_id in followed_ids)


def test_codingamer_get_clash_of_code_rank(codingamer: CodinGamer):
def test_codingamer_get_clash_of_code_rank(codingamer: CodinGamer, mock_http):
mock_http(codingamer._state.http, "get_codingamer_clash_of_code_rank")
rank = codingamer.get_clash_of_code_rank()
assert isinstance(rank, int)

0 comments on commit 0efa19e

Please sign in to comment.