Skip to content

Commit 4573619

Browse files
committed
update testcases
Signed-off-by: Arham-Nasir <arqamnasir719@gmail.com>
1 parent 91e3fa5 commit 4573619

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

tests/hostcfgd/hostcfgd_test.py

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,6 @@ def test_banner_message(self, mock_run_cmd):
370370

371371
mock_run_cmd.assert_has_calls([call(['systemctl', 'restart', 'banner-config'], True, True)])
372372

373-
374-
375373
class TestMemoryStatisticsCfg(TestCase):
376374
"""
377375
Test hostcfd daemon - MemoryStatisticsCfg
@@ -440,29 +438,28 @@ def test_memory_statistics_update_invalid_configuration(self):
440438
]
441439
mocked_syslog.syslog.assert_has_calls(expected_logs)
442440

443-
def test_apply_memory_statistics_configuration(self):
444-
with mock.patch('hostcfgd.subprocess') as mocked_subprocess:
445-
popen_mock = mock.Mock()
446-
attrs = {'communicate.return_value': ('output', 'error')}
447-
popen_mock.configure_mock(**attrs)
448-
mocked_subprocess.Popen.return_value = popen_mock
441+
def test_apply_memory_statistics_configuration(self):
442+
with mock.patch('hostcfgd.subprocess') as mocked_subprocess:
443+
popen_mock = mock.Mock()
444+
attrs = {'communicate.return_value': ('output', 'error')}
445+
popen_mock.configure_mock(**attrs)
446+
mocked_subprocess.Popen.return_value = popen_mock
447+
448+
self.memorystatisticscfg.cache = {
449+
"enabled": "true",
450+
"sampling_interval": "10",
451+
"retention_period": "30"
452+
}
449453

450-
self.memorystatisticscfg.cache = {
451-
"enabled": "true",
452-
"sampling_interval": "10",
453-
"retention_period": "30"
454-
}
454+
# Apply each setting individually and check for the call
455+
self.memorystatisticscfg.apply_setting("enabled", "true")
456+
mocked_subprocess.check_call.assert_called_with(['systemctl', 'restart', 'memory-statistics-service'])
455457

456-
self.memorystatisticscfg.apply_setting("enabled", "true")
457-
self.memorystatisticscfg.apply_setting("sampling_interval", "10")
458-
self.memorystatisticscfg.apply_setting("retention_period", "30")
458+
self.memorystatisticscfg.apply_setting("sampling_interval", "10")
459+
mocked_subprocess.check_call.assert_called_with(['systemctl', 'restart', 'memory-statistics-service'])
459460

460-
expected_calls = [
461-
call(['systemctl', 'restart', 'memory-statistics-service']),
462-
call(['systemctl', 'restart', 'memory-statistics-service']),
463-
call(['systemctl', 'restart', 'memory-statistics-service'])
464-
]
465-
mocked_subprocess.check_call.assert_has_calls(expected_calls)
461+
self.memorystatisticscfg.apply_setting("retention_period", "30")
462+
mocked_subprocess.check_call.assert_called_with(['systemctl', 'restart', 'memory-statistics-service'])
466463

467464
def test_get_memory_statistics_pid(self):
468465
with mock.patch('hostcfgd.psutil') as mocked_psutil:

0 commit comments

Comments
 (0)