Skip to content

Commit

Permalink
fix response quotes return structure
Browse files Browse the repository at this point in the history
  • Loading branch information
chadsr committed May 25, 2024
1 parent 7c7d874 commit 682f57d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
41 changes: 21 additions & 20 deletions tests/test_waybar_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,27 @@ def test_get_coinmarketcap_latest(self, waybar_crypto: WaybarCrypto):
assert field in resp_quotes_latest
assert isinstance(resp_quotes_latest[field], dict)

assert "quote" in resp_quotes_latest["data"]
quote = resp_quotes_latest["data"]["quote"]
assert isinstance(quote, dict)

quote_fields_types = {
"price": float,
"volume_24h": float,
"volume_change_24h": float,
"percent_change_1h": float,
"percent_change_24h": float,
"percent_change_7d": float,
"percent_change_30d": float,
"percent_change_60d": float,
"percent_change_90d": float,
}

for quote_values in quote.values():
for field, field_type in quote_fields_types.items():
assert field in quote_values
assert isinstance(quote_values[field], field_type)
for coin_data in resp_quotes_latest["data"].values():
assert "quote" in coin_data
quote = coin_data["quote"]
assert isinstance(quote, dict)

quote_fields_types = {
"price": float,
"volume_24h": float,
"volume_change_24h": float,
"percent_change_1h": float,
"percent_change_24h": float,
"percent_change_7d": float,
"percent_change_30d": float,
"percent_change_60d": float,
"percent_change_90d": float,
}

for quote_values in quote.values():
for field, field_type in quote_fields_types.items():
assert field in quote_values
assert isinstance(quote_values[field], field_type)

def test_waybar_output(self, waybar_crypto: WaybarCrypto, quotes_latest: ResponseQuotesLatest):
output = waybar_crypto.waybar_output(quotes_latest)
Expand Down
2 changes: 1 addition & 1 deletion waybar_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ResponseQuotesLatest(TypedDict):
"""Latest quotes response returns by the Coinmarketcap API"""

status: ResponseStatus
data: QuoteData
data: dict[str, QuoteData]


class WaybarCryptoException(Exception):
Expand Down

0 comments on commit 682f57d

Please sign in to comment.