"Fossies" - the Fresh Open Source Software Archive 
Member "senlin-8.0.0/senlin/tests/unit/db/test_cred_api.py" (16 Oct 2019, 3594 Bytes) of package /linux/misc/openstack/senlin-8.0.0.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.
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 import copy
14
15 from senlin.db.sqlalchemy import api as db_api
16 from senlin.tests.unit.common import base
17 from senlin.tests.unit.common import utils
18 from senlin.tests.unit.db import shared
19
20 USER_ID = shared.UUID1
21 PROJECT_ID = '26e4df6952b144e5823aae7ce463a240'
22 values = {
23 'user': USER_ID,
24 'project': PROJECT_ID,
25 'cred': {
26 'openstack': {
27 'trust': '01234567890123456789012345678901',
28 },
29 },
30 'data': {}
31 }
32
33
34 class DBAPICredentialTest(base.SenlinTestCase):
35
36 def setUp(self):
37 super(DBAPICredentialTest, self).setUp()
38 self.ctx = utils.dummy_context()
39
40 def test_cred_create(self):
41 cred = db_api.cred_create(self.ctx, values)
42 self.assertIsNotNone(cred)
43 self.assertEqual(USER_ID, cred.user)
44 self.assertEqual(PROJECT_ID, cred.project)
45 self.assertEqual(
46 {'openstack': {'trust': '01234567890123456789012345678901'}},
47 cred.cred)
48 self.assertEqual({}, cred.data)
49
50 def test_cred_get(self):
51 cred = db_api.cred_get(self.ctx, USER_ID, PROJECT_ID)
52 self.assertIsNone(cred)
53
54 db_api.cred_create(self.ctx, values)
55
56 cred = db_api.cred_get(self.ctx, USER_ID, PROJECT_ID)
57 self.assertIsNotNone(cred)
58 self.assertEqual(USER_ID, cred.user)
59 self.assertEqual(PROJECT_ID, cred.project)
60 self.assertEqual(
61 {'openstack': {'trust': '01234567890123456789012345678901'}},
62 cred.cred)
63 self.assertEqual({}, cred.data)
64
65 def test_cred_update(self):
66 db_api.cred_create(self.ctx, values)
67 new_values = {
68 'cred': {
69 'openstack': {
70 'trust': 'newtrust'
71 }
72 }
73 }
74 db_api.cred_update(self.ctx, USER_ID, PROJECT_ID, new_values)
75 cred = db_api.cred_get(self.ctx, USER_ID, PROJECT_ID)
76 self.assertIsNotNone(cred)
77 self.assertEqual({'openstack': {'trust': 'newtrust'}},
78 cred.cred)
79
80 def test_cred_delete(self):
81 cred = db_api.cred_delete(self.ctx, USER_ID, PROJECT_ID)
82 self.assertIsNone(cred)
83
84 db_api.cred_create(self.ctx, values)
85 cred = db_api.cred_delete(self.ctx, USER_ID, PROJECT_ID)
86 self.assertIsNone(cred)
87
88 def test_cred_create_update(self):
89 cred = db_api.cred_create_update(self.ctx, values)
90 self.assertIsNotNone(cred)
91 self.assertEqual(USER_ID, cred.user)
92 self.assertEqual(PROJECT_ID, cred.project)
93 self.assertEqual(
94 {'openstack': {'trust': '01234567890123456789012345678901'}},
95 cred.cred)
96 self.assertEqual({}, cred.data)
97
98 new_values = copy.deepcopy(values)
99 new_values['cred']['openstack']['trust'] = 'newtrust'
100 cred = db_api.cred_create_update(self.ctx, new_values)
101 self.assertEqual(USER_ID, cred.user)
102 self.assertEqual(PROJECT_ID, cred.project)
103 self.assertEqual(
104 {'openstack': {'trust': 'newtrust'}},
105 cred.cred)