From 262226dc295b65cf21891e4831e33782039f3be6 Mon Sep 17 00:00:00 2001 From: Yevhen Fastiuk Date: Sun, 28 Apr 2024 00:26:16 +0300 Subject: [PATCH] Added Banner CLI UTs Signed-off-by: Yevhen Fastiuk --- tests/config_test.py | 62 +++++++++++++++++++++++++++++++++++++++++++- tests/show_test.py | 6 +++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/tests/config_test.py b/tests/config_test.py index 1054a52a33..d00b361838 100644 --- a/tests/config_test.py +++ b/tests/config_test.py @@ -2741,4 +2741,64 @@ def teardown_class(cls): from .mock_tables import dbconnector from .mock_tables import mock_single_asic importlib.reload(mock_single_asic) - dbconnector.load_database_config() \ No newline at end of file + dbconnector.load_database_config() + + +class TestConfigBanner(object): + @classmethod + def setup_class(cls): + print('SETUP') + import config.main + importlib.reload(config.main) + + @patch('utilities_common.cli.run_command', + mock.MagicMock(side_effect=mock_run_command_side_effect)) + def test_banner_state(self): + runner = CliRunner() + obj = {'db': Db().cfgdb} + + result = runner.invoke( + config.config.commands['banner'].commands['state'], + ['enabled'], obj=obj) + + assert result.exit_code == 0 + + @patch('utilities_common.cli.run_command', + mock.MagicMock(side_effect=mock_run_command_side_effect)) + def test_banner_login(self): + runner = CliRunner() + obj = {'db': Db().cfgdb} + + result = runner.invoke( + config.config.commands['banner'].commands['login'], + ['Login message'], obj=obj) + + assert result.exit_code == 0 + + @patch('utilities_common.cli.run_command', + mock.MagicMock(side_effect=mock_run_command_side_effect)) + def test_banner_logout(self): + runner = CliRunner() + obj = {'db': Db().cfgdb} + + result = runner.invoke( + config.config.commands['banner'].commands['logout'], + ['Logout message'], obj=obj) + + assert result.exit_code == 0 + + @patch('utilities_common.cli.run_command', + mock.MagicMock(side_effect=mock_run_command_side_effect)) + def test_banner_motd(self): + runner = CliRunner() + obj = {'db': Db().cfgdb} + + result = runner.invoke( + config.config.commands['banner'].commands['motd'], + ['Motd message'], obj=obj) + + assert result.exit_code == 0 + + @classmethod + def teardown_class(cls): + print('TEARDOWN') diff --git a/tests/show_test.py b/tests/show_test.py index 4cd29ac45e..ad88eeaaa2 100644 --- a/tests/show_test.py +++ b/tests/show_test.py @@ -1040,6 +1040,12 @@ def test_show_ztp(self, mock_run_command): assert result.exit_code == 0 mock_run_command.assert_called_with(['ztp', 'status', '--verbose'], display_cmd=True) + @patch('show.main.run_command') + def test_show_banner(self, mock_run_command): + runner = CliRunner() + result = runner.invoke(show.cli.commands['banner']) + assert result.exit_code == 0 + def teardown(self): print('TEAR DOWN')