Skip to content

Commit

Permalink
feat(INSTALLER): idempotent user config installation
Browse files Browse the repository at this point in the history
  • Loading branch information
niall-byrne committed Jan 18, 2024
1 parent 59788b2 commit b277b38
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
5 changes: 4 additions & 1 deletion pi_portal/installation/steps/step_install_config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ def invoke(self) -> None:
"""Install the user's configuration file."""

self.log.info("Installing the user's configuration file ...")
shutil.copy(self.config_file_path, config.PATH_USER_CONFIG)
try:
shutil.copy(self.config_file_path, config.PATH_USER_CONFIG)
except shutil.SameFileError:
pass
self.log.info("Done writing the user's configuration file.")

self.log.info("Setting permissions on the user's configuration file ...")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Test the StepInstallConfigFile class."""
import logging
import shutil
from io import StringIO
from unittest import mock

Expand Down Expand Up @@ -30,7 +31,7 @@ def test__initialize__inheritance(
base_step.StepBase,
)

def test__invoke__success(
def test__invoke__success__no_exception(
self,
step_install_config_files_instance: StepInstallConfigFile,
mocked_config_file: str,
Expand Down Expand Up @@ -62,7 +63,41 @@ def test__invoke__success(
"configuration file.\n"
)

def test__invoke__failure(
def test__invoke__success__same_file_error(
self,
step_install_config_files_instance: StepInstallConfigFile,
mocked_config_file: str,
mocked_copy: mock.Mock,
mocked_file_system: mock.Mock,
mocked_stream: StringIO,
) -> None:
mocked_copy.side_effect = shutil.SameFileError

step_install_config_files_instance.invoke()

mocked_copy.assert_called_once_with(
mocked_config_file,
config.PATH_USER_CONFIG,
)
assert mocked_file_system.mock_calls == [
mock.call(config.PATH_USER_CONFIG),
mock.call().ownership(
config.PI_PORTAL_USER,
config.PI_PORTAL_USER,
),
mock.call().permissions("600"),
]
assert mocked_stream.getvalue() == \
(
"test - INFO - Installing the user's configuration file ...\n"
"test - INFO - Done writing the user's configuration file.\n"
"test - INFO - Setting permissions on the user's "
"configuration file ...\n"
"test - INFO - Done setting permissions on the user's "
"configuration file.\n"
)

def test__invoke__failure__os_error(
self,
step_install_config_files_instance: StepInstallConfigFile,
mocked_config_file: str,
Expand Down

0 comments on commit b277b38

Please sign in to comment.