Skip to content

Commit

Permalink
version 0.55.5
Browse files Browse the repository at this point in the history
  • Loading branch information
FriendsOfGalaxy committed Oct 20, 2021
1 parent 175203a commit 8ca723d
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 29 deletions.
51 changes: 30 additions & 21 deletions src/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ async def get_owned_games(self):
self._parse_local_games()
self._parse_local_game_ownership()

await self._parse_club_games()
try:
await self._parse_club_games()
except Exception as e:
log.exception(f"Parsing club games failed: {repr(e)}")

try:
await self._parse_subscription_games()
except Exception as e:
Expand Down Expand Up @@ -133,33 +137,38 @@ def get_platforms(game):
platforms.append(platform.get('type', ''))
return platforms

def parse_game(game: dict) -> UbisoftGame:
log.info(f"Parsed game from Club Request {game['name']}")
return UbisoftGame(
space_id=game['spaceId'],
launch_id='',
install_id='',
third_party_id='',
name=game['name'],
path='',
type=GameType.New,
special_registry_path='',
exe='',
status=GameStatus.Unknown,
owned=True
)

if not self.parsing_club_games:
try:
self.parsing_club_games = True
data = await self.client.get_club_titles()
games = data['data']['viewer']['ownedGames'].get('nodes', [])
club_games = []
for game in games:
platforms = get_platforms(game)
if "PC" in platforms:
log.info(f"Parsed game from Club Request {game['name']}")
club_games.append(
UbisoftGame(
space_id=game['spaceId'],
launch_id='',
install_id='',
third_party_id='',
name=game['name'],
path='',
type=GameType.New,
special_registry_path='',
exe='',
status=GameStatus.Unknown,
owned=True
))
else:
log.debug(f"Skipped game from Club Request for {platforms}: {game['spaceId']}, {game['name']}")

try:
platforms = get_platforms(game)
if "PC" in platforms:
club_games.append(parse_game(game))
else:
log.debug(f"Skipped game from Club Request for {platforms}: {game['spaceId']}, {game['name']}")
except TypeError as e:
log.warning("Raised an error: %s for game: %s" % (e, game))
continue
self.games_collection.extend(club_games)
except (KeyError, TypeError) as e:
log.error(f"Unknown response from Ubisoft during parsing club games {repr(e)}")
Expand Down
5 changes: 4 additions & 1 deletion src/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
__version__ = '0.55.4'
__version__ = '0.55.5'

__changelog__ = {
"0.55.5": """
- fix parsing club games during fetching owned games; extend logging for unparsable items
""",
"0.55.4": """
- hotfix fetching club games by replacing version of API endpoint
""",
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ def function():

@pytest.fixture()
def authenticated_plugin(create_authenticated_plugin):
return create_authenticated_plugin()
return create_authenticated_plugin()
86 changes: 80 additions & 6 deletions tests/test_owned_games.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import asyncio
import json
from unittest.mock import Mock

import pytest
from galaxy.api.consts import LicenseType
from galaxy.api.errors import UnknownBackendResponse
from galaxy.api.types import Game, LicenseInfo
from galaxy.unittest.mock import AsyncMock

from definitions import UbisoftGame, GameType, GameStatus


@pytest.fixture
def result_owned_club_games():
Expand Down Expand Up @@ -35,13 +37,28 @@ def test_owned_games_club_only(create_authenticated_plugin, result_owned_club_ga
"BAD_RESPONSE",
None,
])
def test_owned_games_club_only_unknown_backend_response(create_authenticated_plugin, backend_client, response):
loop = asyncio.get_event_loop()
pg = create_authenticated_plugin()
@pytest.mark.asyncio
async def test_owned_games_with_unknown_response_from_club_games(authenticated_plugin, backend_client, response):
backend_client.get_club_titles = AsyncMock(return_value=response)
owned_game_from_ownership_file = UbisoftGame(
space_id='',
launch_id="GAME_ID",
install_id=Mock(str),
third_party_id='',
name="GAME_TITLE",
path='',
type=GameType.New,
special_registry_path='',
exe='',
status=GameStatus.Unknown,
owned=True,
activation_id=Mock(str)
)
authenticated_plugin.games_collection = [owned_game_from_ownership_file]

with pytest.raises(UnknownBackendResponse):
loop.run_until_complete(pg.get_owned_games())
result = await authenticated_plugin.get_owned_games()

assert result == [Game("GAME_ID", "GAME_TITLE", [], LicenseInfo(LicenseType.SinglePurchase))]


@pytest.mark.parametrize("type", [
Expand Down Expand Up @@ -103,3 +120,60 @@ def test_owned_games_club_only_with_multi_platform_groups(create_authenticated_p
result = loop.run_until_complete(pg.get_owned_games())
assert result == expected_result


@pytest.mark.asyncio
async def test_owned_games_with_null_meta_in_viewer_club_games_response(authenticated_plugin, backend_client):
data = {
"data": {
"viewer": {
"id": "57a84edf-09d7-448f-a18f-09c504b84637",
"ownedGames": {
"totalCount": 1,
"nodes": [
{
"id": "GAME_ID_1",
"spaceId": "GAME_ID_1",
"name": "GAME_1",
"viewer": {
"meta": None
}
},
{
"id": "GAME_ID_2",
"spaceId": "GAME_ID_2",
"name": "GAME_2",
"viewer": None
},
{
"id": "GAME_ID_3",
"spaceId": "GAME_ID_3",
"name": "GAME_3",
"viewer": {
"meta": {
"ownedPlatformGroups": [
[
{
"id": "35c5c607-2717-47d9-9323-7df47c6e1c4d",
"type": "PC"
},
],
]
}
}
},
]
}
}
}
}
backend_client.get_club_titles = AsyncMock(return_value=data)
expected_result = [Game(
"GAME_ID_3",
"GAME_3",
[],
LicenseInfo(LicenseType.SinglePurchase)
)]

result = await authenticated_plugin.get_owned_games()

assert result == expected_result

0 comments on commit 8ca723d

Please sign in to comment.