diff options
| author | Jenkins <jenkins@review.openstack.org> | 2017-03-08 02:51:48 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2017-03-08 02:51:48 +0000 |
| commit | dcb2de9db2ea9ff3b4673f9250b593c2aca3c241 (patch) | |
| tree | 6b5f6ab1f54fdbd345e71c50f45f745d7bb4e6f8 /openstackclient/tests/unit/compute/v2 | |
| parent | 054060cbef033b36d22caf47ae44f47e26da597f (diff) | |
| parent | dee22d8faa0c8a0da1d6ff62c0997c2cc770b759 (diff) | |
| download | python-openstackclient-dcb2de9db2ea9ff3b4673f9250b593c2aca3c241.tar.gz | |
Merge "Add "--private-key" option for "keypair create""
Diffstat (limited to 'openstackclient/tests/unit/compute/v2')
| -rw-r--r-- | openstackclient/tests/unit/compute/v2/test_keypair.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/openstackclient/tests/unit/compute/v2/test_keypair.py b/openstackclient/tests/unit/compute/v2/test_keypair.py index efc5463c..d6f5ecf4 100644 --- a/openstackclient/tests/unit/compute/v2/test_keypair.py +++ b/openstackclient/tests/unit/compute/v2/test_keypair.py @@ -15,6 +15,7 @@ import mock from mock import call +import uuid from osc_lib import exceptions from osc_lib import utils @@ -115,6 +116,36 @@ class TestKeypairCreate(TestKeypair): self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) + def test_keypair_create_private_key(self): + tmp_pk_file = '/tmp/kp-file-' + uuid.uuid4().hex + arglist = [ + '--private-key', tmp_pk_file, + self.keypair.name, + ] + verifylist = [ + ('private_key', tmp_pk_file), + ('name', self.keypair.name) + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + with mock.patch('io.open') as mock_open: + mock_open.return_value = mock.MagicMock() + m_file = mock_open.return_value.__enter__.return_value + + columns, data = self.cmd.take_action(parsed_args) + + self.keypairs_mock.create.assert_called_with( + self.keypair.name, + public_key=None + ) + + mock_open.assert_called_once_with(tmp_pk_file, 'w+') + m_file.write.assert_called_once_with(self.keypair.private_key) + + self.assertEqual(self.columns, columns) + self.assertEqual(self.data, data) + class TestKeypairDelete(TestKeypair): |
