1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2012 Nebula Inc
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6
# not use this file except in compliance with the License. You may obtain
7
# a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
# License for the specific language governing permissions and limitations
17
from django.http import HttpRequest
18
from django.core.urlresolvers import reverse
21
from horizon import api
22
from horizon import test
23
from .forms import DownloadX509Credentials
26
INDEX_URL = reverse("horizon:settings:ec2:index")
29
class EC2SettingsTest(test.TestCase):
30
def test_ec2_download_view(self):
31
creds = self.ec2.first()
32
cert = self.certs.first()
34
self.mox.StubOutWithMock(api.keystone, "tenant_list")
35
self.mox.StubOutWithMock(api.nova, "get_x509_credentials")
36
self.mox.StubOutWithMock(api.nova, "get_x509_root_certificate")
37
self.mox.StubOutWithMock(api.keystone, "create_ec2_credentials")
40
api.keystone.tenant_list(IsA(HttpRequest)) \
41
.AndReturn(self.tenants.list())
44
api.keystone.tenant_list(IsA(HttpRequest)) \
45
.AndReturn(self.tenants.list())
46
api.nova.get_x509_credentials(IsA(HttpRequest)).AndReturn(cert)
47
api.nova.get_x509_root_certificate(IsA(HttpRequest)) \
49
api.keystone.create_ec2_credentials(IsA(HttpRequest),
51
self.tenant.id).AndReturn(creds)
54
res = self.client.get(INDEX_URL)
55
self.assertNoMessages()
56
self.assertEqual(res.status_code, 200)
58
data = {'method': DownloadX509Credentials.__name__,
59
'tenant': self.tenant.id}
60
res = self.client.post(INDEX_URL, data)
61
self.assertEqual(res['content-type'], 'application/zip')