mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Don't use the same service, we might get throttled and the test fails.
This commit is contained in:
parent
aff1ce6e37
commit
d495d2c61e
1 changed files with 33 additions and 19 deletions
|
@ -1,14 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Tests for salt.utils.jinja
|
||||
"""
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import ast
|
||||
import builtins
|
||||
import copy
|
||||
import datetime
|
||||
import os
|
||||
import pprint
|
||||
import random
|
||||
import re
|
||||
import tempfile
|
||||
|
||||
|
@ -23,8 +23,6 @@ import salt.utils.stringutils
|
|||
import salt.utils.yaml
|
||||
from jinja2 import DictLoader, Environment, Markup, exceptions
|
||||
from salt.exceptions import SaltRenderError
|
||||
from salt.ext import six
|
||||
from salt.ext.six.moves import builtins
|
||||
from salt.utils.decorators.jinja import JinjaFilter
|
||||
from salt.utils.jinja import (
|
||||
SaltCacheLoader,
|
||||
|
@ -77,7 +75,7 @@ class JinjaTestCase(TestCase):
|
|||
assert result == expected, result
|
||||
|
||||
|
||||
class MockFileClient(object):
|
||||
class MockFileClient:
|
||||
"""
|
||||
Does not download files but records any file request for testing
|
||||
"""
|
||||
|
@ -129,7 +127,7 @@ class TestSaltCacheLoader(TestCase):
|
|||
os.path.dirname(os.path.abspath(__file__)), "extmods"
|
||||
),
|
||||
}
|
||||
super(TestSaltCacheLoader, self).setUp()
|
||||
super().setUp()
|
||||
|
||||
def tearDown(self):
|
||||
salt.utils.files.rm_rf(self.tempdir)
|
||||
|
@ -154,7 +152,7 @@ class TestSaltCacheLoader(TestCase):
|
|||
res = loader.get_source(None, "hello_simple")
|
||||
assert len(res) == 3
|
||||
# res[0] on Windows is unicode and use os.linesep so it works cross OS
|
||||
self.assertEqual(six.text_type(res[0]), "world" + os.linesep)
|
||||
self.assertEqual(str(res[0]), "world" + os.linesep)
|
||||
tmpl_dir = os.path.join(self.template_dir, "hello_simple")
|
||||
self.assertEqual(res[1], tmpl_dir)
|
||||
assert res[2](), "Template up to date?"
|
||||
|
@ -287,7 +285,7 @@ class TestGetTemplate(TestCase):
|
|||
),
|
||||
}
|
||||
self.local_salt = {}
|
||||
super(TestGetTemplate, self).setUp()
|
||||
super().setUp()
|
||||
|
||||
def tearDown(self):
|
||||
salt.utils.files.rm_rf(self.tempdir)
|
||||
|
@ -1116,7 +1114,7 @@ class TestCustomExtensions(TestCase):
|
|||
self.assertEqual(rendered, "2")
|
||||
|
||||
rendered = env.from_string("{{ data | sequence | length }}").render(
|
||||
data=set(["foo", "bar"])
|
||||
data={"foo", "bar"}
|
||||
)
|
||||
self.assertEqual(rendered, "2")
|
||||
|
||||
|
@ -1374,22 +1372,40 @@ class TestCustomExtensions(TestCase):
|
|||
"""
|
||||
Test the `http_query` Jinja filter.
|
||||
"""
|
||||
urls = (
|
||||
# These cannot be HTTPS urls since urllib2 chokes on those
|
||||
"http://saltstack.com",
|
||||
"http://community.saltstack.com",
|
||||
"http://google.com",
|
||||
"http://duckduckgo.com",
|
||||
)
|
||||
for backend in ("requests", "tornado", "urllib2"):
|
||||
rendered = render_jinja_tmpl(
|
||||
"{{ 'http://icanhazip.com' | http_query(backend='" + backend + "') }}",
|
||||
"{{ '"
|
||||
+ random.choice(urls)
|
||||
+ "' | http_query(backend='"
|
||||
+ backend
|
||||
+ "') }}",
|
||||
dict(opts=self.local_opts, saltenv="test", salt=self.local_salt),
|
||||
)
|
||||
self.assertIsInstance(
|
||||
rendered, six.text_type, "Failed with backend: {}".format(backend)
|
||||
rendered, str, "Failed with rendered template: {}".format(rendered)
|
||||
)
|
||||
dict_reply = ast.literal_eval(rendered)
|
||||
self.assertIsInstance(
|
||||
dict_reply, dict, "Failed with backend: {}".format(backend)
|
||||
dict_reply, dict, "Failed with rendered template: {}".format(rendered)
|
||||
)
|
||||
self.assertIn(
|
||||
"body",
|
||||
dict_reply,
|
||||
"'body' not found in request response({}). Rendered template: {!r}".format(
|
||||
dict_reply, rendered
|
||||
),
|
||||
)
|
||||
self.assertIsInstance(
|
||||
dict_reply["body"],
|
||||
six.string_types,
|
||||
"Failed with backend: {}".format(backend),
|
||||
str,
|
||||
"Failed with rendered template: {}".format(rendered),
|
||||
)
|
||||
|
||||
def test_to_bool(self):
|
||||
|
@ -1613,11 +1629,9 @@ class TestCustomExtensions(TestCase):
|
|||
)
|
||||
self.assertEqual(
|
||||
rendered,
|
||||
six.text_type(
|
||||
(
|
||||
"811a90e1c8e86c7b4c0eef5b2c0bf0ec1b19c4b1b5a242e6455be93787cb473cb7bc"
|
||||
"9b0fdeb960d00d5c6881c2094dd63c5c900ce9057255e2a4e271fc25fef1"
|
||||
)
|
||||
str(
|
||||
"811a90e1c8e86c7b4c0eef5b2c0bf0ec1b19c4b1b5a242e6455be93787cb473cb7bc"
|
||||
"9b0fdeb960d00d5c6881c2094dd63c5c900ce9057255e2a4e271fc25fef1"
|
||||
),
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue