Skip to content

Commit

Permalink
Fix case where discount_pct is None.
Browse files Browse the repository at this point in the history
  • Loading branch information
boralyl committed May 19, 2023
1 parent e5813e2 commit 9289552
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions custom_components/steam_wishlist/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
139 changes: 90 additions & 49 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": '<div class="discount_block discount_block_large" data-price-final="1699"><div class="discount_pct">-15%</div><div class="discount_prices"><div class="discount_original_price">$19.99</div><div class="discount_final_price">$16.99</div></div></div>',
"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": '<div class="discount_block discount_block_large" data-price-final="1699"><div class="discount_pct">-15%</div><div class="discount_prices"><div class="discount_original_price">$19.99</div><div class="discount_final_price">$16.99</div></div></div>',
"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

0 comments on commit 9289552

Please sign in to comment.