GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#5)
by
unknown
05:28
created

st2tests.mocks.MockSensorService.set_value()   A

Complexity

Conditions 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 16
rs 9.4285
cc 2
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 st2reactor.container.sensor_wrapper import SensorService
25
from st2tests.mocks.datastore import MockDatastoreService
26
27
__all__ = [
28
    'MockSensorWrapper',
29
    'MockSensorService'
30
]
31
32
33
class MockSensorWrapper(object):
34
    def __init__(self, pack, class_name):
35
        self._pack = pack
36
        self._class_name = class_name
37
38
39
class MockSensorService(SensorService):
40
    """
41
    Mock SensorService for use in testing.
42
    """
43
44
    def __init__(self, sensor_wrapper):
45
        self._sensor_wrapper = sensor_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
        # Holds a list of triggers which were dispatched
52
        self.dispatched_triggers = []
53
54
        self._datastore_service = MockDatastoreService(logger=self._logger,
55
                                                       pack_name=self._sensor_wrapper._pack,
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _pack was declared protected and should not be accessed from this context.

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:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
56
                                                       class_name=self._sensor_wrapper._class_name,
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _class_name was declared protected and should not be accessed from this context.

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:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
57
                                                       api_username='sensor_service')
58
59
    def get_logger(self, name):
60
        """
61
        Return mock logger instance.
62
63
        Keep in mind that this method returns Mock class instance which means you can use all the
64
        usual Mock class methods to assert that a particular message has been logged / logger has
65
        been called with particular arguments.
66
        """
67
        return self._logger
68
69
    def dispatch_with_context(self, trigger, payload=None, trace_context=None):
70
        item = {
71
            'trigger': trigger,
72
            'payload': payload,
73
            'trace_context': trace_context
74
        }
75
        self.dispatched_triggers.append(item)
76