Merge "Remove mox from tests/unit/objects/test_keypair.py"
This commit is contained in:
commit
b7504aff24
@ -12,9 +12,9 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
from oslo_utils import timeutils
|
||||
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova.objects import keypair
|
||||
from nova.tests.unit.objects import test_objects
|
||||
@ -35,68 +35,76 @@ fake_keypair = {
|
||||
|
||||
|
||||
class _TestKeyPairObject(object):
|
||||
def test_get_by_name(self):
|
||||
self.mox.StubOutWithMock(db, 'key_pair_get')
|
||||
db.key_pair_get(self.context, 'fake-user', 'foo-keypair').AndReturn(
|
||||
fake_keypair)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@mock.patch('nova.db.key_pair_get')
|
||||
def test_get_by_name(self, mock_kp_get):
|
||||
mock_kp_get.return_value = fake_keypair
|
||||
|
||||
keypair_obj = keypair.KeyPair.get_by_name(self.context, 'fake-user',
|
||||
'foo-keypair')
|
||||
self.compare_obj(keypair_obj, fake_keypair)
|
||||
|
||||
def test_create(self):
|
||||
self.mox.StubOutWithMock(db, 'key_pair_create')
|
||||
db.key_pair_create(self.context,
|
||||
{'name': 'foo-keypair',
|
||||
'public_key': 'keydata'}).AndReturn(fake_keypair)
|
||||
self.mox.ReplayAll()
|
||||
mock_kp_get.assert_called_once_with(self.context, 'fake-user',
|
||||
'foo-keypair')
|
||||
|
||||
@mock.patch('nova.db.key_pair_create')
|
||||
def test_create(self, mock_kp_create):
|
||||
mock_kp_create.return_value = fake_keypair
|
||||
|
||||
keypair_obj = keypair.KeyPair(context=self.context)
|
||||
keypair_obj.name = 'foo-keypair'
|
||||
keypair_obj.public_key = 'keydata'
|
||||
keypair_obj.create()
|
||||
self.compare_obj(keypair_obj, fake_keypair)
|
||||
|
||||
def test_recreate_fails(self):
|
||||
self.mox.StubOutWithMock(db, 'key_pair_create')
|
||||
db.key_pair_create(self.context,
|
||||
{'name': 'foo-keypair',
|
||||
'public_key': 'keydata'}).AndReturn(fake_keypair)
|
||||
self.mox.ReplayAll()
|
||||
mock_kp_create.assert_called_once_with(self.context,
|
||||
{'name': 'foo-keypair', 'public_key': 'keydata'})
|
||||
|
||||
@mock.patch('nova.db.key_pair_create')
|
||||
def test_recreate_fails(self, mock_kp_create):
|
||||
mock_kp_create.return_value = fake_keypair
|
||||
|
||||
keypair_obj = keypair.KeyPair(context=self.context)
|
||||
keypair_obj.name = 'foo-keypair'
|
||||
keypair_obj.public_key = 'keydata'
|
||||
keypair_obj.create()
|
||||
self.assertRaises(exception.ObjectActionError, keypair_obj.create)
|
||||
|
||||
def test_destroy(self):
|
||||
self.mox.StubOutWithMock(db, 'key_pair_destroy')
|
||||
db.key_pair_destroy(self.context, 'fake-user', 'foo-keypair')
|
||||
self.mox.ReplayAll()
|
||||
mock_kp_create.assert_called_once_with(self.context,
|
||||
{'name': 'foo-keypair', 'public_key': 'keydata'})
|
||||
|
||||
@mock.patch('nova.db.key_pair_destroy')
|
||||
def test_destroy(self, mock_kp_destroy):
|
||||
keypair_obj = keypair.KeyPair(context=self.context)
|
||||
keypair_obj.id = 123
|
||||
keypair_obj.user_id = 'fake-user'
|
||||
keypair_obj.name = 'foo-keypair'
|
||||
keypair_obj.destroy()
|
||||
|
||||
def test_destroy_by_name(self):
|
||||
self.mox.StubOutWithMock(db, 'key_pair_destroy')
|
||||
db.key_pair_destroy(self.context, 'fake-user', 'foo-keypair')
|
||||
self.mox.ReplayAll()
|
||||
mock_kp_destroy.assert_called_once_with(
|
||||
self.context, 'fake-user', 'foo-keypair')
|
||||
|
||||
@mock.patch('nova.db.key_pair_destroy')
|
||||
def test_destroy_by_name(self, mock_kp_destroy):
|
||||
keypair.KeyPair.destroy_by_name(self.context, 'fake-user',
|
||||
'foo-keypair')
|
||||
|
||||
def test_get_by_user(self):
|
||||
self.mox.StubOutWithMock(db, 'key_pair_get_all_by_user')
|
||||
self.mox.StubOutWithMock(db, 'key_pair_count_by_user')
|
||||
db.key_pair_get_all_by_user(self.context, 'fake-user').AndReturn(
|
||||
[fake_keypair])
|
||||
db.key_pair_count_by_user(self.context, 'fake-user').AndReturn(1)
|
||||
self.mox.ReplayAll()
|
||||
mock_kp_destroy.assert_called_once_with(
|
||||
self.context, 'fake-user', 'foo-keypair')
|
||||
|
||||
@mock.patch('nova.db.key_pair_get_all_by_user')
|
||||
@mock.patch('nova.db.key_pair_count_by_user')
|
||||
def test_get_by_user(self, mock_kp_count, mock_kp_get):
|
||||
mock_kp_get.return_value = [fake_keypair]
|
||||
mock_kp_count.return_value = 1
|
||||
|
||||
keypairs = keypair.KeyPairList.get_by_user(self.context, 'fake-user')
|
||||
self.assertEqual(1, len(keypairs))
|
||||
self.compare_obj(keypairs[0], fake_keypair)
|
||||
self.assertEqual(1, keypair.KeyPairList.get_count_by_user(self.context,
|
||||
'fake-user'))
|
||||
mock_kp_get.assert_called_once_with(self.context, 'fake-user')
|
||||
mock_kp_count.assert_called_once_with(self.context, 'fake-user')
|
||||
|
||||
def test_obj_make_compatible(self):
|
||||
keypair_obj = keypair.KeyPair(context=self.context)
|
||||
|
Loading…
Reference in New Issue
Block a user