This file is indexed.

/usr/lib/python3/dist-packages/designateclient/tests/test_utils.py is in python3-designateclient 2.9.0-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Copyright (c) 2015 Thales Services SAS
# 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 uuid

import mock


from designateclient import exceptions
from designateclient.tests import base
from designateclient import utils


LIST_MOCK_RESPONSE = [
    {'id': '13579bdf-0000-0000-abcd-000000000001', 'name': 'abcd'},
    {'id': '13579bdf-0000-0000-baba-000000000001', 'name': 'baba'},
    {'id': '13579bdf-0000-0000-baba-000000000002', 'name': 'baba'},
]


class UtilsTestCase(base.TestCase):

    def _find_resourceid_by_name_or_id(self, name_or_id, by_name=False):
        resource_client = mock.Mock()
        resource_client.list.return_value = LIST_MOCK_RESPONSE
        resourceid = utils.find_resourceid_by_name_or_id(
            resource_client, name_or_id)
        self.assertEqual(by_name, resource_client.list.called)
        return resourceid

    def test_find_resourceid_with_hyphen_uuid(self):
        expected = str(uuid.uuid4())
        observed = self._find_resourceid_by_name_or_id(expected)
        self.assertEqual(expected, observed)

    def test_find_resourceid_with_nonhyphen_uuid(self):
        expected = str(uuid.uuid4())
        fakeid = expected.replace('-', '')
        observed = self._find_resourceid_by_name_or_id(fakeid)
        self.assertEqual(expected, observed)

    def test_find_resourceid_with_unique_resource(self):
        observed = self._find_resourceid_by_name_or_id('abcd', by_name=True)
        self.assertEqual('13579bdf-0000-0000-abcd-000000000001', observed)

    def test_find_resourceid_with_nonexistent_resource(self):
        self.assertRaises(exceptions.ResourceNotFound,
                          self._find_resourceid_by_name_or_id,
                          'taz', by_name=True)

    def test_find_resourceid_with_multiple_resources(self):
        self.assertRaises(exceptions.NoUniqueMatch,
                          self._find_resourceid_by_name_or_id,
                          'baba', by_name=True)

    def test_load_schema(self):
        schema = utils.load_schema('v1', 'domain')
        self.assertIsInstance(schema, dict)

    def test_load_schema_missing(self):
        self.assertRaises(exceptions.ResourceNotFound, utils.load_schema,
                          'v1', 'missing')

    def test_resource_string_empty_param(self):
        self.assertRaises(ValueError, utils.resource_string)

    def test_resource_string(self):
        name = ['schemas', 'v1', 'domain.json']
        resource_string = utils.resource_string(*name)
        self.assertIsNotNone(resource_string)

    def test_resource_string_missing(self):
        name = ['schemas', 'v1', 'missing']
        self.assertRaises(exceptions.ResourceNotFound, utils.resource_string,
                          *name)