"Fossies" - the Fresh Open Source Software Archive 
Member "horizon-14.0.4/openstack_dashboard/dashboards/identity/application_credentials/tests.py" (22 Oct 2019, 5617 Bytes) of package /linux/misc/openstack/horizon-14.0.4.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the last
Fossies "Diffs" side-by-side code changes report for "tests.py":
15.1.0_vs_16.0.0.
1 # Copyright 2018 SUSE Linux GmbH
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14
15 import mock
16 import six
17
18 from django.urls import reverse
19
20 from openstack_dashboard import api
21 from openstack_dashboard.test import helpers as test
22
23
24 APP_CREDS_INDEX_URL = reverse('horizon:identity:application_credentials:index')
25
26
27 class ApplicationCredentialViewTests(test.TestCase):
28 def test_application_credential_create_get(self):
29 url = reverse('horizon:identity:application_credentials:create')
30 res = self.client.get(url)
31
32 self.assertTemplateUsed(res,
33 'identity/application_credentials/create.html')
34
35 @mock.patch.object(api.keystone, 'application_credential_create')
36 @mock.patch.object(api.keystone, 'application_credential_list')
37 def test_application_credential_create(self, mock_app_cred_list,
38 mock_app_cred_create):
39 new_app_cred = self.application_credentials.first()
40 mock_app_cred_create.return_value = new_app_cred
41 data = {
42 'name': new_app_cred.name,
43 'description': new_app_cred.description
44 }
45 api_data = {
46 'name': new_app_cred.name,
47 'description': new_app_cred.description,
48 'expires_at': new_app_cred.expires_at,
49 'roles': None,
50 'unrestricted': None,
51 'secret': None
52 }
53
54 url = reverse('horizon:identity:application_credentials:create')
55 res = self.client.post(url, data)
56
57 self.assertNoFormErrors(res)
58 self.assertEqual(res.status_code, 200)
59
60 mock_app_cred_create.assert_called_once_with(test.IsHttpRequest(),
61 **api_data)
62
63 @mock.patch.object(api.keystone, 'application_credential_get')
64 def test_application_credential_detail_get(self, mock_app_cred_get):
65 app_cred = self.application_credentials.list()[1]
66 mock_app_cred_get.return_value = app_cred
67
68 res = self.client.get(
69 reverse('horizon:identity:application_credentials:detail',
70 args=[app_cred.id]))
71
72 self.assertTemplateUsed(
73 res, 'identity/application_credentials/detail.html')
74 self.assertEqual(res.context['application_credential'].name,
75 app_cred.name)
76 mock_app_cred_get.assert_called_once_with(test.IsHttpRequest(),
77 six.text_type(app_cred.id))
78
79 @mock.patch.object(api.keystone, 'application_credential_get')
80 def test_application_credential_detail_get_with_exception(
81 self, mock_app_cred_get):
82 app_cred = self.application_credentials.list()[1]
83
84 mock_app_cred_get.side_effect = self.exceptions.keystone
85
86 url = reverse('horizon:identity:application_credentials:detail',
87 args=[app_cred.id])
88 res = self.client.get(url)
89 self.assertRedirectsNoFollow(res, APP_CREDS_INDEX_URL)
90 mock_app_cred_get.assert_called_once_with(test.IsHttpRequest(),
91 six.text_type(app_cred.id))
92
93 @mock.patch.object(api.keystone, 'application_credential_create')
94 @mock.patch.object(api.keystone, 'application_credential_list')
95 def test_application_credential_openrc(self, mock_app_cred_list,
96 mock_app_cred_create):
97
98 new_app_cred = self.application_credentials.first()
99 mock_app_cred_create.return_value = new_app_cred
100 data = {
101 'name': new_app_cred.name,
102 'description': new_app_cred.description
103 }
104 url = reverse('horizon:identity:application_credentials:create')
105 res = self.client.post(url, data)
106
107 download_url = (
108 'horizon:identity:application_credentials:download_openrc'
109 )
110 url = reverse(download_url)
111 res = self.client.get(url)
112 self.assertEqual(res.status_code, 200)
113 self.assertTemplateUsed(
114 res, 'identity/application_credentials/openrc.sh.template')
115
116 @mock.patch.object(api.keystone, 'application_credential_create')
117 @mock.patch.object(api.keystone, 'application_credential_list')
118 def test_application_credential_cloudsyaml(self, mock_app_cred_list,
119 mock_app_cred_create):
120
121 new_app_cred = self.application_credentials.first()
122 mock_app_cred_create.return_value = new_app_cred
123 data = {
124 'name': new_app_cred.name,
125 'description': new_app_cred.description
126 }
127 url = reverse('horizon:identity:application_credentials:create')
128 res = self.client.post(url, data)
129
130 download_url = (
131 'horizon:identity:application_credentials:download_clouds_yaml'
132 )
133 url = reverse(download_url)
134 res = self.client.get(url)
135 self.assertEqual(res.status_code, 200)
136 self.assertTemplateUsed(
137 res, 'identity/application_credentials/clouds.yaml.template')