Skip to content

Commit

Permalink
added code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ZohebShaikh committed Dec 12, 2024
1 parent 3f728ec commit 4b06c4e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
16 changes: 6 additions & 10 deletions src/blueapi/service/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from blueapi.config import OIDCConfig
from blueapi.service.model import Cache

BLUEAPI_CACHE_LOCATION = "~/.cache/blueapi_cache"
BLUEAPI_CACHE_LOCATION = "~/.cache/"
SCOPES = "openid offline_access"


Expand All @@ -34,7 +34,7 @@ def delete_cache(self) -> None: ...
class SessionCacheManager(CacheManager):
def __init__(self, token_path: Path | None) -> None:
self._token_path: Path = (
token_path if token_path else self._get_xdg_cache_path()
token_path if token_path else self._default_token_cache_path()
)

@cached_property
Expand All @@ -56,16 +56,12 @@ def load_cache(self) -> Cache:
def delete_cache(self) -> None:
Path(self._file_path).unlink(missing_ok=True)

def _get_xdg_cache_path(self) -> Path:
def _default_token_cache_path(self) -> Path:
"""
Return the XDG cache file path.
Return the default cache file path.
"""
cache_path = os.environ.get("XDG_CACHE_HOME")
if not cache_path:
cache_path = os.path.expanduser(BLUEAPI_CACHE_LOCATION)
elif os.path.isdir(cache_path):
cache_path = Path(cache_path) / "blueapi_cache"
return Path(cache_path)
cache_path = os.environ.get("XDG_CACHE_HOME", BLUEAPI_CACHE_LOCATION)
return Path(cache_path).expanduser() / "blueapi_cache"


class SessionManager:
Expand Down
11 changes: 5 additions & 6 deletions tests/unit_tests/service/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,8 @@ def test_processes_valid_token(


def test_session_cache_manager_returns_writable_file_path(tmp_path):
with patch("os.environ.get") as xdg_directory:
xdg_directory.return_value = tmp_path
cache = SessionCacheManager(token_path=None)
with open(cache._file_path, "xb") as token_file:
assert token_file.writable()
assert cache._file_path == f"{tmp_path}/blueapi_cache"
os.environ["XDG_CACHE_HOME"] = str(tmp_path)
cache = SessionCacheManager(token_path=None)
Path(cache._file_path).touch()
assert os.path.isfile(cache._file_path)
assert cache._file_path == f"{tmp_path}/blueapi_cache"

0 comments on commit 4b06c4e

Please sign in to comment.