Skip to content

Commit

Permalink
Return full path to avoid IsADirectoryError
Browse files Browse the repository at this point in the history
When getting local path, the full path is not returned
only the directory (ADAPTER_DATA_DIR) raising an IsADirectoryError
when opening the CSP config file

Return the full path, directory + filename

Add test for get_local_path(filename) method
  • Loading branch information
jesusbv committed Jul 27, 2023
1 parent 8ad9f2a commit ae586c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 1 addition & 2 deletions csp_billing_adapter_local/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def get_local_path(filename):
local_storage_path = Path(ADAPTER_DATA_DIR)
if not local_storage_path.exists():
local_storage_path.mkdir(parents=True, exist_ok=True)
local_storage_path.joinpath(filename)
return local_storage_path
return local_storage_path.joinpath(filename)


@csp_billing_adapter.hookimpl(trylast=True)
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@


from csp_billing_adapter_local.plugin import (
get_local_path,
get_cache,
get_csp_config,
update_cache,
Expand All @@ -47,6 +48,12 @@
)


def test_local_get_local_path():
"""Test get_local_path(filename) in local plugin"""
expected_path = Path('/var/lib/csp-billing-adapter/foo')
assert get_local_path('foo') == expected_path


def test_local_get_cache():
"""Test get_cache() in local plugin"""
with patch(
Expand Down

0 comments on commit ae586c0

Please sign in to comment.