
This involved a huge amount of cleanup to existing code in order to make sure that existing failures were properly fixed or silenced when intentional. Additionally, this introduces a set of pre-built exception instances for test purposes which are marked with the "silence_logging" attribute to denote expected failures which should not be logged in test output. Change-Id: I6b420382dcdc5792c7be4d727853f438154c641e
127 lines
5.2 KiB
Python
127 lines
5.2 KiB
Python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
|
|
# Copyright 2012 United States Government as represented by the
|
|
# Administrator of the National Aeronautics and Space Administration.
|
|
# All Rights Reserved.
|
|
#
|
|
# Copyright 2012 Nebula, Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
from django import http
|
|
from django.core.urlresolvers import reverse
|
|
from mox import IsA
|
|
|
|
from horizon import api
|
|
from horizon import test
|
|
|
|
|
|
INDEX_VIEW_URL = reverse('horizon:nova:access_and_security:index')
|
|
|
|
|
|
class KeyPairViewTests(test.TestCase):
|
|
def test_delete_keypair(self):
|
|
keypair = self.keypairs.first()
|
|
|
|
self.mox.StubOutWithMock(api.nova, 'keypair_list')
|
|
self.mox.StubOutWithMock(api.nova, 'keypair_delete')
|
|
self.mox.StubOutWithMock(api, 'security_group_list')
|
|
self.mox.StubOutWithMock(api, 'tenant_floating_ip_list')
|
|
self.mox.StubOutWithMock(api.nova, 'server_list')
|
|
|
|
api.nova.server_list(IsA(http.HttpRequest),
|
|
all_tenants=True).AndReturn(self.servers.list())
|
|
api.security_group_list(IsA(http.HttpRequest)) \
|
|
.AndReturn(self.security_groups.list())
|
|
api.tenant_floating_ip_list(IsA(http.HttpRequest)) \
|
|
.AndReturn(self.floating_ips.list())
|
|
api.nova.keypair_list(IsA(http.HttpRequest)) \
|
|
.AndReturn(self.keypairs.list())
|
|
api.nova.keypair_delete(IsA(http.HttpRequest), keypair.name)
|
|
self.mox.ReplayAll()
|
|
|
|
formData = {'action': 'keypairs__delete__%s' % keypair.name}
|
|
res = self.client.post(INDEX_VIEW_URL, formData)
|
|
self.assertRedirectsNoFollow(res, INDEX_VIEW_URL)
|
|
|
|
def test_delete_keypair_exception(self):
|
|
keypair = self.keypairs.first()
|
|
self.mox.StubOutWithMock(api.nova, 'keypair_list')
|
|
self.mox.StubOutWithMock(api.nova, 'keypair_delete')
|
|
self.mox.StubOutWithMock(api, 'security_group_list')
|
|
self.mox.StubOutWithMock(api, 'tenant_floating_ip_list')
|
|
self.mox.StubOutWithMock(api.nova, 'server_list')
|
|
|
|
api.nova.server_list(IsA(http.HttpRequest),
|
|
all_tenants=True).AndReturn(self.servers.list())
|
|
api.security_group_list(IsA(http.HttpRequest)) \
|
|
.AndReturn(self.security_groups.list())
|
|
api.tenant_floating_ip_list(IsA(http.HttpRequest)) \
|
|
.AndReturn(self.floating_ips.list())
|
|
api.nova.keypair_list(IsA(http.HttpRequest)) \
|
|
.AndReturn(self.keypairs.list())
|
|
api.nova.keypair_delete(IsA(http.HttpRequest), keypair.name) \
|
|
.AndRaise(self.exceptions.nova)
|
|
self.mox.ReplayAll()
|
|
|
|
formData = {'action': 'keypairs__delete__%s' % keypair.name}
|
|
res = self.client.post(INDEX_VIEW_URL, formData)
|
|
self.assertRedirectsNoFollow(res, INDEX_VIEW_URL)
|
|
|
|
def test_create_keypair_get(self):
|
|
res = self.client.get(
|
|
reverse('horizon:nova:access_and_security:keypairs:create'))
|
|
self.assertTemplateUsed(res,
|
|
'nova/access_and_security/keypairs/create.html')
|
|
|
|
def test_download_keypair_get(self):
|
|
keypair_name = "keypair"
|
|
context = {'keypair_name': keypair_name}
|
|
url = reverse('horizon:nova:access_and_security:keypairs:download',
|
|
kwargs={'keypair_name': keypair_name})
|
|
res = self.client.get(url, context)
|
|
self.assertTemplateUsed(
|
|
res, 'nova/access_and_security/keypairs/download.html')
|
|
|
|
def test_generate_keypair_get(self):
|
|
keypair = self.keypairs.first()
|
|
keypair.private_key = "secret"
|
|
|
|
self.mox.StubOutWithMock(api, 'keypair_create')
|
|
api.keypair_create(IsA(http.HttpRequest),
|
|
keypair.name).AndReturn(keypair)
|
|
self.mox.ReplayAll()
|
|
|
|
context = {'keypair_name': keypair.name}
|
|
url = reverse('horizon:nova:access_and_security:keypairs:generate',
|
|
kwargs={'keypair_name': keypair.name})
|
|
res = self.client.get(url, context)
|
|
|
|
self.assertTrue(res.has_header('content-disposition'))
|
|
|
|
def test_generate_keypair_exception(self):
|
|
keypair = self.keypairs.first()
|
|
|
|
self.mox.StubOutWithMock(api, 'keypair_create')
|
|
api.keypair_create(IsA(http.HttpRequest), keypair.name) \
|
|
.AndRaise(self.exceptions.nova)
|
|
self.mox.ReplayAll()
|
|
|
|
context = {'keypair_name': keypair.name}
|
|
url = reverse('horizon:nova:access_and_security:keypairs:generate',
|
|
kwargs={'keypair_name': keypair.name})
|
|
res = self.client.get(url, context)
|
|
|
|
self.assertRedirectsNoFollow(
|
|
res, reverse('horizon:nova:access_and_security:index'))
|