diff --git a/tests/portchannel_test.py b/tests/portchannel_test.py index 922b304518..352681a3cc 100644 --- a/tests/portchannel_test.py +++ b/tests/portchannel_test.py @@ -1,20 +1,38 @@ import os import pytest import traceback +import mock from click.testing import CliRunner +from jsonpatch import JsonPatchConflict import config.main as config import show.main as show from utilities_common.db import Db +from mock import patch class TestPortChannel(object): @classmethod def setup_class(cls): os.environ['UTILITIES_UNIT_TESTING'] = "1" print("SETUP") + + @patch("config.main.is_portchannel_present_in_db", mock.Mock(return_value=False)) + @patch("config.validated_config_db_connector.validated_set_entry", mock.Mock(side_effect=ValueError)) + @mock.patch.dict(os.environ, {"ADHOC_VALIDATION": "False"}) + def test_add_portchannel_with_invalid_name_yang_validation(self): + runner = CliRunner() + db = Db() + obj = {'db':db.cfgdb} + + result = runner.invoke(config.config.commands["portchannel"].commands["add"], ["PortChan005"], obj=obj) + print(result.exit_code) + print(result.output) + assert result.exit_code != 0 + assert "Error: PortChan005 is invalid!, name should have prefix 'PortChannel' and suffix '<0-9999>'" in result.output + - def test_add_portchannel_with_invalid_name(self): + def test_add_portchannel_with_invalid_name_adhoc_validation(self): runner = CliRunner() db = Db() obj = {'db':db.cfgdb}