Merge pull request #58351 from s0undt3ch/hotfix/bad-tests-1

Don't use the same service, we might get throttled and the test fails.
This commit is contained in:
Pedro Algarvio 2020-09-01 16:40:25 +01:00 committed by GitHub
commit a53bac0a6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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"
),
)