Add unit test for keypair's api

Add unit test for keypair's api in test_shell.py, just for v1.1,
not for v3, because of v3 inherits from v1.1.

Change-Id: Ibbad199449431b328091ef4b5e4b955ffcddc303
Closes-Bug: #1309986
This commit is contained in:
Zhengguang 2014-04-19 10:44:54 -04:00
parent 25987144ac
commit 02ee4fc79e

View File

@ -23,6 +23,7 @@ import os
import fixtures
import mock
import six
from six.moves import builtins
import novaclient.client
from novaclient import exceptions
@ -1939,6 +1940,33 @@ class ShellTest(utils.TestCase):
mock_system.assert_called_with("ssh -6 -p22 "
"root@2607:f0d0:1002::4 -1")
def test_keypair_add(self):
self.run_command('keypair-add test')
self.assert_called('POST', '/os-keypairs',
{'keypair':
{'name': 'test'}})
@mock.patch.object(builtins, 'open',
mock.mock_open(read_data='FAKE_PUBLIC_KEY'))
def test_keypair_import(self):
self.run_command('keypair-add --pub-key test.pub test')
self.assert_called('POST', '/os-keypairs',
{'keypair':
{'public_key': 'FAKE_PUBLIC_KEY',
'name': 'test'}})
def test_keypair_list(self):
self.run_command('keypair-list')
self.assert_called('GET', '/os-keypairs')
def test_keypair_show(self):
self.run_command('keypair-show test')
self.assert_called('GET', '/os-keypairs/test')
def test_keypair_delete(self):
self.run_command('keypair-delete test')
self.assert_called('DELETE', '/os-keypairs/test')
class GetSecgroupTest(utils.TestCase):
def test_with_integer(self):