Skip to content

An exception is raised when calling MockDatastoreService.set_value() with a ttl #4880

@ya3xp

Description

@ya3xp

SUMMARY

When using MockDatastoreService.set_value() for unit testing (e.g. via BaseActionTestCase), a ValueError exception will be raised if ttl argument is specified.

STACKSTORM VERSION

st2 3.1.0, on Python 3.6.8

OS, environment, install method

Custom install, but not relevant to this case, see below.

Steps to reproduce the problem

See code for MockDatastoreService.set_value(). If ttl argument is specified, ValueError will explicitly be raised.

class MockDatastoreService(BaseDatastoreService):
    # ...
    def set_value(self, name, value, ttl=None, local=True, scope=SYSTEM_SCOPE, encrypt=False):
        """
        Store a value in a dictionary which is local to this class.
        """
        if ttl:
            raise ValueError('MockDatastoreService.set_value doesn\'t support "ttl" argument')
        # ...

Expected Results

Both action_service.set_value() and sensor_service.set_value() support ttl argument. Although I understand that this argument cannot be honored in a mock situation, MockDatastoreService should be consistent with the behavior of the class it is mocking - perhaps fire a warning instead of an Exception?

Actual Results

An exception is returned while running tests:

ValueError: MockDatastoreService.set_value doesn't support "ttl" argument

It is not possible to test actions or sensors that use xxx.set_value() with a ttl argument.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions