def test_filter_from_yaml_string(self): env = jinja_utils.get_jinja_environment() expected_obj = {'a': 'b', 'c': {'d': 'e', 'f': 1, 'g': True}} obj_yaml_str = ("---\n" "a: b\n" "c:\n" " d: e\n" " f: 1\n" " g: true\n") template = '{{k1 | from_yaml_string}}' obj_str = env.from_string(template).render({'k1': obj_yaml_str}) obj = eval(obj_str) self.assertDictEqual(obj, expected_obj) # With KeyValueLookup object env = jinja_utils.get_jinja_environment() obj_yaml_str = ("---\n" "- a\n" "- b\n" "- c\n") expected_obj = ['a', 'b', 'c'] template = '{{ k1 | from_yaml_string }}' lookup = KeyValueLookup(scope=FULL_SYSTEM_SCOPE, key_prefix='b') lookup._value_cache['b'] = obj_yaml_str obj_str = env.from_string(template).render({'k1': lookup}) obj = eval(obj_str) self.assertEqual(obj, expected_obj)
def test_filters_regex_substring(self): env = jinja_utils.get_jinja_environment() # Normal (match) template = r'{{input_str | regex_substring("([0-9]{3} \w+ (?:Ave|St|Dr))")}}' actual = env.from_string(template).render( {"input_str": "My address is 123 Somewhere Ave. See you soon!"} ) expected = "123 Somewhere Ave" self.assertEqual(actual, expected) # Selecting second match explicitly template = r'{{input_str | regex_substring("([0-9]{3} \w+ (?:Ave|St|Dr))", 1)}}' actual = env.from_string(template).render( { "input_str": "Your address is 567 Elsewhere Dr. My address is 123 Somewhere Ave." } ) expected = "123 Somewhere Ave" self.assertEqual(actual, expected) # Selecting second match explicitly, but doesn't exist template = r'{{input_str | regex_substring("([0-9]{3} \w+ (?:Ave|St|Dr))", 1)}}' with self.assertRaises(IndexError): actual = env.from_string(template).render( {"input_str": "Your address is 567 Elsewhere Dr."} ) # No match template = r'{{input_str | regex_substring("([0-3]{3} \w+ (?:Ave|St|Dr))")}}' with self.assertRaises(IndexError): actual = env.from_string(template).render( {"input_str": "My address is 986 Somewhere Ave. See you soon!"} )
def test_version_match(self): env = jinja_utils.get_jinja_environment() template = '{{version | version_match(">0.10.0")}}' actual = env.from_string(template).render({'version': '0.10.1'}) expected = 'True' self.assertEqual(actual, expected) actual = env.from_string(template).render({'version': '0.1.1'}) expected = 'False' self.assertEqual(actual, expected) template = '{{version | version_match("<0.10.0")}}' actual = env.from_string(template).render({'version': '0.1.0'}) expected = 'True' self.assertEqual(actual, expected) actual = env.from_string(template).render({'version': '1.1.0'}) expected = 'False' self.assertEqual(actual, expected) template = '{{version | version_match("==0.10.0")}}' actual = env.from_string(template).render({'version': '0.10.0'}) expected = 'True' self.assertEqual(actual, expected) actual = env.from_string(template).render({'version': '0.10.1'}) expected = 'False' self.assertEqual(actual, expected)
def test_jsonpath_query_no_results(self): env = jinja_utils.get_jinja_environment() obj = { 'people': [{ 'first': 'James', 'last': 'd' }, { 'first': 'Jacob', 'last': 'e' }, { 'first': 'Jayden', 'last': 'f' }, { 'missing': 'different' }], 'foo': { 'bar': 'baz' } } query = "query_returns_no_results" template = '{{ obj | jsonpath_query(query) }}' actual_str = env.from_string(template).render({ 'obj': obj, 'query': query }) actual = eval(actual_str) expected = None self.assertEqual(actual, expected)
def test_version_strip_patch(self): env = jinja_utils.get_jinja_environment() template = "{{version | version_strip_patch}}" actual = env.from_string(template).render({"version": "0.10.1"}) expected = "0.10" self.assertEqual(actual, expected)
def test_jsonpath_query_static(self): env = jinja_utils.get_jinja_environment() obj = { "people": [ { "first": "James", "last": "d" }, { "first": "Jacob", "last": "e" }, { "first": "Jayden", "last": "f" }, { "missing": "different" }, ], "foo": { "bar": "baz" }, } template = '{{ obj | jsonpath_query("people[*].first") }}' actual_str = env.from_string(template).render({"obj": obj}) actual = eval(actual_str) expected = ["James", "Jacob", "Jayden"] self.assertEqual(actual, expected)
def test_version_strip_patch(self): env = jinja_utils.get_jinja_environment() template = '{{version | version_strip_patch}}' actual = env.from_string(template).render({'version': '0.10.1'}) expected = '0.10' self.assertEqual(actual, expected)
def test_jsonpath_query_static(self): env = jinja_utils.get_jinja_environment() obj = { 'people': [{ 'first': 'James', 'last': 'd' }, { 'first': 'Jacob', 'last': 'e' }, { 'first': 'Jayden', 'last': 'f' }, { 'missing': 'different' }], 'foo': { 'bar': 'baz' } } template = '{{ obj | jsonpath_query("people[*].first") }}' actual_str = env.from_string(template).render({'obj': obj}) actual = eval(actual_str) expected = ['James', 'Jacob', 'Jayden'] self.assertEqual(actual, expected)
def test_jsonpath_query_no_results(self): env = jinja_utils.get_jinja_environment() obj = { "people": [ { "first": "James", "last": "d" }, { "first": "Jacob", "last": "e" }, { "first": "Jayden", "last": "f" }, { "missing": "different" }, ], "foo": { "bar": "baz" }, } query = "query_returns_no_results" template = "{{ obj | jsonpath_query(query) }}" actual_str = env.from_string(template).render({ "obj": obj, "query": query }) actual = eval(actual_str) expected = None self.assertEqual(actual, expected)
def test_version_match(self): env = jinja_utils.get_jinja_environment() template = '{{version | version_match(">0.10.0")}}' actual = env.from_string(template).render({"version": "0.10.1"}) expected = "True" self.assertEqual(actual, expected) actual = env.from_string(template).render({"version": "0.1.1"}) expected = "False" self.assertEqual(actual, expected) template = '{{version | version_match("<0.10.0")}}' actual = env.from_string(template).render({"version": "0.1.0"}) expected = "True" self.assertEqual(actual, expected) actual = env.from_string(template).render({"version": "1.1.0"}) expected = "False" self.assertEqual(actual, expected) template = '{{version | version_match("==0.10.0")}}' actual = env.from_string(template).render({"version": "0.10.0"}) expected = "True" self.assertEqual(actual, expected) actual = env.from_string(template).render({"version": "0.10.1"}) expected = "False" self.assertEqual(actual, expected)
def test_filters_regex_substring(self): env = jinja_utils.get_jinja_environment() # Normal (match) template = r'{{input_str | regex_substring("([0-9]{3} \w+ (?:Ave|St|Dr))")}}' actual = env.from_string(template).render( {'input_str': 'My address is 123 Somewhere Ave. See you soon!'} ) expected = '123 Somewhere Ave' self.assertEqual(actual, expected) # Selecting second match explicitly template = r'{{input_str | regex_substring("([0-9]{3} \w+ (?:Ave|St|Dr))", 1)}}' actual = env.from_string(template).render( {'input_str': 'Your address is 567 Elsewhere Dr. My address is 123 Somewhere Ave.'} ) expected = '123 Somewhere Ave' self.assertEqual(actual, expected) # Selecting second match explicitly, but doesn't exist template = r'{{input_str | regex_substring("([0-9]{3} \w+ (?:Ave|St|Dr))", 1)}}' with self.assertRaises(IndexError): actual = env.from_string(template).render( {'input_str': 'Your address is 567 Elsewhere Dr.'} ) # No match template = r'{{input_str | regex_substring("([0-3]{3} \w+ (?:Ave|St|Dr))")}}' with self.assertRaises(IndexError): actual = env.from_string(template).render( {'input_str': 'My address is 986 Somewhere Ave. See you soon!'} )
def test_filter_to_yaml_string(self): env = jinja_utils.get_jinja_environment() obj = {"a": "b", "c": {"d": "e", "f": 1, "g": True}} template = "{{k1 | to_yaml_string}}" obj_yaml_str = env.from_string(template).render({"k1": obj}) actual_obj = yaml.safe_load(obj_yaml_str) self.assertDictEqual(obj, actual_obj)
def test_filter_to_yaml_string(self): env = jinja_utils.get_jinja_environment() obj = {'a': 'b', 'c': {'d': 'e', 'f': 1, 'g': True}} template = '{{k1 | to_yaml_string}}' obj_yaml_str = env.from_string(template).render({'k1': obj}) actual_obj = yaml.safe_load(obj_yaml_str) self.assertDictEqual(obj, actual_obj)
def setUp(self): super(JinjaUtilsDecryptTestCase, self).setUp() crypto_key_path = cfg.CONF.keyvalue.encryption_key_path crypto_key = read_crypto_key(key_path=crypto_key_path) self.secret = 'Build a wall' self.secret_value = symmetric_encrypt(encrypt_key=crypto_key, plaintext=self.secret) self.env = jinja_utils.get_jinja_environment()
def test_filter_from_json_string(self): env = jinja_utils.get_jinja_environment() expected_obj = {'a': 'b', 'c': {'d': 'e', 'f': 1, 'g': True}} obj_json_str = '{"a": "b", "c": {"d": "e", "f": 1, "g": true}}' template = '{{k1 | from_json_string}}' obj_str = env.from_string(template).render({'k1': obj_json_str}) obj = eval(obj_str) self.assertDictEqual(obj, expected_obj)
def __init__(self, config=None, action_service=None): super(FormatResultAction, self).__init__(config=config, action_service=action_service) api_url = os.environ.get('ST2_ACTION_API_URL', None) token = os.environ.get('ST2_ACTION_AUTH_TOKEN', None) self.client = Client(api_url=api_url, token=token) self.jinja = jinja_utils.get_jinja_environment() self.jinja.tests['in'] = lambda item, list: item in list path = os.path.dirname(os.path.realpath(__file__)) with open(os.path.join(path, 'templates/default.j2'), 'r') as f: self.default_template = f.read()
def __init__(self, config=None, action_service=None): super(FormatResultAction, self).__init__(config=config, action_service=action_service) api_url = os.environ.get('ST2_ACTION_API_URL', None) token = os.environ.get('ST2_ACTION_AUTH_TOKEN', None) self.client = Client(api_url=api_url, token=token) self.jinja = jinja_utils.get_jinja_environment(allow_undefined=True) self.jinja.tests['in'] = lambda item, list: item in list
def __init__(self, config): super(FormatResultAction, self).__init__(config) api_url = os.environ.get('ST2_ACTION_API_URL', None) token = os.environ.get('ST2_ACTION_AUTH_TOKEN', None) self.client = Client(api_url=api_url, token=token) self.jinja = jinja_utils.get_jinja_environment() self.jinja.tests['in'] = lambda item, list: item in list path = os.path.dirname(os.path.realpath(__file__)) with open(os.path.join(path, 'templates/default.j2'), 'r') as f: self.default_template = f.read()
def __init__(self, config=None, action_service=None): super(FormatResultAction, self).__init__(config=config, action_service=action_service) api_url = os.environ.get("ST2_ACTION_API_URL", None) token = os.environ.get("ST2_ACTION_AUTH_TOKEN", None) self.client = Client(api_url=api_url, token=token) self.jinja = jinja_utils.get_jinja_environment(allow_undefined=True) self.jinja.tests["in"] = lambda item, list: item in list path = os.path.dirname(os.path.realpath(__file__)) with open(os.path.join(path, "templates/default.j2"), "r") as f: self.default_template = f.read()
def test_to_human_time_filter(self): env = jinja_utils.get_jinja_environment() template = "{{k1 | to_human_time_from_seconds}}" actual = env.from_string(template).render({"k1": 12345}) self.assertEqual(actual, "3h25m45s") actual = env.from_string(template).render({"k1": 0}) self.assertEqual(actual, "0s") self.assertRaises(AssertionError, env.from_string(template).render, {"k1": "stuff"})
def test_dirname(self): env = jinja_utils.get_jinja_environment() template = '{{k1 | dirname}}' actual = env.from_string(template).render({'k1': '/some/path/to/file.txt'}) self.assertEqual(actual, '/some/path/to') actual = env.from_string(template).render({'k1': '/some/path/to/dir'}) self.assertEqual(actual, '/some/path/to') actual = env.from_string(template).render({'k1': '/some/path/to/dir/'}) self.assertEqual(actual, '/some/path/to/dir')
def test_to_human_time_filter(self): env = jinja_utils.get_jinja_environment() template = '{{k1 | to_human_time_from_seconds}}' actual = env.from_string(template).render({'k1': 12345}) self.assertEqual(actual, '3h25m45s') actual = env.from_string(template).render({'k1': 0}) self.assertEqual(actual, '0s') self.assertRaises(AssertionError, env.from_string(template).render, {'k1': 'stuff'})
def test_filters_regex_replace(self): env = jinja_utils.get_jinja_environment() template = '{{k1 | regex_replace("x", "y")}}' actual = env.from_string(template).render({'k1': 'xyz'}) expected = 'yyz' self.assertEqual(actual, expected) template = '{{k1 | regex_replace("(blue|white|red)", "color")}}' actual = env.from_string(template).render({'k1': 'blue socks and red shoes'}) expected = 'color socks and color shoes' self.assertEqual(actual, expected)
def test_filters_regex_replace(self): env = jinja_utils.get_jinja_environment() template = '{{k1 | regex_replace("x", "y")}}' actual = env.from_string(template).render({"k1": "xyz"}) expected = "yyz" self.assertEqual(actual, expected) template = '{{k1 | regex_replace("(blue|white|red)", "color")}}' actual = env.from_string(template).render({"k1": "blue socks and red shoes"}) expected = "color socks and color shoes" self.assertEqual(actual, expected)
def test_jsonpath_query_static(self): env = jinja_utils.get_jinja_environment() obj = {'people': [{'first': 'James', 'last': 'd'}, {'first': 'Jacob', 'last': 'e'}, {'first': 'Jayden', 'last': 'f'}, {'missing': 'different'}], 'foo': {'bar': 'baz'}} template = '{{ obj | jsonpath_query("people[*].first") }}' actual_str = env.from_string(template).render({'obj': obj}) actual = eval(actual_str) expected = ['James', 'Jacob', 'Jayden'] self.assertEqual(actual, expected)
def test_dirname(self): env = jinja_utils.get_jinja_environment() template = "{{k1 | dirname}}" actual = env.from_string(template).render( {"k1": "/some/path/to/file.txt"}) self.assertEqual(actual, "/some/path/to") actual = env.from_string(template).render({"k1": "/some/path/to/dir"}) self.assertEqual(actual, "/some/path/to") actual = env.from_string(template).render({"k1": "/some/path/to/dir/"}) self.assertEqual(actual, "/some/path/to/dir")
def test_filter_from_yaml_string(self): env = jinja_utils.get_jinja_environment() expected_obj = {"a": "b", "c": {"d": "e", "f": 1, "g": True}} obj_yaml_str = "---\n" "a: b\n" "c:\n" " d: e\n" " f: 1\n" " g: true\n" template = "{{k1 | from_yaml_string}}" obj_str = env.from_string(template).render({"k1": obj_yaml_str}) obj = eval(obj_str) self.assertDictEqual(obj, expected_obj) # With KeyValueLookup object env = jinja_utils.get_jinja_environment() obj_yaml_str = "---\n" "- a\n" "- b\n" "- c\n" expected_obj = ["a", "b", "c"] template = "{{ k1 | from_yaml_string }}" lookup = KeyValueLookup(scope=FULL_SYSTEM_SCOPE, key_prefix="b") lookup._value_cache["b"] = obj_yaml_str obj_str = env.from_string(template).render({"k1": lookup}) obj = eval(obj_str) self.assertEqual(obj, expected_obj)
def test_dirname(self): env = jinja_utils.get_jinja_environment() template = '{{k1 | dirname}}' actual = env.from_string(template).render( {'k1': '/some/path/to/file.txt'}) self.assertEqual(actual, '/some/path/to') actual = env.from_string(template).render({'k1': '/some/path/to/dir'}) self.assertEqual(actual, '/some/path/to') actual = env.from_string(template).render({'k1': '/some/path/to/dir/'}) self.assertEqual(actual, '/some/path/to/dir')
def test_filter_from_yaml_string(self): env = jinja_utils.get_jinja_environment() expected_obj = {'a': 'b', 'c': {'d': 'e', 'f': 1, 'g': True}} obj_yaml_str = ("---\n" "a: b\n" "c:\n" " d: e\n" " f: 1\n" " g: true\n") template = '{{k1 | from_yaml_string}}' obj_str = env.from_string(template).render({'k1': obj_yaml_str}) obj = eval(obj_str) self.assertDictEqual(obj, expected_obj)
def test_filter_from_json_string(self): env = jinja_utils.get_jinja_environment() expected_obj = {'a': 'b', 'c': {'d': 'e', 'f': 1, 'g': True}} obj_json_str = '{"a": "b", "c": {"d": "e", "f": 1, "g": true}}' template = '{{k1 | from_json_string}}' obj_str = env.from_string(template).render({'k1': obj_json_str}) obj = eval(obj_str) self.assertDictEqual(obj, expected_obj) # With KeyValueLookup object env = jinja_utils.get_jinja_environment() obj_json_str = '["a", "b", "c"]' expected_obj = ['a', 'b', 'c'] template = '{{ k1 | from_json_string}}' lookup = KeyValueLookup(scope=FULL_SYSTEM_SCOPE, key_prefix='a') lookup._value_cache['a'] = obj_json_str obj_str = env.from_string(template).render({'k1': lookup}) obj = eval(obj_str) self.assertEqual(obj, expected_obj)
def test_filter_from_json_string(self): env = jinja_utils.get_jinja_environment() expected_obj = {"a": "b", "c": {"d": "e", "f": 1, "g": True}} obj_json_str = '{"a": "b", "c": {"d": "e", "f": 1, "g": true}}' template = "{{k1 | from_json_string}}" obj_str = env.from_string(template).render({"k1": obj_json_str}) obj = eval(obj_str) self.assertDictEqual(obj, expected_obj) # With KeyValueLookup object env = jinja_utils.get_jinja_environment() obj_json_str = '["a", "b", "c"]' expected_obj = ["a", "b", "c"] template = "{{ k1 | from_json_string}}" lookup = KeyValueLookup(scope=FULL_SYSTEM_SCOPE, key_prefix="a") lookup._value_cache["a"] = obj_json_str obj_str = env.from_string(template).render({"k1": lookup}) obj = eval(obj_str) self.assertEqual(obj, expected_obj)
def test_jsonpath_query_no_results(self): env = jinja_utils.get_jinja_environment() obj = {'people': [{'first': 'James', 'last': 'd'}, {'first': 'Jacob', 'last': 'e'}, {'first': 'Jayden', 'last': 'f'}, {'missing': 'different'}], 'foo': {'bar': 'baz'}} query = "query_returns_no_results" template = '{{ obj | jsonpath_query(query) }}' actual_str = env.from_string(template).render({'obj': obj, 'query': query}) actual = eval(actual_str) expected = None self.assertEqual(actual, expected)
def test_filters_regex_match(self): env = jinja_utils.get_jinja_environment() template = '{{k1 | regex_match("x")}}' actual = env.from_string(template).render({'k1': 'xyz'}) expected = 'True' self.assertEqual(actual, expected) template = '{{k1 | regex_match("y")}}' actual = env.from_string(template).render({'k1': 'xyz'}) expected = 'False' self.assertEqual(actual, expected) template = '{{k1 | regex_match("^v(\\d+\\.)?(\\d+\\.)?(\\*|\\d+)$")}}' actual = env.from_string(template).render({'k1': 'v0.10.1'}) expected = 'True' self.assertEqual(actual, expected)
def test_version_compare(self): env = jinja_utils.get_jinja_environment() template = '{{version | version_compare("0.10.0")}}' actual = env.from_string(template).render({'version': '0.9.0'}) expected = '-1' self.assertEqual(actual, expected) template = '{{version | version_compare("0.10.0")}}' actual = env.from_string(template).render({'version': '0.10.1'}) expected = '1' self.assertEqual(actual, expected) template = '{{version | version_compare("0.10.0")}}' actual = env.from_string(template).render({'version': '0.10.0'}) expected = '0' self.assertEqual(actual, expected)
def test_filters_regex_search(self): env = jinja_utils.get_jinja_environment() template = '{{k1 | regex_search("x")}}' actual = env.from_string(template).render({"k1": "xyz"}) expected = "True" self.assertEqual(actual, expected) template = '{{k1 | regex_search("y")}}' actual = env.from_string(template).render({"k1": "xyz"}) expected = "True" self.assertEqual(actual, expected) template = '{{k1 | regex_search("^v(\\d+\\.)?(\\d+\\.)?(\\*|\\d+)$")}}' actual = env.from_string(template).render({"k1": "v0.10.1"}) expected = "True" self.assertEqual(actual, expected)
def test_filters_regex_search(self): env = jinja_utils.get_jinja_environment() template = '{{k1 | regex_search("x")}}' actual = env.from_string(template).render({'k1': 'xyz'}) expected = 'True' self.assertEqual(actual, expected) template = '{{k1 | regex_search("y")}}' actual = env.from_string(template).render({'k1': 'xyz'}) expected = 'True' self.assertEqual(actual, expected) template = '{{k1 | regex_search("^v(\\d+\\.)?(\\d+\\.)?(\\*|\\d+)$")}}' actual = env.from_string(template).render({'k1': 'v0.10.1'}) expected = 'True' self.assertEqual(actual, expected)
def test_version_compare(self): env = jinja_utils.get_jinja_environment() template = '{{version | version_compare("0.10.0")}}' actual = env.from_string(template).render({"version": "0.9.0"}) expected = "-1" self.assertEqual(actual, expected) template = '{{version | version_compare("0.10.0")}}' actual = env.from_string(template).render({"version": "0.10.1"}) expected = "1" self.assertEqual(actual, expected) template = '{{version | version_compare("0.10.0")}}' actual = env.from_string(template).render({"version": "0.10.0"}) expected = "0" self.assertEqual(actual, expected)
def render_template(value, context=None): """ Render provided template with the provided context. :param value: Template string. :type value: ``str`` :param context: Template context. :type context: ``dict`` """ assert isinstance(value, six.string_types) context = context or {} env = get_jinja_environment(allow_undefined=False) # nosec template = env.from_string(value) rendered = template.render(context) return rendered
def test_filter_decrypt_kv(self): secret = 'Build a wall' crypto_key_path = cfg.CONF.keyvalue.encryption_key_path crypto_key = read_crypto_key(key_path=crypto_key_path) secret_value = symmetric_encrypt(encrypt_key=crypto_key, plaintext=secret) KeyValuePair.add_or_update(KeyValuePairDB(name='k8', value=secret_value, scope=FULL_SYSTEM_SCOPE, secret=True)) env = jinja_utils.get_jinja_environment() context = {} context.update({SYSTEM_SCOPE: KeyValueLookup(scope=SYSTEM_SCOPE)}) context.update({ DATASTORE_PARENT_SCOPE: { SYSTEM_SCOPE: KeyValueLookup(scope=FULL_SYSTEM_SCOPE) } }) template = '{{st2kv.system.k8 | decrypt_kv}}' actual = env.from_string(template).render(context) self.assertEqual(actual, secret)
def render_template(value, context=None): """ Render provided template with the provided context. :param value: Template string. :type value: ``str`` :param context: Template context. :type context: ``dict`` """ if not isinstance(value, six.string_types): raise TypeError( f"The template value needs to be of type string (was {type(value)})." ) context = context or {} env = get_jinja_environment(allow_undefined=False) # nosec template = env.from_string(value) rendered = template.render(context) return rendered
def test_filter_decrypt_kv(self): secret = 'Build a wall' crypto_key_path = cfg.CONF.keyvalue.encryption_key_path crypto_key = read_crypto_key(key_path=crypto_key_path) secret_value = symmetric_encrypt(encrypt_key=crypto_key, plaintext=secret) KeyValuePair.add_or_update( KeyValuePairDB(name='k8', value=secret_value, scope=FULL_SYSTEM_SCOPE, secret=True)) env = jinja_utils.get_jinja_environment() context = {} context.update({SYSTEM_SCOPE: KeyValueLookup(scope=SYSTEM_SCOPE)}) context.update({ DATASTORE_PARENT_SCOPE: { SYSTEM_SCOPE: KeyValueLookup(scope=FULL_SYSTEM_SCOPE) } }) template = '{{st2kv.system.k8 | decrypt_kv}}' actual = env.from_string(template).render(context) self.assertEqual(actual, secret)
import six import networkx as nx from jinja2 import meta from st2common import log as logging from st2common.constants.action import ACTION_CONTEXT_KV_PREFIX from st2common.constants.keyvalue import SYSTEM_SCOPE from st2common.exceptions.param import ParamException from st2common.services.keyvalues import KeyValueLookup from st2common.util.casts import get_cast from st2common.util.compat import to_unicode from st2common.util import jinja as jinja_utils LOG = logging.getLogger(__name__) ENV = jinja_utils.get_jinja_environment() __all__ = [ 'render_live_params', 'render_final_params', ] def _split_params(runner_parameters, action_parameters, mixed_params): def pf(params, skips): result = {k: v for k, v in six.iteritems(mixed_params) if k in params and k not in skips} return result return (pf(runner_parameters, {}), pf(action_parameters, runner_parameters))
def test_tab(self): env = jinja_utils.get_jinja_environment() template = '{{ test_str | json_escape }}' actual = env.from_string(template).render({'test_str': 'foo \t bar'}) expected = 'foo \\t bar' self.assertEqual(actual, expected)