Skip to content

Commit 64bca6e

Browse files
committed
Add test for hostname setting
Signed-off-by: Yevhen Fastiuk <[email protected]>
1 parent 26866a2 commit 64bca6e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/config_test.py

+34
Original file line numberDiff line numberDiff line change
@@ -1585,3 +1585,37 @@ def test_config_rate(self, get_cmd_module, setup_single_broadcom_asic):
15851585
def teardown_class(cls):
15861586
print("TEARDOWN")
15871587
os.environ['UTILITIES_UNIT_TESTING'] = "0"
1588+
1589+
1590+
class TestConfigHostname(object):
1591+
@classmethod
1592+
def setup_class(cls):
1593+
print("SETUP")
1594+
import config.main
1595+
importlib.reload(config.main)
1596+
1597+
@mock.patch('config.main.ConfigDBConnector')
1598+
def test_hostname_add(self, db_conn_patch, get_cmd_module):
1599+
db_conn_patch().mod_entry = mock.Mock()
1600+
(config, show) = get_cmd_module
1601+
1602+
runner = CliRunner()
1603+
result = runner.invoke(config.config.commands["hostname"],
1604+
["new_hostname"])
1605+
1606+
# Verify success
1607+
assert result.exit_code == 0
1608+
1609+
# Check was called
1610+
args_list = db_conn_patch().mod_entry.call_args_list
1611+
assert len(args_list) > 0
1612+
1613+
args, _ = args_list[0]
1614+
assert len(args) > 0
1615+
1616+
# Check new hostname was part of args
1617+
assert {'hostname': 'new_hostname'} in args
1618+
1619+
@classmethod
1620+
def teardown_class(cls):
1621+
print("TEARDOWN")

0 commit comments

Comments
 (0)