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.MockDatastoreService.list_values()   A

Complexity

Conditions 4

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 15
rs 9.2
cc 4
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 st2common.services.datastore import DatastoreService
21
from st2client.models.keyvalue import KeyValuePair
22
23
__all__ = [
24
    'MockDatastoreService'
25
]
26
27
28
class MockDatastoreService(DatastoreService):
29
    """
30
    Mock DatastoreService for use in testing.
31
    """
32
    def __init__(self, logger, pack_name, class_name, api_username):
33
        # Holds mock KeyValuePair objects
34
        # Key is a KeyValuePair name and value is the KeyValuePair object
35
        self._datastore_items = {}
36
37
    def list_values(self, local=True, prefix=None):
38
        """
39
        Return a list of all values stored in a dictionary which is local to this class.
40
        """
41
        key_prefix = self._get_full_key_prefix(local=local, prefix=prefix)
42
43
        if not key_prefix:
44
            return self._datastore_items.values()
45
46
        result = []
47
        for name, kvp in self._datastore_items.items():
48
            if name.startswith(key_prefix):
49
                result.append(kvp)
50
51
        return result
52
53
    def get_value(self, name, local=True):
54
        """
55
        Return a particular value stored in a dictionary which is local to this class.
56
        """
57
        name = self._get_full_key_name(name=name, local=local)
58
59
        if name not in self._datastore_items:
60
            return None
61
62
        kvp = self._datastore_items[name]
63
        return kvp.value
64
65
    def set_value(self, name, value, ttl=None, local=True):
66
        """
67
        Store a value in a dictionary which is local to this class.
68
        """
69
        if ttl:
70
            raise ValueError('MockSensorService.set_value doesn\'t support "ttl" argument')
71
72
        name = self._get_full_key_name(name=name, local=local)
73
74
        instance = KeyValuePair()
75
        instance.id = name
76
        instance.name = name
77
        instance.value = value
78
79
        self._datastore_items[name] = instance
80
        return True
81
82
    def delete_value(self, name, local=True):
83
        """
84
        Delete a value from a dictionary which is local to this class.
85
        """
86
        name = self._get_full_key_name(name=name, local=local)
87
88
        if name not in self._datastore_items:
89
            return False
90
91
        del self._datastore_items[name]
92
        return True
93