From 424e1c142e66d84d59798f1ad442a875985cf99f Mon Sep 17 00:00:00 2001 From: Eliise Date: Tue, 24 Aug 2021 18:10:45 +0000 Subject: [PATCH] Fix issue with tests failing due to previous tests --- tests/test_iotedgedev_solution.py | 4 ++-- tests/test_utility.py | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/test_iotedgedev_solution.py b/tests/test_iotedgedev_solution.py index 3ac321c..bba2f13 100644 --- a/tests/test_iotedgedev_solution.py +++ b/tests/test_iotedgedev_solution.py @@ -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']) diff --git a/tests/test_utility.py b/tests/test_utility.py index 00dadfb..2ab6156 100644 --- a/tests/test_utility.py +++ b/tests/test_utility.py @@ -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"