From 2fcb23b36d36b1d510cdb6e89fb4f8a17e97af4d Mon Sep 17 00:00:00 2001 From: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com> Date: Thu, 27 Jul 2023 13:55:21 +0200 Subject: [PATCH] Test system_settings --- .../openbb_core/app/service/system_service.py | 7 +++ .../core/tests/test_service_system_service.py | 54 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 openbb_sdk/sdk/core/tests/test_service_system_service.py diff --git a/openbb_sdk/sdk/core/openbb_core/app/service/system_service.py b/openbb_sdk/sdk/core/openbb_core/app/service/system_service.py index f9bc25cc7b9..d479b48fbae 100644 --- a/openbb_sdk/sdk/core/openbb_core/app/service/system_service.py +++ b/openbb_sdk/sdk/core/openbb_core/app/service/system_service.py @@ -6,6 +6,8 @@ from openbb_core.app.model.system_settings import SystemSettings class SystemService: + """System service.""" + SYSTEM_SETTINGS_PATH = SYSTEM_SETTINGS_PATH SYSTEM_SETTINGS_ALLOWED_FIELD_SET = {"run_in_isolation", "dbms_uri"} @@ -13,6 +15,7 @@ class SystemService: def read_default_system_settings( cls, path: Optional[Path] = None ) -> SystemSettings: + """Read default system settings.""" path = path or cls.SYSTEM_SETTINGS_PATH if path.exists(): @@ -31,6 +34,7 @@ class SystemService: system_settings: SystemSettings, path: Optional[Path] = None, ) -> None: + """Write default system settings.""" path = path or cls.SYSTEM_SETTINGS_PATH system_settings_json = system_settings.json( @@ -50,13 +54,16 @@ class SystemService: @property def system_settings(self) -> SystemSettings: + """Get system settings.""" return self._system_settings @system_settings.setter def system_settings(self, system_settings: SystemSettings) -> None: + """Set system settings.""" self._system_settings = system_settings def refresh_system_settings(self) -> SystemSettings: + """Refresh system settings.""" self._system_settings = self.read_default_system_settings() return self._system_settings diff --git a/openbb_sdk/sdk/core/tests/test_service_system_service.py b/openbb_sdk/sdk/core/tests/test_service_system_service.py new file mode 100644 index 00000000000..79e6c4a0ab2 --- /dev/null +++ b/openbb_sdk/sdk/core/tests/test_service_system_service.py @@ -0,0 +1,54 @@ +"""Test the ../openbb_core/app/service/system_service.py module.""" +# pylint: disable=redefined-outer-name + +import pytest +from openbb_core.app.service.system_service import SystemService + + +@pytest.fixture +def system_service(): + """Fixture for system service.""" + return SystemService() + + +def test_system_service_init(system_service): + """Test system service init.""" + assert system_service + + +def test_read_default_system_settings(system_service): + """Test read default system settings.""" + system_settings = system_service.read_default_system_settings() + + assert system_settings + + +def test_write_default_system_settings(system_service): + """Test write default system settings.""" + system_settings = system_service.read_default_system_settings() + system_service.write_default_system_settings(system_settings=system_settings) + + assert system_service + + +def test_system_settings(system_service): + """Test system settings.""" + system_settings = system_service.system_settings + + assert system_settings + + +def test_system_settings_setter(system_service): + """Test system settings setter.""" + system_settings = system_service.system_settings + + system_service.system_settings = system_settings + + assert system_service.system_settings == system_settings + + +def test_refresh_system_settings(system_service): + """Test refresh system settings.""" + system_settings = system_service.refresh_system_settings() + + assert system_settings