From 9d068b9aa617cfd9f2511fbafedcf146dce4074f Mon Sep 17 00:00:00 2001 From: Aaron Godfrey Date: Mon, 21 Dec 2020 19:37:55 -0800 Subject: [PATCH] Fixes #16 --- custom_components/nintendo_wishlist/eshop.py | 5 ++++- tests/test_eshop.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/custom_components/nintendo_wishlist/eshop.py b/custom_components/nintendo_wishlist/eshop.py index 6e6b46d..ddc7c0a 100644 --- a/custom_components/nintendo_wishlist/eshop.py +++ b/custom_components/nintendo_wishlist/eshop.py @@ -178,8 +178,11 @@ async def _get_eu_page(self, page: int = 0) -> ResultsDict: def get_eu_switch_game(self, game: dict) -> SwitchGame: try: + image_url = game["image_url"] + if not image_url.startswith("https:"): + image_url = f"https:{image_url}" return { - "box_art_url": f"https:{game['image_url']}", + "box_art_url": image_url, "nsuid": int(game["nsuid_txt"][0]), "percent_off": game["price_discount_percentage_f"], "title": game["title"], diff --git a/tests/test_eshop.py b/tests/test_eshop.py index c170409..50278fa 100644 --- a/tests/test_eshop.py +++ b/tests/test_eshop.py @@ -225,6 +225,26 @@ def test_get_eu_switch_game(): assert expected == actual +def test_get_eu_switch_game_with_https_prefix_on_image_url(): + """Regression test for when the image_url actually has a protocol.""" + wishlist = ["Aggelos"] + eshop = EShop("DE", Mock(), wishlist) + game = { + "title": "Aggelos", + "image_url": "https://nintendo.com/image.png", + "nsuid_txt": ["70010000532"], + "price_discount_percentage_f": 10, + } + actual = eshop.get_eu_switch_game(game) + expected = { + "box_art_url": "https://nintendo.com/image.png", + "nsuid": 70010000532, + "percent_off": 10, + "title": "Aggelos", + } + assert expected == actual + + async def test_fetch_eu(): """Test the fetch_eu method returns the expected result.""" page_response = {