From 2859be5d574717e85fbb75b1fb0d386703444ac2 Mon Sep 17 00:00:00 2001 From: twangboy Date: Thu, 18 Jan 2018 19:07:50 +0000 Subject: [PATCH 1/2] Fix mock, fix paths --- tests/unit/test_crypt.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/unit/test_crypt.py b/tests/unit/test_crypt.py index 9e37d6f52b..70d3f58e62 100644 --- a/tests/unit/test_crypt.py +++ b/tests/unit/test_crypt.py @@ -10,6 +10,7 @@ from tests.support.mock import patch, call, mock_open, NO_MOCK, NO_MOCK_REASON, # salt libs import salt.utils.files +import salt.utils.platform from salt import crypt # third-party libs @@ -104,19 +105,20 @@ class CryptTestCase(TestCase): @patch('os.umask', MagicMock()) @patch('os.chmod', MagicMock()) - @patch('os.chown', MagicMock()) + @patch('os.chown', MagicMock(), create=True) @patch('os.access', MagicMock(return_value=True)) def test_gen_keys_with_passphrase(self): + key_path = os.path.join(os.sep, 'keydir') with patch('salt.utils.files.fopen', mock_open()): - open_priv_wb = call('/keydir/keyname.pem', 'wb+') - open_pub_wb = call('/keydir/keyname.pub', 'wb+') + open_priv_wb = call(os.path.join(key_path, 'keyname.pem'), 'wb+') + open_pub_wb = call(os.path.join(key_path, 'keyname.pub'), 'wb+') with patch('os.path.isfile', return_value=True): - self.assertEqual(crypt.gen_keys('/keydir', 'keyname', 2048, passphrase='password'), '/keydir/keyname.pem') + self.assertEqual(crypt.gen_keys(key_path, 'keyname', 2048, passphrase='password'), os.path.join(key_path, 'keyname.pem')) self.assertNotIn(open_priv_wb, salt.utils.files.fopen.mock_calls) self.assertNotIn(open_pub_wb, salt.utils.files.fopen.mock_calls) with patch('os.path.isfile', return_value=False): with patch('salt.utils.files.fopen', mock_open()): - crypt.gen_keys('/keydir', 'keyname', 2048) + crypt.gen_keys(key_path, 'keyname', 2048) salt.utils.files.fopen.assert_has_calls([open_priv_wb, open_pub_wb], any_order=True) def test_sign_message(self): From 2dea2f16a9242a8e82f08fd4bf9971163ef31de5 Mon Sep 17 00:00:00 2001 From: twangboy Date: Thu, 18 Jan 2018 19:13:33 +0000 Subject: [PATCH 2/2] Remove salt.utils.platform import --- tests/unit/test_crypt.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit/test_crypt.py b/tests/unit/test_crypt.py index 70d3f58e62..ffa1f33eb8 100644 --- a/tests/unit/test_crypt.py +++ b/tests/unit/test_crypt.py @@ -10,7 +10,6 @@ from tests.support.mock import patch, call, mock_open, NO_MOCK, NO_MOCK_REASON, # salt libs import salt.utils.files -import salt.utils.platform from salt import crypt # third-party libs