summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorChris Yeoh <cyeoh@au1.ibm.com>2013-06-13 14:08:43 +0930
committerChris Yeoh <cyeoh@au1.ibm.com>2013-06-13 14:08:43 +0930
commit71ece4a73c86995685fcbc8de2237f4fd70d0f53 (patch)
tree4757035eb0dfa0434931d553a12d47f3dad2aa5e /nova/tests
parent53f62b33caa71de1da3163e0f835e39ea7a64ee8 (diff)
Port certificates API to v3 Part 1
This changeset only copies the v2 files (implementation and test) into the appropriate v3 directories unchanged. The copy as-is will not be loaded by either the v2 or v3 extension loaders. The second changeset will then make the changes required for it to work as a v3 extension. This is being done in order to make reviewing of extension porting easier as gerrit will display only what is actually changed for v3 rather than entirely new files Partially implements blueprint nova-v3-api Change-Id: Ibdb3b444432fa707786e6bb43aaba61d2a3fc89f
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/compute/plugins/v3/test_certificates.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/nova/tests/api/openstack/compute/plugins/v3/test_certificates.py b/nova/tests/api/openstack/compute/plugins/v3/test_certificates.py
new file mode 100644
index 000000000..df5a7e9a1
--- /dev/null
+++ b/nova/tests/api/openstack/compute/plugins/v3/test_certificates.py
@@ -0,0 +1,77 @@
+# Copyright (c) 2012 OpenStack Foundation
+# All Rights Reserved.
+#
+# 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 lxml import etree
+
+from nova.api.openstack.compute.contrib import certificates
+from nova import context
+from nova.openstack.common import rpc
+from nova import test
+from nova.tests.api.openstack import fakes
+
+
+def fake_get_root_cert(context, *args, **kwargs):
+ return 'fakeroot'
+
+
+def fake_create_cert(context, *args, **kwargs):
+ return 'fakepk', 'fakecert'
+
+
+class CertificatesTest(test.TestCase):
+ def setUp(self):
+ super(CertificatesTest, self).setUp()
+ self.context = context.RequestContext('fake', 'fake')
+ self.controller = certificates.CertificatesController()
+
+ def test_translate_certificate_view(self):
+ pk, cert = fake_create_cert(self.context)
+ view = certificates._translate_certificate_view(cert, pk)
+ self.assertEqual(view['data'], cert)
+ self.assertEqual(view['private_key'], pk)
+
+ def test_certificates_show_root(self):
+ self.stubs.Set(rpc, 'call', fake_get_root_cert)
+ req = fakes.HTTPRequest.blank('/v2/fake/os-certificates/root')
+ res_dict = self.controller.show(req, 'root')
+
+ cert = fake_get_root_cert(self.context)
+ response = {'certificate': {'data': cert, 'private_key': None}}
+ self.assertEqual(res_dict, response)
+
+ def test_certificates_create_certificate(self):
+ self.stubs.Set(rpc, 'call', fake_create_cert)
+ req = fakes.HTTPRequest.blank('/v2/fake/os-certificates/')
+ res_dict = self.controller.create(req)
+
+ pk, cert = fake_create_cert(self.context)
+ response = {'certificate': {'data': cert, 'private_key': pk}}
+ self.assertEqual(res_dict, response)
+
+
+class CertificatesSerializerTest(test.TestCase):
+ def test_index_serializer(self):
+ serializer = certificates.CertificateTemplate()
+ text = serializer.serialize(dict(
+ certificate=dict(
+ data='fakecert',
+ private_key='fakepk'),
+ ))
+
+ tree = etree.fromstring(text)
+
+ self.assertEqual('certificate', tree.tag)
+ self.assertEqual('fakepk', tree.get('private_key'))
+ self.assertEqual('fakecert', tree.get('data'))