Skip to content

Commit

Permalink
Merge pull request #8 from DazEdword/feature/windows-configuration-lo…
Browse files Browse the repository at this point in the history
…ading

Feature/windows configuration loading - Rc 0.5.0
  • Loading branch information
DazEdword authored Mar 15, 2020
2 parents de0f145 + bdcf996 commit 6bd9451
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.4.0
current_version = 0.5.0
commit = True
tag = True

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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\<YourUsername>\.synotools\credentials.txt` instead.


```
# Device access credentials
SYNOLOGY_IP=your-ip
Expand Down
2 changes: 1 addition & 1 deletion docker/scripts/tests
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ coverage
coveralls
flake8
freezegun
ipython
isort
mypy
pytest
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
12 changes: 8 additions & 4 deletions synotools/settings.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
31 changes: 31 additions & 0 deletions tests/integration/settings/test_settings_os.py
Original file line number Diff line number Diff line change
@@ -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")
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand Down

0 comments on commit 6bd9451

Please sign in to comment.