Skip to content

Commit

Permalink
Add tests for clock CLI
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Fastiuk <yfastiuk@nvidia.com>
  • Loading branch information
fastiuk committed Apr 13, 2023
1 parent 56492ff commit 438db17
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
63 changes: 63 additions & 0 deletions tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1935,3 +1935,66 @@ def test_del_ntp_server_invalid_ip_yang_validation(self):
@classmethod
def teardown_class(cls):
print("TEARDOWN")


class TestConfigClock(object):
timezone_test_val = ['Europe/Kyiv', 'Asia/Israel', 'Etc/UTC']

@classmethod
def setup_class(cls):
print('SETUP')
import config.main
importlib.reload(config.main)

@patch('config.main.get_tzs', mock.Mock(return_value=timezone_test_val))
def test_timezone_good(self):
runner = CliRunner()
obj = {'db': Db().cfgdb}

result = runner.invoke(
config.config.commands['clock'].commands['timezone'],
['Etc/UTC'], obj=obj)

assert result.exit_code == 0

@patch('config.main.get_tzs', mock.Mock(return_value=timezone_test_val))
def test_timezone_bad(self):
runner = CliRunner()
obj = {'db': Db().cfgdb}

result = runner.invoke(
config.config.commands['clock'].commands['timezone'],
['Atlantis'], obj=obj)

assert result.exit_code != 0
assert 'Timezone Atlantis does not conform format' in result.output

@patch('utilities_common.cli.run_command',
mock.MagicMock(side_effect=mock_run_command_side_effect))
def test_date_good(self):
runner = CliRunner()
obj = {'db': Db().cfgdb}

result = runner.invoke(
config.config.commands['clock'].commands['date'],
['2020-10-10', '10:20:30'], obj=obj)

assert result.exit_code == 0

@patch('utilities_common.cli.run_command',
mock.MagicMock(side_effect=mock_run_command_side_effect))
def test_date_bad(self):
runner = CliRunner()
obj = {'db': Db().cfgdb}

result = runner.invoke(
config.config.commands['clock'].commands['date'],
['20-10-10', '60:70:80'], obj=obj)

assert result.exit_code != 0
assert 'Date 20-10-10 does not conform format' in result.output
assert 'Time 60:70:80 does not conform format' in result.output

@classmethod
def teardown_class(cls):
print('TEARDOWN')
34 changes: 34 additions & 0 deletions tests/show_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,37 @@ def test_show_logging_tmpfs_syslog_1(run_command, cli_arguments, expected):
runner = CliRunner()
result = runner.invoke(show.cli.commands["logging"], cli_arguments)
run_command.assert_called_with(EXPECTED_BASE_COMMAND + expected, display_cmd=False)


class TestShowClock(object):
@classmethod
def setup_class(cls):
print('SETUP')
os.environ['UTILITIES_UNIT_TESTING'] = '1'

@patch('show.main.run_command')
def test_clock(self, mock_rc):
runner = CliRunner()

result = runner.invoke(show.cli.commands['clock'])
print(result.exit_code)
print(result.output)

assert result.exit_code == 0
mock_rc.assert_called_once_with('date')

@patch('show.main.run_command')
def test_timezone(self, mock_rc):
runner = CliRunner()

result = runner.invoke(
show.cli.commands['clock'].commands['timezones'])
print(result.exit_code)
print(result.output)

assert result.exit_code == 0
mock_rc.assert_called_once_with('timedatectl list-timezones')

@classmethod
def teardown_class(cls):
print('TEARDOWN')

0 comments on commit 438db17

Please sign in to comment.