|
| 1 | +import json |
| 2 | +import jsonpatch |
1 | 3 | import os
|
2 | 4 | import traceback
|
3 | 5 | from unittest import mock
|
|
8 | 10 | import show.main as show
|
9 | 11 | from utilities_common.db import Db
|
10 | 12 |
|
| 13 | +test_path = os.path.dirname(os.path.abspath(__file__)) |
| 14 | +ip_config_input_path = os.path.join(test_path, "ip_config_input") |
| 15 | + |
11 | 16 | ERROR_MSG = "Error: IP address is not valid"
|
12 | 17 |
|
13 | 18 | class TestConfigIP(object):
|
@@ -157,6 +162,22 @@ def test_add_del_interface_shortened_ipv6_with_leading_zeros(self):
|
157 | 162 | assert result.exit_code != 0
|
158 | 163 | assert ('Ethernet68', '3000::1/64') not in db.cfgdb.get_table('INTERFACE')
|
159 | 164 |
|
| 165 | + def test_remove_interface_case_sensitive_mock_ipv6_w_apply_patch(self): |
| 166 | + runner = CliRunner() |
| 167 | + any_patch_as_json = [{"op": "remove", "path": "/INTERFACE/Ethernet12|FC00::1~1126"}] |
| 168 | + any_patch = jsonpatch.JsonPatch(any_patch_as_json) |
| 169 | + any_patch_as_text = json.dumps(any_patch_as_json) |
| 170 | + ipv6_patch_file = os.path.join(ip_config_input_path, 'patch_ipv6.test') |
| 171 | + |
| 172 | + # config apply-patch patch |
| 173 | + mock_generic_updater = mock.Mock() |
| 174 | + with mock.patch('config.main.GenericUpdater', return_value=mock_generic_updater): |
| 175 | + with mock.patch('builtins.open', mock.mock_open(read_data=any_patch_as_text)): |
| 176 | + result = runner.invoke(config.config.commands["apply-patch"], [ipv6_patch_file], catch_exceptions=False) |
| 177 | + print(result.exit_code, result.output) |
| 178 | + assert "converted ipv6 address to lowercase fc00::1~1126 with prefix /INTERFACE/Ethernet12| in value: /INTERFACE/Ethernet12|FC00::1~1126" in result.output |
| 179 | + |
| 180 | + |
160 | 181 | @classmethod
|
161 | 182 | def teardown_class(cls):
|
162 | 183 | os.environ['UTILITIES_UNIT_TESTING'] = "0"
|
|
0 commit comments