Skip to content

Commit 470550f

Browse files
committed
updated scripts to mock chmod
1 parent b3babbd commit 470550f

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/sonic-py-common/tests/test_security_cipher.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@
3333
class TestSecurityCipher(object):
3434
def test_passkey_encryption(self):
3535
with mock.patch("sonic_py_common.security_cipher.ConfigDBConnector", new=ConfigDBConnector), \
36-
mock.patch("{}.open".format(BUILTINS),mock.mock_open()) as mock_file:
36+
mock.patch("os.chmod") as mock_chmod, \
37+
mock.patch("{}.open".format(BUILTINS),mock.mock_open()) as mock_file:
3738
temp = security_cipher()
3839

3940
# Use patch to replace the built-in 'open' function with a mock
40-
with mock.patch("{}.open".format(BUILTINS), mock.mock_open()) as mock_file:
41+
with mock.patch("{}.open".format(BUILTINS), mock.mock_open()) as mock_file, \
42+
mock.patch("os.chmod") as mock_chmod:
4143
mock_fd = mock.MagicMock()
4244
mock_fd.readlines = mock.MagicMock(return_value=DEFAULT_FILE)
4345
mock_file.return_value.__enter__.return_value = mock_fd
@@ -46,19 +48,22 @@ def test_passkey_encryption(self):
4648

4749
def test_passkey_decryption(self):
4850
with mock.patch("sonic_py_common.security_cipher.ConfigDBConnector", new=ConfigDBConnector), \
49-
mock.patch("{}.open".format(BUILTINS), mock.mock_open()) as mock_file:
51+
mock.patch("os.chmod") as mock_chmod, \
52+
mock.patch("{}.open".format(BUILTINS), mock.mock_open()) as mock_file:
5053
temp = security_cipher()
5154

5255
# Use patch to replace the built-in 'open' function with a mock
53-
with mock.patch("{}.open".format(BUILTINS), mock.mock_open()) as mock_file:
56+
with mock.patch("{}.open".format(BUILTINS), mock.mock_open()) as mock_file, \
57+
mock.patch("os.chmod") as mock_chmod:
5458
mock_fd = mock.MagicMock()
5559
mock_fd.readlines = mock.MagicMock(return_value=DEFAULT_FILE)
5660
mock_file.return_value.__enter__.return_value = mock_fd
5761
encrypt, err = temp.encrypt_passkey("RADIUS", "passkey2", "TEST2")
5862

5963
# Use patch to replace the built-in 'open' function with a mock
6064
#with mock.patch("{}.open".format(BUILTINS), mock.mock_open(read_data=EXPECTED_PASSWD)) as mock_file:
61-
with mock.patch("{}.open".format(BUILTINS), mock.mock_open()) as mock_file:
65+
with mock.patch("{}.open".format(BUILTINS), mock.mock_open()) as mock_file, \
66+
mock.patch("os.chmod") as mock_chmod:
6267
mock_fd = mock.MagicMock()
6368
mock_fd.readlines = mock.MagicMock(return_value=UPDATED_FILE)
6469
mock_file.return_value.__enter__.return_value = mock_fd

0 commit comments

Comments
 (0)