Skip to content

Commit

Permalink
push settings coverage to 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Dec 18, 2024
1 parent 4569515 commit 8f0ba13
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/edutap/wallet_google/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ def google_root_signing_public_keys(self) -> RootSigningPublicKeys:
GOOGLE_ROOT_SIGNING_PUBLIC_KEYS_URL[self.google_environment]
)
resp.raise_for_status()
return RootSigningPublicKeys.model_validate_json(resp.text)
GOOGLE_ROOT_SIGNING_PUBLIC_KEYS_VALUE[self.google_environment] = RootSigningPublicKeys.model_validate_json(resp.text)
return GOOGLE_ROOT_SIGNING_PUBLIC_KEYS_VALUE[self.google_environment]

@property
def credentials_info(self) -> dict[str, str]:
if credentials_info := self.cached_credentials_info:
return credentials_info
if not self.credentials_file.exists():
raise ValueError(
raise FileNotFoundError(
f"EDUTAP_WALLET_GOOGLE_CREDENTIALS_FILE={self.credentials_file} does not exist."
)
with open(self.credentials_file) as fp:
Expand Down
1 change: 1 addition & 0 deletions tests/data/credentials_fake_wrong.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1, 2]
23 changes: 23 additions & 0 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from edutap.wallet_google.settings import ROOT_DIR
from edutap.wallet_google.settings import Settings

import pytest
import pathlib

def test_base_settings():
settings = Settings()
Expand Down Expand Up @@ -28,3 +30,24 @@ def test_local_settings(monkeypatch):

assert settings.issuer_id == "1234567890123456789"
assert settings.credentials_file.exists()

def test_settings_cached(mock_settings):
mock_settings.cached_credentials_info = "test"
assert mock_settings.credentials_info == "test"

def test_settings_cached_empty(mock_settings):
assert mock_settings.google_root_signing_public_keys is not None

from edutap.wallet_google.settings import GOOGLE_ROOT_SIGNING_PUBLIC_KEYS_VALUE
assert GOOGLE_ROOT_SIGNING_PUBLIC_KEYS_VALUE.get(mock_settings.google_environment, None) is not None
assert mock_settings.google_root_signing_public_keys is not None

def test_settings_no_credentials_file(mock_settings):
mock_settings.credentials_file = pathlib.Path("nonexistent.json")
with pytest.raises(FileNotFoundError):
mock_settings.credentials_info

def test_settings_wrong_credentials_file(mock_settings):
mock_settings.credentials_file = ROOT_DIR / "tests" / "data" / "credentials_fake_wrong.json"
with pytest.raises(ValueError):
mock_settings.credentials_info

0 comments on commit 8f0ba13

Please sign in to comment.