Skip to content
This repository has been archived by the owner on Sep 15, 2020. It is now read-only.

Commit

Permalink
to_complex improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Oswalt <oswaltm@brocade.com>
  • Loading branch information
Matt Oswalt committed Jul 29, 2017
1 parent 3efc840 commit a164d6c
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 61 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -16,7 +16,7 @@ mistral.expression.functions =
regex_search = st2mistral.functions.regex:regex_search
regex_substring = st2mistral.functions.regex:regex_substring
st2kv = st2mistral.functions.stackstorm:st2kv_
to_complex = st2mistral.functions.complex_type:to_complex
to_complex = st2mistral.functions.data:to_complex
to_human_time_from_seconds = st2mistral.functions.time:to_human_time_from_seconds
to_json_string = st2mistral.functions.data:to_json_string
to_yaml_string = st2mistral.functions.data:to_yaml_string
Expand Down
26 changes: 0 additions & 26 deletions st2mistral/functions/complex_type.py

This file was deleted.

7 changes: 6 additions & 1 deletion st2mistral/functions/data.py
Expand Up @@ -17,11 +17,16 @@
import yaml

__all__ = [
'to_complex',
'to_json_string',
'to_yaml_string',
'to_yaml_string'
]


def to_complex(value):
return json.dumps(value)


def to_json_string(value, indent=4, sort_keys=False, separators=(',', ':')):
return json.dumps(value, indent=indent, separators=separators,
sort_keys=sort_keys)
Expand Down
3 changes: 1 addition & 2 deletions st2mistral/tests/unit/test_function_base.py
Expand Up @@ -20,7 +20,6 @@


def get_functions():
from st2mistral.functions import complex_type
from st2mistral.functions import data
from st2mistral.functions import json_escape
from st2mistral.functions import regex
Expand All @@ -34,7 +33,7 @@ def get_functions():
'regex_replace': regex.regex_replace,
'regex_search': regex.regex_search,
'regex_substring': regex.regex_substring,
'to_complex': complex_type.to_complex,
'to_complex': data.to_complex,
'to_human_time_from_seconds': time.to_human_time_from_seconds,
'to_json_string': data.to_json_string,
'to_yaml_string': data.to_yaml_string,
Expand Down
31 changes: 0 additions & 31 deletions st2mistral/tests/unit/test_jinja_render_complex.py

This file was deleted.

10 changes: 10 additions & 0 deletions st2mistral/tests/unit/test_jinja_render_data.py
Expand Up @@ -21,6 +21,16 @@

class JinjaUtilsDataFunctionTestCase(base.JinjaFunctionTestCase):

def test_function_to_complex(self):
env = self.get_jinja_environment()
obj = {'a': 'b', 'c': {'d': 'e', 'f': 1, 'g': True}}

template = '{{k1 | to_complex}}'

obj_json_str = env.from_string(template).render({'k1': obj})
actual_obj = json.loads(obj_json_str)
self.assertDictEqual(obj, actual_obj)

def test_function_to_json_string(self):
env = self.get_jinja_environment()
obj = {'a': 'b', 'c': {'d': 'e', 'f': 1, 'g': True}}
Expand Down

0 comments on commit a164d6c

Please sign in to comment.