From a3d5f220a3decaa025e30724d8fa070b99ccf547 Mon Sep 17 00:00:00 2001 From: Maciej Urbanski Date: Thu, 28 Mar 2024 14:58:59 +0100 Subject: [PATCH] Add SqliteAccountInfo.get_user_account_info_path to public API --- b2sdk/account_info/sqlite_account_info.py | 4 ++-- ...public_get_user_account_info_path.added.md | 1 + .../account_info/test_sqlite_account_info.py | 20 +++++++++---------- 3 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 changelog.d/+public_get_user_account_info_path.added.md diff --git a/b2sdk/account_info/sqlite_account_info.py b/b2sdk/account_info/sqlite_account_info.py index 69b7786a..d7372412 100644 --- a/b2sdk/account_info/sqlite_account_info.py +++ b/b2sdk/account_info/sqlite_account_info.py @@ -73,7 +73,7 @@ def __init__(self, file_name=None, last_upgrade_to_run=None, profile: str | None """ self.thread_local = threading.local() - self.filename = self._get_user_account_info_path(file_name=file_name, profile=profile) + self.filename = self.get_user_account_info_path(file_name=file_name, profile=profile) logger.debug('%s file path to use: %s', self.__class__.__name__, self.filename) self._validate_database(last_upgrade_to_run) @@ -105,7 +105,7 @@ def _get_xdg_config_path(cls) -> str | None: return None @classmethod - def _get_user_account_info_path(cls, file_name: str | None = None, profile: str | None = None): + def get_user_account_info_path(cls, file_name: str | None = None, profile: str | None = None): if profile and not B2_ACCOUNT_INFO_PROFILE_NAME_REGEXP.match(profile): raise ValueError(f'Invalid profile name: {profile}') diff --git a/changelog.d/+public_get_user_account_info_path.added.md b/changelog.d/+public_get_user_account_info_path.added.md new file mode 100644 index 00000000..380c562f --- /dev/null +++ b/changelog.d/+public_get_user_account_info_path.added.md @@ -0,0 +1 @@ +Add SqliteAccountInfo.get_user_account_info_path to public API. diff --git a/test/unit/account_info/test_sqlite_account_info.py b/test/unit/account_info/test_sqlite_account_info.py index 1bcd28c5..bea09b91 100644 --- a/test/unit/account_info/test_sqlite_account_info.py +++ b/test/unit/account_info/test_sqlite_account_info.py @@ -77,20 +77,20 @@ def setup(self, monkeypatch, tmpdir): def test_invalid_profile_name(self): with pytest.raises(ValueError): - SqliteAccountInfo._get_user_account_info_path(profile='&@(*$') + SqliteAccountInfo.get_user_account_info_path(profile='&@(*$') def test_profile_and_file_name_conflict(self): with pytest.raises(ValueError): - SqliteAccountInfo._get_user_account_info_path(file_name='foo', profile='bar') + SqliteAccountInfo.get_user_account_info_path(file_name='foo', profile='bar') def test_profile_and_env_var_conflict(self, monkeypatch): monkeypatch.setenv(B2_ACCOUNT_INFO_ENV_VAR, 'foo') with pytest.raises(ValueError): - SqliteAccountInfo._get_user_account_info_path(profile='bar') + SqliteAccountInfo.get_user_account_info_path(profile='bar') def test_profile_and_xdg_config_env_var(self, monkeypatch): monkeypatch.setenv(XDG_CONFIG_HOME_ENV_VAR, os.path.join('~', 'custom')) - account_info_path = SqliteAccountInfo._get_user_account_info_path(profile='secondary') + account_info_path = SqliteAccountInfo.get_user_account_info_path(profile='secondary') assert account_info_path == os.path.expanduser( os.path.join('~', 'custom', 'b2', 'db-secondary.sqlite') ) @@ -102,18 +102,18 @@ def test_profile(self, monkeypatch): else: expected_path = ('~', '.b2db-foo.sqlite') - account_info_path = SqliteAccountInfo._get_user_account_info_path(profile='foo') + account_info_path = SqliteAccountInfo.get_user_account_info_path(profile='foo') assert account_info_path == os.path.expanduser(os.path.join(*expected_path)) def test_file_name(self): - account_info_path = SqliteAccountInfo._get_user_account_info_path( + account_info_path = SqliteAccountInfo.get_user_account_info_path( file_name=os.path.join('~', 'foo') ) assert account_info_path == os.path.expanduser(os.path.join('~', 'foo')) def test_env_var(self, monkeypatch): monkeypatch.setenv(B2_ACCOUNT_INFO_ENV_VAR, os.path.join('~', 'foo')) - account_info_path = SqliteAccountInfo._get_user_account_info_path() + account_info_path = SqliteAccountInfo.get_user_account_info_path() assert account_info_path == os.path.expanduser(os.path.join('~', 'foo')) def test_default_file_if_exists(self, monkeypatch): @@ -124,12 +124,12 @@ def test_default_file_if_exists(self, monkeypatch): os.makedirs(parent_dir, exist_ok=True) with open(account_file_path, 'w') as account_file: account_file.write('') - account_info_path = SqliteAccountInfo._get_user_account_info_path() + account_info_path = SqliteAccountInfo.get_user_account_info_path() assert account_info_path == os.path.expanduser(B2_ACCOUNT_INFO_DEFAULT_FILE) def test_xdg_config_env_var(self, monkeypatch): monkeypatch.setenv(XDG_CONFIG_HOME_ENV_VAR, os.path.join('~', 'custom')) - account_info_path = SqliteAccountInfo._get_user_account_info_path() + account_info_path = SqliteAccountInfo.get_user_account_info_path() assert account_info_path == os.path.expanduser( os.path.join('~', 'custom', 'b2', 'account_info') ) @@ -141,5 +141,5 @@ def test_default_file(self): else: expected_path = B2_ACCOUNT_INFO_DEFAULT_FILE - account_info_path = SqliteAccountInfo._get_user_account_info_path() + account_info_path = SqliteAccountInfo.get_user_account_info_path() assert account_info_path == os.path.expanduser(expected_path)