diff --git a/.bumpversion.cfg b/.bumpversion.cfg index e2fd9fa..a0ed8bf 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.4.0 +current_version = 0.5.0 commit = True tag = True diff --git a/README.md b/README.md index 0ef3427..5ecb70d 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,13 @@ Install the package with pip: python -m pip install synotools ``` +Unix users (Linux, Mac) Create your credentials file in `~/.synotools/credentials`: +Windows users: +Use `C:\Users\\.synotools\credentials.txt` instead. + + ``` # Device access credentials SYNOLOGY_IP=your-ip diff --git a/docker/scripts/tests b/docker/scripts/tests index ec9b8dc..5a5d7c7 100755 --- a/docker/scripts/tests +++ b/docker/scripts/tests @@ -12,7 +12,7 @@ echo "--> Running tests with coverage..." coverage run \ --source=synotools \ - -- $(which pytest) -v --durations=20 --tb=short --junit-xml=artifacts/test-report.xml tests/unit + -- $(which pytest) -v --durations=20 --tb=short --junit-xml=artifacts/test-report.xml tests/unit tests/integration/settings echo "--> Coverage stats..." coverage html diff --git a/requirements-dev.txt b/requirements-dev.txt index a451953..9ecda5e 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -6,6 +6,7 @@ coverage coveralls flake8 freezegun +ipython isort mypy pytest diff --git a/setup.py b/setup.py index 04694c3..d813f72 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="synotools", - version="0.4.0", + version="0.5.0", author="Ed Garabito", author_email="eduardo@gottabegarabi.com", description="A Python API wrapper and toolset to interact with Synology NAS devices.", diff --git a/synotools/settings.py b/synotools/settings.py index f2b926a..c77a6f2 100644 --- a/synotools/settings.py +++ b/synotools/settings.py @@ -1,18 +1,22 @@ import os +import sys from os.path import join from pathlib import Path from dotenv import load_dotenv -CREDENTIALS_PATH = ".synotools/credentials" - class Settings: def __init__(self): - load_dotenv(dotenv_path=self.get_local_credentials_path, verbose=True) + load_dotenv(dotenv_path=self.credentials_path, verbose=True) @property - def get_local_credentials_path(self): + def credentials_path(self): + if sys.platform.startswith("win"): + CREDENTIALS_PATH = ".synotools\\credentials.txt" + else: + CREDENTIALS_PATH = ".synotools/credentials" + return join(str(Path.home()), CREDENTIALS_PATH) def get_environmental_variable(self, var_name): diff --git a/tests/integration/settings/test_settings_os.py b/tests/integration/settings/test_settings_os.py new file mode 100644 index 0000000..88982e0 --- /dev/null +++ b/tests/integration/settings/test_settings_os.py @@ -0,0 +1,31 @@ +from synotools.settings import Settings + + +class TestSettingsOS: + def test_get_environmental_variable_loads_credentials_from_expected_location_on_linux( + self, mocker, + ): + # Arrange + mocker.patch("synotools.settings.sys.platform", "linux") + + # Act + target = Settings() + + actual = target.credentials_path + + # Assert + assert actual.endswith("credentials") + + def test_get_environmental_variable_loads_credentials_from_expected_location_on_windows( + self, mocker, + ): + # Arrange + mocker.patch("synotools.settings.sys.platform", "win32") + + # Act + target = Settings() + + actual = target.credentials_path + + # Assert + assert actual.endswith("credentials.txt") diff --git a/tests/unit/test_settings.py b/tests/unit/settings/test_settings.py similarity index 86% rename from tests/unit/test_settings.py rename to tests/unit/settings/test_settings.py index 36778dc..da4d1d9 100644 --- a/tests/unit/test_settings.py +++ b/tests/unit/settings/test_settings.py @@ -4,7 +4,7 @@ def test_get_environmental_variable_loads_credentials_from_expected_location(mocker): mocker.patch( - "synotools.settings.Settings.get_local_credentials_path", + "synotools.settings.Settings.credentials_path", "home/test-user/.my-test/credentials", )