This file is indexed.

/usr/lib/python2.7/dist-packages/heatclient/tests/unit/test_events.py is in python-heatclient 1.1.0-2.

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
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Copyright 2013 IBM Corp.
#
#    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.

from heatclient.common import utils
from heatclient.v1 import events

import mock
from mox3 import mox
import testtools


class EventManagerTest(testtools.TestCase):

    def setUp(self):
        super(EventManagerTest, self).setUp()
        self.m = mox.Mox()
        self.addCleanup(self.m.VerifyAll)
        self.addCleanup(self.m.UnsetStubs)

    def test_list_event(self):
        stack_id = 'teststack',
        resource_name = 'testresource'
        manager = events.EventManager(None)
        self.m.StubOutWithMock(manager, '_resolve_stack_id')
        manager._resolve_stack_id(stack_id).AndReturn('teststack/abcd1234')
        self.m.ReplayAll()
        manager._list = mock.MagicMock()
        manager.list(stack_id, resource_name)
        # Make sure url is correct.
        manager._list.assert_called_once_with('/stacks/teststack%2Fabcd1234/'
                                              'resources/testresource/events',
                                              "events")

    def test_list_event_with_unicode_resource_name(self):
        stack_id = 'teststack',
        resource_name = u'\u5de5\u4f5c'
        manager = events.EventManager(None)
        self.m.StubOutWithMock(manager, '_resolve_stack_id')
        manager._resolve_stack_id(stack_id).AndReturn('teststack/abcd1234')
        self.m.ReplayAll()
        manager._list = mock.MagicMock()
        manager.list(stack_id, resource_name)
        # Make sure url is correct.
        manager._list.assert_called_once_with('/stacks/teststack%2Fabcd1234/'
                                              'resources/%E5%B7%A5%E4%BD%9C/'
                                              'events', "events")

    def test_list_event_with_none_resource_name(self):
        stack_id = 'teststack',
        manager = events.EventManager(None)
        manager._list = mock.MagicMock()
        manager.list(stack_id)
        # Make sure url is correct.
        manager._list.assert_called_once_with('/stacks/teststack/'
                                              'events', "events")

    def test_list_event_with_kwargs(self):
        stack_id = 'teststack',
        resource_name = 'testresource'
        kwargs = {'limit': 2,
                  'marker': '6d6935f4-0ae5',
                  'filters': {
                      'resource_action': 'CREATE',
                      'resource_status': 'COMPLETE'
                  }}
        manager = events.EventManager(None)
        self.m.StubOutWithMock(manager, '_resolve_stack_id')
        manager._resolve_stack_id(stack_id).AndReturn('teststack/abcd1234')
        self.m.ReplayAll()
        manager._list = mock.MagicMock()
        manager.list(stack_id, resource_name, **kwargs)
        # Make sure url is correct.
        self.assertEqual(1, manager._list.call_count)
        args = manager._list.call_args
        self.assertEqual(2, len(args[0]))
        url, param = args[0]
        self.assertEqual("events", param)
        base_url, query_params = utils.parse_query_url(url)
        expected_base_url = ('/stacks/teststack%2Fabcd1234/'
                             'resources/testresource/events')
        self.assertEqual(expected_base_url, base_url)
        expected_query_dict = {'marker': ['6d6935f4-0ae5'],
                               'limit': ['2'],
                               'resource_action': ['CREATE'],
                               'resource_status': ['COMPLETE']}
        self.assertEqual(expected_query_dict, query_params)

    def test_get_event(self):
        fields = {'stack_id': 'teststack',
                  'resource_name': 'testresource',
                  'event_id': '1'}

        class FakeAPI(object):
            """Fake API and ensure request url is correct."""

            def json_request(self, *args, **kwargs):
                expect = ('GET',
                          '/stacks/teststack%2Fabcd1234/resources'
                          '/testresource/events/1')
                assert args == expect
                return {}, {'event': []}

            def get(self, *args, **kwargs):
                pass

        manager = events.EventManager(FakeAPI())
        with mock.patch('heatclient.v1.events.Event'):
            self.m.StubOutWithMock(manager, '_resolve_stack_id')
            self.m.StubOutWithMock(utils, 'get_response_body')
            utils.get_response_body(mox.IgnoreArg()).AndReturn({'event': []})
            manager._resolve_stack_id('teststack').AndReturn(
                'teststack/abcd1234')
            self.m.ReplayAll()
            manager.get(**fields)

    def test_get_event_with_unicode_resource_name(self):
        fields = {'stack_id': 'teststack',
                  'resource_name': u'\u5de5\u4f5c',
                  'event_id': '1'}

        class FakeAPI(object):
            """Fake API and ensure request url is correct."""

            def json_request(self, *args, **kwargs):
                expect = ('GET',
                          '/stacks/teststack%2Fabcd1234/resources'
                          '/%E5%B7%A5%E4%BD%9C/events/1')
                assert args == expect
                return {}, {'event': []}

            def get(self, *args, **kwargs):
                pass

        manager = events.EventManager(FakeAPI())
        with mock.patch('heatclient.v1.events.Event'):
            self.m.StubOutWithMock(manager, '_resolve_stack_id')
            self.m.StubOutWithMock(utils, 'get_response_body')
            utils.get_response_body(mox.IgnoreArg()).AndReturn({'event': []})
            manager._resolve_stack_id('teststack').AndReturn(
                'teststack/abcd1234')
            self.m.ReplayAll()
            manager.get(**fields)