1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# Copyright (c) 2017
#
# 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.
import testtools
import barbicanclient
from barbicanclient import base
from barbicanclient import version
class TestValidateRef(testtools.TestCase):
def test_valid_ref(self):
ref = 'http://localhost/ff2ca003-5ebb-4b61-8a17-3f9c54ef6356'
self.assertTrue(base.validate_ref(ref, 'Thing'))
def test_invalid_uuid(self):
ref = 'http://localhost/not_a_uuid'
self.assertRaises(ValueError, base.validate_ref, ref, 'Thing')
def test_censored_copy(self):
d1 = {'a': '1', 'password': 'my_password', 'payload': 'my_key',
'b': '2'}
d2 = base.censored_copy(d1, None)
self.assertEqual(d1, d2, 'd2 contents are unchanged')
self.assertFalse(d1 is d2, 'd1 and d2 are different instances')
d3 = base.censored_copy(d1, ['payload'])
self.assertNotEqual(d1, d3, 'd3 has redacted payload value')
self.assertNotEqual(d3['payload'], 'my_key', 'no key in payload')
def test_module_version(self):
self.assertTrue(hasattr(barbicanclient, '__version__'))
# Test forward compatibility, please remove the case when all reference
# switch to barbicanclient.__version__
self.assertTrue(hasattr(version, '__version__'))
|