This file is indexed.

/usr/lib/python3/dist-packages/muranopkgcheck/tests/functional/test_cases.py is in python3-murano-pkg-check 0.3.0-0ubuntu4.

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
86
87
88
89
90
91
92
93
94
95
#    Copyright (c) 2016 Mirantis, Inc.
#
# 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 io
import os

import oslotest.base
import six
import testscenarios
import yaml

from muranopkgcheck import consts
from muranopkgcheck import manager
from muranopkgcheck import pkg_loader


class DictLoader(pkg_loader.BaseLoader):

    @classmethod
    def _try_load(cls, pkg):
        if consts.MANIFEST_PATH in pkg:
            return cls(pkg)
        return None

    def __init__(self, pkg):
        super(DictLoader, self).__init__('')
        self.pkg = pkg

    def open_file(self, path, mode='r'):
        if self.pkg[path]['format'] == 'raw':
            sio = io.BytesIO(six.b(self.pkg[path]['content']))
            setattr(sio, 'name', path)
        elif self.pkg[path]['format'] == 'yaml':
            content = yaml.safe_dump(self.pkg[path]['content'])
            sio = io.BytesIO(six.b(content))
            setattr(sio, 'name', path)
        else:
            raise ValueError('Unknown type of content')
        return sio

    def list_files(self, subdir=None):
        files = self.pkg.keys()
        if subdir is None:
            return files
        subdir_len = len(subdir)
        return [file_[subdir_len:].lstrip('/') for file_ in files
                if file_.startswith(subdir)]

    def exists(self, name):
        return name in self.pkg


class DictFormatter(manager.Formatter):

    def format(self, error):
        return sorted([{'code': e.code, 'msg': e.message} for e in error],
                      key=lambda item: item['code'])


def load_cases():
    cases_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                              'cases')
    cases_files = [os.path.join(cases_path, f)for f in os.listdir(cases_path)
                   if os.path.isfile(os.path.join(cases_path, f))]
    cases = []
    for cases_file in cases_files:
        with open(cases_file) as f:
            cases.extend(list(yaml.load_all(f)))
    return cases

cases = load_cases()


class TestCase(testscenarios.WithScenarios, oslotest.base.BaseTestCase):

    """Test case base class for all unit tests."""

    scenarios = cases

    def test_foo(self):
        m = manager.Manager(self.pkg, loader=DictLoader)
        errors = m.validate()
        fmt = DictFormatter()
        self.assertEqual(self.expected, fmt.format(errors))