Repository navigation
feat: Added two new methods to WindowsService in mfd_host/feature/service/windows.py #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
tests/unit/test_mfd_host/test_feature/test_service/test_windows.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # Copyright (C) 2026 Intel Corporation | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| import pytest | ||
| from mfd_common_libs import log_levels | ||
| from mfd_connect import RPyCConnection | ||
| from mfd_connect.base import ConnectionCompletedProcess | ||
| from mfd_typing import OSName | ||
|
|
||
| from mfd_host import Host | ||
| from mfd_host.feature.service.windows import WindowsService | ||
|
|
||
|
|
||
| class TestWindowsService: | ||
| @pytest.fixture | ||
| def host(self, mocker): | ||
| _connection = mocker.create_autospec(RPyCConnection) | ||
| _connection.get_os_name.return_value = OSName.WINDOWS | ||
| yield Host(connection=_connection) | ||
| mocker.stopall() | ||
|
|
||
| @pytest.fixture | ||
| def windows_service(self, host): | ||
| yield host.service | ||
|
|
||
| def test_restart_service(self, windows_service: WindowsService): | ||
| service_name = "TestService" | ||
| windows_service.restart_service(service_name) | ||
| windows_service._connection.execute_powershell.assert_called_once_with( | ||
| 'Restart-Service -Name "TestService" -Force', | ||
| expected_return_codes={0}, | ||
| ) | ||
|
|
||
| def test_restart_service_logs(self, windows_service: WindowsService, caplog): | ||
| caplog.set_level(log_levels.MODULE_DEBUG) | ||
| service_name = "TestService" | ||
| windows_service.restart_service(service_name) | ||
| assert f"Restarting service '{service_name}'" in caplog.text | ||
|
|
||
| def test_restart_service_raises_on_error(self, windows_service: WindowsService): | ||
| service_name = "TestService" | ||
| windows_service._connection.execute_powershell.side_effect = RuntimeError("Command failed") | ||
| with pytest.raises(RuntimeError): | ||
| windows_service.restart_service(service_name) | ||
|
|
||
| def test_get_service_status(self, windows_service: WindowsService): | ||
| service_name = "TestService" | ||
| expected_status = "Running" | ||
| windows_service._connection.execute_powershell.return_value = ConnectionCompletedProcess( | ||
| return_code=0, args="", stdout=f" {expected_status} ", stderr="" | ||
| ) | ||
| result = windows_service.get_service_status(service_name) | ||
| windows_service._connection.execute_powershell.assert_called_once_with( | ||
| '(Get-Service -Name "TestService").Status', | ||
| expected_return_codes={0}, | ||
| ) | ||
| assert result == expected_status | ||
|
|
||
| def test_get_service_status_stopped(self, windows_service: WindowsService): | ||
| service_name = "TestService" | ||
| windows_service._connection.execute_powershell.return_value = ConnectionCompletedProcess( | ||
| return_code=0, args="", stdout="Stopped\n", stderr="" | ||
| ) | ||
| result = windows_service.get_service_status(service_name) | ||
| assert result == "Stopped" | ||
|
|
||
| def test_get_service_status_logs(self, windows_service: WindowsService, caplog): | ||
| caplog.set_level(log_levels.MODULE_DEBUG) | ||
| service_name = "TestService" | ||
| windows_service._connection.execute_powershell.return_value = ConnectionCompletedProcess( | ||
| return_code=0, args="", stdout="Running\n", stderr="" | ||
| ) | ||
| windows_service.get_service_status(service_name) | ||
| assert f"Getting service '{service_name}'" in caplog.text | ||
|
|
||
| def test_get_service_status_raises_on_error(self, windows_service: WindowsService): | ||
| service_name = "TestService" | ||
| windows_service._connection.execute_powershell.side_effect = RuntimeError("Command failed") | ||
| with pytest.raises(RuntimeError): | ||
| windows_service.get_service_status(service_name) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.