Skip to content

Commit

Permalink
Fixed North American image urls.
Browse files Browse the repository at this point in the history
  • Loading branch information
boralyl committed Jul 6, 2022
1 parent c24e94f commit 774bce3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 29 deletions.
4 changes: 2 additions & 2 deletions custom_components/nintendo_wishlist/eshop.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ async def fetch_on_sale(self) -> EShopResults:
def get_na_switch_game(self, game: dict[str, Any]) -> SwitchGame:
"""Get a SwitchGame from a json result."""
box_art = game.get("boxart", game.get("gallery"))
if not box_art or not box_art.endswith((".png", ".jpg")):
if not box_art:
box_art_url = NO_BOX_ART_URL
else:
box_art_url = f"https://www.nintendo.com{box_art}"
box_art_url = box_art

return {
"box_art_url": box_art_url,
Expand Down
32 changes: 5 additions & 27 deletions tests/test_eshop.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ def client_mock():
client = Mock()
games = [
{
"boxart": "image.png",
"boxart": "https://assets.nintendo.com/0/box-eShop",
"msrp": 24.99,
"nsuid": 70010000531,
"salePrice": 9.99,
"title": "Picross",
},
{
"boxart": "image.png",
"boxart": "https://assets.nintendo.com/1/box-eShop",
"msrp": 14.99,
"nsuid": 70010000532,
"salePrice": 8.24,
Expand Down Expand Up @@ -77,28 +77,6 @@ def test_get_na_switch_game_no_box_art_value_error():
assert expected == eshop.get_na_switch_game(game)


def test_get_na_switch_game_bad_prefix_value_error():
"""Test no box art url is used if the game has the wrong extension."""
wishlist = ["title1"]
eshop = EShop("US", Mock(), wishlist)
game = {
"boxart": "image.exe",
"msrp": 14.99,
"nsuid": 70010000532,
"salePrice": 8.24,
"title": "Aggelos",
}
expected = {
"box_art_url": NO_BOX_ART_URL,
"normal_price": "$14.99",
"nsuid": 70010000532,
"percent_off": 45,
"sale_price": "$8.24",
"title": "Aggelos",
}
assert expected == eshop.get_na_switch_game(game)


def test_get_na_switch_game_success():
"""Test we return the expected SwitchGame instance from the response."""
wishlist = ["title1"]
Expand All @@ -111,7 +89,7 @@ def test_get_na_switch_game_success():
"title": "Aggelos",
}
expected = {
"box_art_url": "https://www.nintendo.comimage.png",
"box_art_url": "image.png",
"normal_price": "$14.99",
"nsuid": 70010000532,
"percent_off": 45,
Expand All @@ -130,7 +108,7 @@ async def test__get_page(client_mock):
expected = {
"games": {
70010000532: {
"box_art_url": "https://www.nintendo.comimage.png",
"box_art_url": "https://assets.nintendo.com/1/box-eShop",
"normal_price": "$14.99",
"nsuid": 70010000532,
"percent_off": 45,
Expand All @@ -155,7 +133,7 @@ async def test_fetch_na(client_mock):

expected = {
70010000532: {
"box_art_url": "https://www.nintendo.comimage.png",
"box_art_url": "https://assets.nintendo.com/1/box-eShop",
"normal_price": "$14.99",
"nsuid": 70010000532,
"percent_off": 45,
Expand Down

0 comments on commit 774bce3

Please sign in to comment.