def test_script_call_return_as_dict(self, _): name = 'foo' regions = [ ReturnRegion( type_='list', content='%return list', ), ] script = Script( name=name, regions=regions, ) value = {'a': 1, 'b': 3.5, 'c': None, 'd': ['a', 2], 'e': 's'} script._redis_script = MagicMock(return_value=jdumps(value)) result = script.get_runner(client=None)() self.assertEqual(value, result) script._redis_script.assert_called_once_with( keys=[], args=[], client=None, )
def test_script_run(self, _): name = 'foo' regions = [ KeyRegion( name='key1', index=1, content='%key key1', ), ArgumentRegion( name='arg1', index=1, type_='string', content='%arg arg1', ), TextRegion(content='b'), KeyRegion( name='key2', index=2, content='%key key2', ), ArgumentRegion( name='arg2', index=2, type_='integer', content='%arg arg2', ), ArgumentRegion( name='arg3', index=3, type_='bool', content='%arg arg3', ), ArgumentRegion( name='arg4', index=4, type_='list', content='%arg arg4', ), ArgumentRegion( name='arg5', index=5, type_='dict', content='%arg arg5', ), ] script = Script( name=name, regions=regions, ) script._redis_script = MagicMock(return_value="result") result = script.get_runner(client=None)( arg1='ARG', arg2=2, arg3=False, arg4=(1, 2.5, None, 'a'), arg5={'b': None}, key1='KEY', key2='KEY 2', ) self.assertEqual("result", result) script._redis_script.assert_called_once_with( keys=['KEY', 'KEY 2'], args=[ 'ARG', 2, 0, jdumps([1, 2.5, None, 'a']), jdumps({'b': None}), ], client=None, )