Fix issue with tests failing due to previous tests

This commit is contained in:
Eliise 2021-08-24 18:10:45 +00:00
Родитель 1437f7c6ef
Коммит 424e1c142e
2 изменённых файлов: 11 добавлений и 8 удалений

Просмотреть файл

@ -358,12 +358,12 @@ def test_validate_deployment_template_and_manifest_failed():
os.remove(os.path.join(tests_assets_dir, env_file_name))
@mock.patch.dict(os.environ, {"CONTAINER_REGISTRY_PASSWORD": "nonempty"})
def test_validate_deployment_template_and_manifest_success():
try:
deployment_file_name = "deployment.template.json"
os.chdir(test_solution_shared_lib_dir)
shutil.copyfile(env_file_path, os.path.join(test_solution_shared_lib_dir, env_file_name))
os.environ["CONTAINER_REGISTRY_PASSWORD"] = "nonempty"
if get_docker_os_type() == "windows":
result = runner_invoke(['genconfig', '-P', get_platform_type(), '-f', deployment_file_name])
@ -422,9 +422,9 @@ def test_fail_gen_config_on_validation_error(deployment_file_name):
assert "ERROR" not in result.output
@mock.patch.dict(os.environ, {"TTL": "7200"})
def test_gen_config_with_non_string_placeholder():
os.chdir(tests_assets_dir)
os.environ["TTL"] = "7200"
deployment_file_name = "deployment.template.non_str_placeholder.json"
if get_docker_os_type() == "windows":
result = runner_invoke(['genconfig', '-P', get_platform_type(), '-f', deployment_file_name, '--fail-on-validation-error'])

Просмотреть файл

@ -1,12 +1,13 @@
import os
from unittest import mock
import pytest
from iotedgedev.envvars import EnvVars
from iotedgedev.output import Output
from iotedgedev.utility import Utility
from .utility import assert_list_equal, assert_file_equal, assert_json_file_equal
from .utility import (assert_file_equal, assert_json_file_equal,
assert_list_equal)
pytestmark = pytest.mark.unit
@ -59,12 +60,12 @@ def test_copy_template(utility, tmpdir):
assert_json_file_equal(test_file_2, dest)
@mock.patch.dict(os.environ, {"CONTAINER_REGISTRY_SERVER": "localhost:5000"})
def test_copy_template_expandvars(utility, tmpdir):
replacements = {
"${MODULES.csharpmodule.amd64}": "${CONTAINER_REGISTRY_SERVER}/csharpmodule:0.0.1-amd64",
"${MODULES.csharpfunction.amd64.debug}": "${CONTAINER_REGISTRY_SERVER}/csharpfunction:0.0.1-amd64.debug"
}
os.environ["CONTAINER_REGISTRY_SERVER"] = "localhost:5000"
dest = tmpdir.join("deployment_template_2.dest.json").strpath
dest2 = tmpdir.join("deployment_template_2.dest2.json").strpath
utility.copy_template(test_file_1, dest, replacements=replacements, expandvars=True)
@ -116,6 +117,11 @@ def test_get_sha256_hash():
assert Utility.get_sha256_hash("foo") == "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"
@mock.patch.dict(os.environ, {"DEPLOYMENT_CONFIG_FILE": "foo.json"})
def test_get_deployment_manifest_name__set_from_envvar():
assert Utility.get_deployment_manifest_name("deployment.debug.template.json", "1.0.0", "amd64") == "foo.json"
def test_get_deployment_manifest_name():
assert Utility.get_deployment_manifest_name("config/deployment.template.json", "0.0.1", "amd64") == "deployment.json"
assert Utility.get_deployment_manifest_name("deployment.template.json", "0.0.1", "amd64") == "deployment.json"
@ -124,6 +130,3 @@ def test_get_deployment_manifest_name():
assert Utility.get_deployment_manifest_name("deployment.template.json", "1.0.0", "amd64") == "deployment.amd64.json"
assert Utility.get_deployment_manifest_name("deployment.debug.template.json", "1.0.0", "amd64") == "deployment.debug.amd64.json"
assert Utility.get_deployment_manifest_name("", "", "") == "deployment.json"
os.environ["DEPLOYMENT_CONFIG_FILE"] = "foo.json"
assert Utility.get_deployment_manifest_name("deployment.debug.template.json", "1.0.0", "amd64") == "foo.json"