Skip to content

Commit e43b948

Browse files
authored
Merge pull request #5468 from ytjohn/patch-1
Enable setting ttl for MockDatastoreService
2 parents 3981ab0 + be000fb commit e43b948

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ in development
77
Added
88
~~~~~
99

10+
* Enable setting ttl for MockDatastoreService. #5468
11+
12+
Contributed by @ytjohn
13+
1014
* Added st2 API and CLI command for actions clone operation.
1115

1216
API endpoint ``/api/v1/actions/{ref_or_id}/clone`` takes ``ref_or_id`` of source action.

st2tests/st2tests/mocks/datastore.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def __init__(self, logger, pack_name, class_name, api_username=None):
3434
self._pack_name = pack_name
3535
self._class_name = class_name
3636
self._username = api_username or "admin"
37+
self._logger = logger
3738

3839
# Holds mock KeyValuePair objects
3940
# Key is a KeyValuePair name and value is the KeyValuePair object
@@ -96,17 +97,18 @@ def set_value(
9697
"""
9798
Store a value in a dictionary which is local to this class.
9899
"""
99-
if ttl:
100-
raise ValueError(
101-
'MockDatastoreService.set_value doesn\'t support "ttl" argument'
102-
)
103100

104101
name = self._get_full_key_name(name=name, local=local)
105102

106103
instance = KeyValuePair()
107104
instance.id = name
108105
instance.name = name
109106
instance.value = value
107+
if ttl:
108+
self._logger.warning(
109+
"MockDatastoreService is not able to expire keys based on ttl."
110+
)
111+
instance.ttl = ttl
110112

111113
self._datastore_items[name] = instance
112114
return True

0 commit comments

Comments
 (0)