From 2b2c293296a95d4ba8867a1c1e8ab95f184270c9 Mon Sep 17 00:00:00 2001 From: Robert Luttrell Date: Tue, 28 Nov 2023 10:08:32 -0800 Subject: [PATCH] feat: Add system config path for Windows Signed-off-by: Robert Luttrell --- .../configuration/_configuration_manager.py | 12 ++++++++- test/openjd/adaptor_runtime/conftest.py | 4 ++- .../test_configuration_manager.py | 25 +++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/openjd/adaptor_runtime/adaptors/configuration/_configuration_manager.py b/src/openjd/adaptor_runtime/adaptors/configuration/_configuration_manager.py index 3a95ed7..858a15e 100644 --- a/src/openjd/adaptor_runtime/adaptors/configuration/_configuration_manager.py +++ b/src/openjd/adaptor_runtime/adaptors/configuration/_configuration_manager.py @@ -61,7 +61,17 @@ def create_adaptor_configuration_manager( adaptor_name, f"{adaptor_name}.json", ) - ) + ), + "Windows": os.path.abspath( + os.path.join( + os.path.sep, + os.environ["PROGRAMDATA"], + "openjd", + "adaptors", + adaptor_name, + f"{adaptor_name}.json", + ) + ), } user_config_rel_path = os.path.join(".openjd", "adaptors", adaptor_name, f"{adaptor_name}.json") diff --git a/test/openjd/adaptor_runtime/conftest.py b/test/openjd/adaptor_runtime/conftest.py index 31600b4..fd695be 100644 --- a/test/openjd/adaptor_runtime/conftest.py +++ b/test/openjd/adaptor_runtime/conftest.py @@ -11,7 +11,9 @@ def pytest_collection_modifyitems(items): if OSName.is_windows(): # Add the tests' paths that we want to enable in Windows - do_not_skip_paths = [] + do_not_skip_paths = [ + "test\\openjd\\adaptor_runtime\\unit\\adaptors\\configuration\\test_configuration_manager.py" + ] skip_marker = pytest.mark.skip(reason="Skipping tests on Windows") for item in items: if not any(not_skip_path in item.fspath.strpath for not_skip_path in do_not_skip_paths): diff --git a/test/openjd/adaptor_runtime/unit/adaptors/configuration/test_configuration_manager.py b/test/openjd/adaptor_runtime/unit/adaptors/configuration/test_configuration_manager.py index 135260e..3e372e4 100644 --- a/test/openjd/adaptor_runtime/unit/adaptors/configuration/test_configuration_manager.py +++ b/test/openjd/adaptor_runtime/unit/adaptors/configuration/test_configuration_manager.py @@ -153,6 +153,18 @@ def test_creates_config_manager(self): assert result._system_config_path_map["Linux"] == ( f"/etc/openjd/adaptors/{adaptor_name}/{adaptor_name}.json" ) + assert result._system_config_path_map["Windows"] == ( + os.path.abspath( + os.path.join( + os.path.sep, + os.environ["PROGRAMDATA"], + "openjd", + "adaptors", + adaptor_name, + f"{adaptor_name}.json", + ) + ) + ) assert result._user_config_rel_path == os.path.join( ".openjd", "adaptors", adaptor_name, f"{adaptor_name}.json" ) @@ -499,6 +511,19 @@ def test_gets_linux_path(self, mock_system: MagicMock): mock_system.assert_called_once() assert result == expected + @patch.object(osname.platform, "system") + def test_gets_windows_path(self, mock_system: MagicMock): + # GIVEN + mock_system.return_value = "Windows" + expected = "path\\to\\windows\\system\\config" + manager = ConfigurationManagerMock(system_config_path_map={"Windows": expected}) + + # WHEN + result = manager.get_system_config_path() + + # THEN + assert result == expected + @patch.object(osname.platform, "system") def test_raises_on_nonvalid_os(self, mock_system: MagicMock): """