Debian Codegraph @

keystoneclient/tests/unit/v3/test_simple_cert.py

raw symbols SCIP
1 # Copyright 2014 IBM Corp.
2 # Licensed under the Apache License, Version 2.0 (the "License"); you may
3 # not use this file except in compliance with the License. You may obtain
4 # a copy of the License at
5 #
6 # http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11 # License for the specific language governing permissions and limitations
12 # under the License.
13
14 import fixtures
15 import testresources
16
17 from keystoneclient.tests.unit import client_fixtures
18 from keystoneclient.tests.unit.v3 import utils
19 from keystoneclient.v3.contrib import simple_cert
20
21
22 class SimpleCertTests(utils.ClientTestCase, testresources.ResourcedTestCase):
23
24 resources = [('examples', client_fixtures.EXAMPLES_RESOURCE)]
25
26 def test_get_ca_certificate(self):
27 self.stub_url('GET', ['OS-SIMPLE-CERT', 'ca'],
28 headers={'Content-Type': 'application/x-pem-file'},
29 text=self.examples.SIGNING_CA)
30 res = self.client.simple_cert.get_ca_certificates()
31 self.assertEqual(self.examples.SIGNING_CA, res)
32
33 def test_get_certificates(self):
34 self.stub_url('GET', ['OS-SIMPLE-CERT', 'certificates'],
35 headers={'Content-Type': 'application/x-pem-file'},
36 text=self.examples.SIGNING_CERT)
37 res = self.client.simple_cert.get_certificates()
38 self.assertEqual(self.examples.SIGNING_CERT, res)
39
40
41 class SimpleCertRequestIdTests(utils.TestRequestId):
42
43 def setUp(self):
44 super(SimpleCertRequestIdTests, self).setUp()
45 self.mgr = simple_cert.SimpleCertManager(self.client)
46
47 def _mock_request_method(self, method=None, body=None):
48 return self.useFixture(fixtures.MockPatchObject(
49 self.client, method, autospec=True,
50 return_value=(self.resp, body))
51 ).mock
52
53 def test_list_ca_certificates(self):
54 body = {"certificates": [{"name": "admin"}, {"name": "admin2"}]}
55 get_mock = self._mock_request_method(method='get', body=body)
56
57 response = self.mgr.get_ca_certificates()
58 self.assertEqual(response.request_ids[0], self.TEST_REQUEST_ID)
59 get_mock.assert_called_once_with(
60 '/OS-SIMPLE-CERT/ca', authenticated=False)
61
62 def test_list_certificates(self):
63 body = {"certificates": [{"name": "admin"}, {"name": "admin2"}]}
64 get_mock = self._mock_request_method(method='get', body=body)
65
66 response = self.mgr.get_certificates()
67 self.assertEqual(response.request_ids[0], self.TEST_REQUEST_ID)
68 get_mock.assert_called_once_with(
69 '/OS-SIMPLE-CERT/certificates', authenticated=False)
70
71
72 def load_tests(loader, tests, pattern):
73 return testresources.OptimisingTestSuite(tests)