Skip to content

Commit

Permalink
test: no API key in config (#88)
Browse files Browse the repository at this point in the history
* test: no API key in config

* fix: exception checks
  • Loading branch information
chadsr committed May 27, 2024
1 parent baf36df commit 09431b0
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions tests/test_waybar_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,8 @@ def test_read_config_min_precision():
tmp.flush()
tmp_config_path = tmp.file.name

try:
with pytest.raises(WaybarCryptoException):
_ = read_config(tmp_config_path)
except Exception as e:
assert isinstance(e, WaybarCryptoException)


def test_read_config_display_options_single():
Expand Down Expand Up @@ -345,10 +343,23 @@ def test_read_config_display_invalid():
tmp.flush()
tmp_config_path = tmp.file.name

try:
with pytest.raises(WaybarCryptoException):
_ = read_config(tmp_config_path)


def test_read_config_no_api_key():
with open(TEST_CONFIG_PATH, "r", encoding="utf-8") as f:
cfp = configparser.ConfigParser(allow_no_value=True, interpolation=None)
cfp.read_file(f)
cfp.set("general", "api_key", "")

with tempfile.NamedTemporaryFile(mode="w") as tmp:
cfp.write(tmp)
tmp.flush()
tmp_config_path = tmp.file.name

with pytest.raises(NoApiKeyException):
_ = read_config(tmp_config_path)
except Exception as e:
assert isinstance(e, WaybarCryptoException)


class TestWaybarCrypto:
Expand Down Expand Up @@ -393,10 +404,8 @@ def test_get_coinmarketcap_latest(self):

@mock.patch.dict(os.environ, {API_KEY_ENV: ""})
def test_get_coinmarketcap_latest_invalid_key(self, waybar_crypto: WaybarCrypto):
try:
with pytest.raises(CoinmarketcapApiException):
_ = waybar_crypto.coinmarketcap_latest()
except Exception as e:
assert isinstance(e, CoinmarketcapApiException)

def test_waybar_output(self, waybar_crypto: WaybarCrypto, quotes_latest: ResponseQuotesLatest):
output = waybar_crypto.waybar_output(quotes_latest)
Expand All @@ -410,8 +419,6 @@ def test_waybar_output(self, waybar_crypto: WaybarCrypto, quotes_latest: Respons

@mock.patch.dict(os.environ, {API_KEY_ENV: ""})
def test_no_api_key(self, config: Config):
try:
with pytest.raises(NoApiKeyException):
config["general"]["api_key"] = ""
_ = WaybarCrypto(config)
except Exception as e:
assert isinstance(e, NoApiKeyException)

0 comments on commit 09431b0

Please sign in to comment.