1
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
2
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
3
|
|
|
# this work for additional information regarding copyright ownership. |
4
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
5
|
|
|
# (the "License"); you may not use this file except in compliance with |
6
|
|
|
# the License. You may obtain a copy of the License at |
7
|
|
|
# |
8
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
9
|
|
|
# |
10
|
|
|
# Unless required by applicable law or agreed to in writing, software |
11
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
12
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13
|
|
|
# See the License for the specific language governing permissions and |
14
|
|
|
# limitations under the License. |
15
|
|
|
|
16
|
|
|
""" |
17
|
|
|
Mock classes for use in pack testing. |
18
|
|
|
""" |
19
|
|
|
|
20
|
|
|
from logging import RootLogger |
21
|
|
|
|
22
|
|
|
from mock import Mock |
23
|
|
|
|
24
|
|
|
from st2actions.runners.python_action_wrapper import ActionService |
25
|
|
|
from st2tests.mocks.datastore import MockDatastoreService |
26
|
|
|
|
27
|
|
|
__all__ = [ |
28
|
|
|
'MockActionWrapper', |
29
|
|
|
'MockActionService' |
30
|
|
|
] |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
class MockActionWrapper(object): |
34
|
|
|
def __init__(self, pack, class_name): |
35
|
|
|
self._pack = pack |
36
|
|
|
self._class_name = class_name |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
class MockActionService(ActionService): |
40
|
|
|
""" |
41
|
|
|
Mock ActionService for use in testing. |
42
|
|
|
""" |
43
|
|
|
|
44
|
|
|
def __init__(self, action_wrapper): |
45
|
|
|
self._action_wrapper = action_wrapper |
46
|
|
|
|
47
|
|
|
# Holds a mock logger instance |
48
|
|
|
# We use a Mock class so use can assert logger was called with particular arguments |
49
|
|
|
self._logger = Mock(spec=RootLogger) |
50
|
|
|
|
51
|
|
|
self._datastore_service = MockDatastoreService(logger=self._logger, |
52
|
|
|
pack_name=self._action_wrapper._pack, |
|
|
|
|
53
|
|
|
class_name=self._action_wrapper._class_name, |
|
|
|
|
54
|
|
|
api_username='action_service') |
55
|
|
|
|
Prefixing a member variable
_
is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class: