Skip to content

Commit

Permalink
add unit test for apply-patch ipv6 regex
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarashinvd committed Aug 10, 2022
1 parent 641ef37 commit 8f7e4ff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/ip_config_input/patch_ipv6.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"path": "/INTERFACE/Ethernet12|FC00::1~1126",
"op": "remove"
}
]
21 changes: 21 additions & 0 deletions tests/ip_config_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json
import jsonpatch
import os
import traceback
from unittest import mock
Expand All @@ -8,6 +10,9 @@
import show.main as show
from utilities_common.db import Db

test_path = os.path.dirname(os.path.abspath(__file__))
ip_config_input_path = os.path.join(test_path, "ip_config_input")

ERROR_MSG = "Error: IP address is not valid"

class TestConfigIP(object):
Expand Down Expand Up @@ -157,6 +162,22 @@ def test_add_del_interface_shortened_ipv6_with_leading_zeros(self):
assert result.exit_code != 0
assert ('Ethernet68', '3000::1/64') not in db.cfgdb.get_table('INTERFACE')

def test_remove_interface_case_sensitive_mock_ipv6_w_apply_patch(self):
runner = CliRunner()
any_patch_as_json = [{"op": "remove", "path": "/INTERFACE/Ethernet12|FC00::1~1126"}]
any_patch = jsonpatch.JsonPatch(any_patch_as_json)
any_patch_as_text = json.dumps(any_patch_as_json)
ipv6_patch_file = os.path.join(ip_config_input_path, 'patch_ipv6.test')

# config apply-patch patch
mock_generic_updater = mock.Mock()
with mock.patch('config.main.GenericUpdater', return_value=mock_generic_updater):
with mock.patch('builtins.open', mock.mock_open(read_data=any_patch_as_text)):
result = runner.invoke(config.config.commands["apply-patch"], [ipv6_patch_file], catch_exceptions=False)
print(result.exit_code, result.output)
assert "converted ipv6 address to lowercase fc00::1~1126 with prefix /INTERFACE/Ethernet12| in value: /INTERFACE/Ethernet12|FC00::1~1126" in result.output


@classmethod
def teardown_class(cls):
os.environ['UTILITIES_UNIT_TESTING'] = "0"
Expand Down

0 comments on commit 8f7e4ff

Please sign in to comment.