mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
requested changes
This commit is contained in:
parent
2276018cd5
commit
e75b8fef09
3 changed files with 71 additions and 86 deletions
|
@ -35,9 +35,9 @@ def template_dir(tmp_path):
|
|||
@pytest.fixture
|
||||
def hello_import(macro_template, template_dir):
|
||||
contents = """{% from 'macro' import mymacro -%}
|
||||
{% from 'macro' import mymacro -%}
|
||||
{{ mymacro('Hey') ~ mymacro(a|default('a'), b|default('b')) }}
|
||||
"""
|
||||
{% from 'macro' import mymacro -%}
|
||||
{{ mymacro('Hey') ~ mymacro(a|default('a'), b|default('b')) }}
|
||||
"""
|
||||
|
||||
with pytest.helpers.temp_file(
|
||||
"hello_import", directory=template_dir, contents=contents
|
||||
|
@ -48,10 +48,10 @@ def hello_import(macro_template, template_dir):
|
|||
@pytest.fixture
|
||||
def macro_template(template_dir):
|
||||
contents = """# macro
|
||||
{% macro mymacro(greeting, greetee='world') -%}
|
||||
{{ greeting ~ ' ' ~ greetee }} !
|
||||
{%- endmacro %}
|
||||
"""
|
||||
{% macro mymacro(greeting, greetee='world') -%}
|
||||
{{ greeting ~ ' ' ~ greetee }} !
|
||||
{%- endmacro %}
|
||||
"""
|
||||
|
||||
with pytest.helpers.temp_file(
|
||||
"macro", directory=template_dir, contents=contents
|
||||
|
|
|
@ -203,7 +203,7 @@ def test_load_tag():
|
|||
def test_load_json():
|
||||
env = Environment(extensions=[SerializerExtension])
|
||||
rendered = env.from_string(
|
||||
'{% set document = \'{"foo": "it works"}\'|load_json %}{{ document.foo }}'
|
||||
"""{% set document = '{"foo": "it works"}'|load_json %}{{ document.foo }}"""
|
||||
).render()
|
||||
assert rendered == "it works"
|
||||
|
||||
|
@ -259,9 +259,9 @@ def test_profile():
|
|||
|
||||
source = (
|
||||
"{%- profile as 'profile test' %}"
|
||||
+ "{% set var = 'val' %}"
|
||||
+ "{%- endprofile %}"
|
||||
+ "{{ var }}"
|
||||
"{% set var = 'val' %}"
|
||||
"{%- endprofile %}"
|
||||
"{{ var }}"
|
||||
)
|
||||
|
||||
rendered = env.from_string(source).render()
|
||||
|
@ -750,7 +750,8 @@ def test_network_size(minion_opts, local_salt):
|
|||
|
||||
|
||||
@pytest.mark.requires_network
|
||||
def test_http_query(minion_opts, local_salt):
|
||||
@pytest.mark.parametrize("backend", ["requests", "tornado", "urllib2"])
|
||||
def test_http_query(minion_opts, local_salt, backend):
|
||||
"""
|
||||
Test the `http_query` Jinja filter.
|
||||
"""
|
||||
|
@ -760,30 +761,25 @@ def test_http_query(minion_opts, local_salt):
|
|||
"http://google.com",
|
||||
"http://duckduckgo.com",
|
||||
)
|
||||
for backend in ("requests", "tornado", "urllib2"):
|
||||
rendered = render_jinja_tmpl(
|
||||
"{{ '"
|
||||
+ random.choice(urls)
|
||||
+ "' | http_query(backend='"
|
||||
+ backend
|
||||
+ "') }}",
|
||||
dict(opts=minion_opts, saltenv="test", salt=local_salt),
|
||||
)
|
||||
assert isinstance(rendered, str), "Failed with rendered template: {}".format(
|
||||
rendered
|
||||
)
|
||||
dict_reply = ast.literal_eval(rendered)
|
||||
assert isinstance(dict_reply, dict), "Failed with rendered template: {}".format(
|
||||
rendered
|
||||
)
|
||||
assert (
|
||||
"body" in dict_reply
|
||||
), "'body' not found in request response({}). Rendered template: {!r}".format(
|
||||
dict_reply, rendered
|
||||
)
|
||||
assert isinstance(
|
||||
dict_reply["body"], str
|
||||
), "Failed with rendered template: {}".format(rendered)
|
||||
rendered = render_jinja_tmpl(
|
||||
"{{ '" + random.choice(urls) + "' | http_query(backend='" + backend + "') }}",
|
||||
dict(opts=minion_opts, saltenv="test", salt=local_salt),
|
||||
)
|
||||
assert isinstance(rendered, str), "Failed with rendered template: {}".format(
|
||||
rendered
|
||||
)
|
||||
dict_reply = ast.literal_eval(rendered)
|
||||
assert isinstance(dict_reply, dict), "Failed with rendered template: {}".format(
|
||||
rendered
|
||||
)
|
||||
assert (
|
||||
"body" in dict_reply
|
||||
), "'body' not found in request response({}). Rendered template: {!r}".format(
|
||||
dict_reply, rendered
|
||||
)
|
||||
assert isinstance(
|
||||
dict_reply["body"], str
|
||||
), "Failed with rendered template: {}".format(rendered)
|
||||
|
||||
|
||||
def test_to_bool(minion_opts, local_salt):
|
||||
|
@ -1074,15 +1070,3 @@ def test_json_query(minion_opts, local_salt):
|
|||
dict(opts=minion_opts, saltenv="test", salt=local_salt),
|
||||
)
|
||||
assert rendered == "2"
|
||||
|
||||
|
||||
# def test_print():
|
||||
# env = Environment(extensions=[SerializerExtension])
|
||||
# source = '{% import_yaml "toto.foo" as docu %}'
|
||||
# name, filename = None, '<filename>'
|
||||
# parsed = env._parse(source, name, filename)
|
||||
# print parsed
|
||||
# print
|
||||
# compiled = env._generate(parsed, name, filename)
|
||||
# print compiled
|
||||
# return
|
||||
|
|
|
@ -325,53 +325,54 @@ def test_non_ascii_encoding(
|
|||
@pytest.mark.skipif(
|
||||
HAS_TIMELIB is False, reason="The `timelib` library is not installed."
|
||||
)
|
||||
def test_strftime(minion_opts, local_salt):
|
||||
@pytest.mark.parametrize(
|
||||
"data_object",
|
||||
[
|
||||
datetime.datetime(2002, 12, 25, 12, 00, 00, 00),
|
||||
"2002/12/25",
|
||||
1040814000,
|
||||
"1040814000",
|
||||
],
|
||||
)
|
||||
def test_strftime(minion_opts, local_salt, data_object):
|
||||
response = render_jinja_tmpl(
|
||||
'{{ "2002/12/25"|strftime }}',
|
||||
dict(opts=minion_opts, saltenv="test", salt=local_salt),
|
||||
)
|
||||
assert response == "2002-12-25"
|
||||
|
||||
objects = (
|
||||
datetime.datetime(2002, 12, 25, 12, 00, 00, 00),
|
||||
"2002/12/25",
|
||||
1040814000,
|
||||
"1040814000",
|
||||
response = render_jinja_tmpl(
|
||||
"{{ object|strftime }}",
|
||||
dict(
|
||||
object=data_object,
|
||||
opts=minion_opts,
|
||||
saltenv="test",
|
||||
salt=local_salt,
|
||||
),
|
||||
)
|
||||
assert response == "2002-12-25"
|
||||
|
||||
for object in objects:
|
||||
response = render_jinja_tmpl(
|
||||
"{{ object|strftime }}",
|
||||
dict(
|
||||
object=object,
|
||||
opts=minion_opts,
|
||||
saltenv="test",
|
||||
salt=local_salt,
|
||||
),
|
||||
)
|
||||
assert response == "2002-12-25"
|
||||
response = render_jinja_tmpl(
|
||||
'{{ object|strftime("%b %d, %Y") }}',
|
||||
dict(
|
||||
object=data_object,
|
||||
opts=minion_opts,
|
||||
saltenv="test",
|
||||
salt=local_salt,
|
||||
),
|
||||
)
|
||||
assert response == "Dec 25, 2002"
|
||||
|
||||
response = render_jinja_tmpl(
|
||||
'{{ object|strftime("%b %d, %Y") }}',
|
||||
dict(
|
||||
object=object,
|
||||
opts=minion_opts,
|
||||
saltenv="test",
|
||||
salt=local_salt,
|
||||
),
|
||||
)
|
||||
assert response == "Dec 25, 2002"
|
||||
|
||||
response = render_jinja_tmpl(
|
||||
'{{ object|strftime("%y") }}',
|
||||
dict(
|
||||
object=object,
|
||||
opts=minion_opts,
|
||||
saltenv="test",
|
||||
salt=local_salt,
|
||||
),
|
||||
)
|
||||
assert response == "02"
|
||||
response = render_jinja_tmpl(
|
||||
'{{ object|strftime("%y") }}',
|
||||
dict(
|
||||
object=data_object,
|
||||
opts=minion_opts,
|
||||
saltenv="test",
|
||||
salt=local_salt,
|
||||
),
|
||||
)
|
||||
assert response == "02"
|
||||
|
||||
|
||||
def test_non_ascii(minion_opts, local_salt, non_ascii):
|
||||
|
|
Loading…
Add table
Reference in a new issue