Skip to content

Commit

Permalink
Added Banner CLI UTs
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Fastiuk <yfastiuk@nvidia.com>
  • Loading branch information
fastiuk committed May 14, 2024
1 parent 1d00038 commit 9bdd4ca
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
1 change: 0 additions & 1 deletion config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7687,7 +7687,6 @@ def state(state):
{'state': state})



@banner.command()
@click.argument('message', metavar='<message>', required=True)
def login(message):
Expand Down
62 changes: 61 additions & 1 deletion tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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')
6 changes: 6 additions & 0 deletions tests/show_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down

0 comments on commit 9bdd4ca

Please sign in to comment.