From 92895521ad4f0794d27d95a85f3ae0db092439c5 Mon Sep 17 00:00:00 2001 From: Aaron Godfrey Date: Thu, 18 May 2023 17:46:27 -0700 Subject: [PATCH] Fix case where discount_pct is None. --- .pre-commit-config.yaml | 2 +- custom_components/steam_wishlist/entities.py | 2 + tests/test_util.py | 139 ++++++++++++------- 3 files changed, 93 insertions(+), 50 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 84a6e6d..77e4dc5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ repos: - id: pyupgrade args: [--py37-plus] - repo: https://github.com/psf/black - rev: 20.8b1 + rev: 23.3.0 hooks: - id: black args: diff --git a/custom_components/steam_wishlist/entities.py b/custom_components/steam_wishlist/entities.py index 38bed62..5446fb0 100644 --- a/custom_components/steam_wishlist/entities.py +++ b/custom_components/steam_wishlist/entities.py @@ -115,6 +115,8 @@ def is_on(self): discount_pct = pricing["discount_pct"] except IndexError: discount_pct = 0 + if discount_pct is None: + return False return discount_pct > 0 @property diff --git a/tests/test_util.py b/tests/test_util.py index 950f523..a1908ae 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -4,98 +4,139 @@ def test_get_steam_game_unreleased_game() -> None: """Test that we get the correct return value for an unreleased game.""" - game_id = "870780" + game_id = "12007070" game = { - "name": "Control", - "capsule": "https://steamcdn-a.akamaihd.net/steam/apps/870780/header_292x136.jpg?t=1572428374", - "release_date": "1556236800", - "release_string": "Coming August 2020", - "review_desc": "3 user reviews", - "reviews_percent": 100, - "reviews_total": "3", + "name": "Deathground", + "capsule": "https://cdn.akamai.steamstatic.com/steam/apps/1200770/header_292x136.jpg?t=1680256324", + "review_score": 0, + "review_desc": "No user reviews", + "reviews_total": "0", + "reviews_percent": 0, + "release_date": 1684421117, + "release_string": "Coming soon", + "platform_icons": "", "subs": [], "type": "Game", + "screenshots": [], + "review_css": "no_reviews", + "priority": 0, + "added": 1598977652, + "background": "", + "rank": 1000, + "tags": [], + "is_free_game": False, + "deck_compat": 0, + "prerelease": 1, + "win": 1, } actual = get_steam_game(game_id, game) expected = { - "box_art_url": "https://steamcdn-a.akamaihd.net/steam/apps/870780/header_292x136.jpg?t=1572428374", + "box_art_url": "https://cdn.akamai.steamstatic.com/steam/apps/1200770/header_292x136.jpg?t=1680256324", "normal_price": None, "percent_off": 0, - "review_desc": "3 user reviews", - "reviews_percent": 100, - "reviews_total": "3", + "review_desc": "No user reviews", + "reviews_percent": 0, + "reviews_total": "0", "sale_price": None, - "steam_id": "870780", - "title": "Control", + "steam_id": game_id, + "title": "Deathground", } assert expected == actual def test_get_steam_game_with_sale_price() -> None: """Test that we get the correct return value for a normal on sale game.""" - game_id = "975150" + game_id = "1262350" game = { - "name": "Resolutiion", - "capsule": "https://steamcdn-a.akamaihd.net/steam/apps/975150/header_292x136.jpg?t=1590678003", + "name": "SIGNALIS", + "capsule": "https://cdn.akamai.steamstatic.com/steam/apps/1262350/header_292x136.jpg?t=1684085470", + "review_score": 9, + "review_desc": "Overwhelmingly Positive", + "reviews_total": "6,844", + "reviews_percent": 97, + "release_date": "1666879183", + "release_string": "Oct 27, 2022", + "platform_icons": "", "subs": [ { - "id": 320073, - "discount_block": '
-15%
$19.99
$16.99
', - "discount_pct": 15, - "price": 1699, + "packageid": 438763, + "bundleid": None, + "discount_block": "", + "discount_pct": 20, + "price": "1599", } ], "type": "Game", - "added": 1590721175, - "review_desc": "3 user reviews", - "reviews_percent": 100, - "reviews_total": "3", + "screenshots": [], + "review_css": "positive", + "priority": 0, + "added": 1669934204, + "background": "", + "rank": 558, + "tags": [], + "is_free_game": False, + "deck_compat": "3", + "win": 1, } actual = get_steam_game(game_id, game) expected = { - "box_art_url": "https://steamcdn-a.akamaihd.net/steam/apps/975150/header_292x136.jpg?t=1590678003", + "box_art_url": "https://cdn.akamai.steamstatic.com/steam/apps/1262350/header_292x136.jpg?t=1684085470", "normal_price": 19.99, - "percent_off": 15, - "review_desc": "3 user reviews", - "reviews_percent": 100, - "reviews_total": "3", - "sale_price": 16.99, - "steam_id": "975150", - "title": "Resolutiion", + "percent_off": 20, + "review_desc": "Overwhelmingly Positive", + "reviews_percent": 97, + "reviews_total": "6,844", + "sale_price": 15.99, + "steam_id": game_id, + "title": "SIGNALIS", } assert expected == actual def test_get_steam_game_with_100_percent_discount() -> None: """Test that a free game doesn't cause a division by zero error.""" - game_id = "975150" + game_id = "1262350" game = { - "name": "Resolutiion", - "capsule": "https://steamcdn-a.akamaihd.net/steam/apps/975150/header_292x136.jpg?t=1590678003", + "name": "SIGNALIS", + "capsule": "https://cdn.akamai.steamstatic.com/steam/apps/1262350/header_292x136.jpg?t=1684085470", + "review_score": 9, + "review_desc": "Overwhelmingly Positive", + "reviews_total": "6,844", + "reviews_percent": 97, + "release_date": "1666879183", + "release_string": "Oct 27, 2022", + "platform_icons": "", "subs": [ { - "id": 320073, - "discount_block": '
-15%
$19.99
$16.99
', + "packageid": 438763, + "bundleid": None, + "discount_block": "", "discount_pct": 100, - "price": 0, + "price": "0", } ], "type": "Game", - "added": 1590721175, - "review_desc": "3 user reviews", - "reviews_percent": 100, - "reviews_total": "3", + "screenshots": [], + "review_css": "positive", + "priority": 0, + "added": 1669934204, + "background": "", + "rank": 558, + "tags": [], + "is_free_game": False, + "deck_compat": "3", + "win": 1, } actual = get_steam_game(game_id, game) expected = { - "box_art_url": "https://steamcdn-a.akamaihd.net/steam/apps/975150/header_292x136.jpg?t=1590678003", + "box_art_url": "https://cdn.akamai.steamstatic.com/steam/apps/1262350/header_292x136.jpg?t=1684085470", "normal_price": 0, "percent_off": 100, - "review_desc": "3 user reviews", - "reviews_percent": 100, - "reviews_total": "3", + "review_desc": "Overwhelmingly Positive", + "reviews_percent": 97, + "reviews_total": "6,844", "sale_price": 0, - "steam_id": "975150", - "title": "Resolutiion", + "steam_id": game_id, + "title": "SIGNALIS", } assert expected == actual