From 75b87d6d2f2f4e2d71265828f69d640702231873 Mon Sep 17 00:00:00 2001 From: Steven Murawski Date: Wed, 1 Jun 2022 17:29:33 +0000 Subject: [PATCH] update tests to pre-install the az containerapp extension --- .../tests/latest/common.py | 26 ++++++++ .../latest/test_containerapp_preview_basic.py | 21 +++--- .../test_containerapp_preview_command.py | 37 +++++------ .../test_containerapp_preview_environment.py | 31 ++++----- .../test_containerapp_preview_ingress.py | 51 +++++++-------- .../test_containerapp_preview_registries.py | 31 ++++----- .../test_containerapp_preview_resources.py | 37 +++++------ .../latest/test_containerapp_preview_scale.py | 29 ++++----- .../test_containerapp_preview_secrets.py | 64 ++++++++----------- ...ontainerapp_preview_transport_overrides.py | 21 +++--- src/containerapp-compose/setup.py | 2 +- 11 files changed, 167 insertions(+), 183 deletions(-) create mode 100644 src/containerapp-compose/azext_containerapp_compose/tests/latest/common.py diff --git a/src/containerapp-compose/azext_containerapp_compose/tests/latest/common.py b/src/containerapp-compose/azext_containerapp_compose/tests/latest/common.py new file mode 100644 index 00000000000..2a4a05e4207 --- /dev/null +++ b/src/containerapp-compose/azext_containerapp_compose/tests/latest/common.py @@ -0,0 +1,26 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +import os +from azure.cli.testsdk import (ScenarioTest) + +TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) + + +def write_test_file(filename, content): + test_file = open(filename, "w", encoding='utf-8') + _ = test_file.write(content) + test_file.close() + + +def clean_up_test_file(filename): + if os.path.exists(filename): + os.remove(filename) + + +class ContainerappComposePreviewScenarioTest(ScenarioTest): + def setUp(self): + self.cmd("extension add --name containerapp") + return super().setUp() diff --git a/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_basic.py b/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_basic.py index 63615f4bed8..9f7737abe8b 100644 --- a/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_basic.py +++ b/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_basic.py @@ -3,17 +3,19 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -import os import unittest # pylint: disable=unused-import -from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer) +from azure.cli.testsdk import (ResourceGroupPreparer) +from azure.cli.testsdk.decorators import serial_test +from azext_containerapp_compose.tests.latest.common import (ContainerappComposePreviewScenarioTest, # pylint: disable=unused-import + write_test_file, + clean_up_test_file, + TEST_DIR) -TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) - - -class ContainerappComposePreviewScenarioTest(ScenarioTest): +class ContainerappComposeBaseScenarioTest(ContainerappComposePreviewScenarioTest): + @serial_test() @ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus') def test_containerapp_compose_create_basic_no_existing_resources(self, resource_group): compose_text = """ @@ -22,9 +24,7 @@ def test_containerapp_compose_create_basic_no_existing_resources(self, resource_ image: smurawski/printenv:latest """ compose_file_name = f"{self._testMethodName}_compose.yml" - docker_compose_file = open(compose_file_name, "w", encoding='utf-8') - _ = docker_compose_file.write(compose_text) - docker_compose_file.close() + write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), @@ -42,5 +42,4 @@ def test_containerapp_compose_create_basic_no_existing_resources(self, resource_ self.check('[] | length(@)', 1), ]) - if os.path.exists(compose_file_name): - os.remove(compose_file_name) + clean_up_test_file(compose_file_name) diff --git a/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_command.py b/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_command.py index 4a913d69e35..30392dd9603 100644 --- a/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_command.py +++ b/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_command.py @@ -3,16 +3,18 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -import os import unittest # pylint: disable=unused-import -from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer) +from azure.cli.testsdk import (ResourceGroupPreparer) +from azure.cli.testsdk.decorators import serial_test +from azext_containerapp_compose.tests.latest.common import (ContainerappComposePreviewScenarioTest, # pylint: disable=unused-import + write_test_file, + clean_up_test_file, + TEST_DIR) -TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) - - -class ContainerappComposePreviewCommandScenarioTest(ScenarioTest): +class ContainerappComposePreviewCommandScenarioTest(ContainerappComposePreviewScenarioTest): + @serial_test() @ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus') def test_containerapp_compose_with_command_string(self, resource_group): compose_text = """ @@ -24,9 +26,7 @@ def test_containerapp_compose_with_command_string(self, resource_group): - "5000" """ compose_file_name = f"{self._testMethodName}_compose.yml" - docker_compose_file = open(compose_file_name, "w", encoding='utf-8') - _ = docker_compose_file.write(compose_text) - docker_compose_file.close() + write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), @@ -43,9 +43,9 @@ def test_containerapp_compose_with_command_string(self, resource_group): self.check('[?name==`foo`].properties.template.containers[0].command[0]', "['echo \"hello world\"']"), ]) - if os.path.exists(compose_file_name): - os.remove(compose_file_name) + clean_up_test_file(compose_file_name) + @serial_test() @ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus') def test_containerapp_compose_with_command_list(self, resource_group): compose_text = """ @@ -57,9 +57,7 @@ def test_containerapp_compose_with_command_list(self, resource_group): - "5000" """ compose_file_name = f"{self._testMethodName}_compose.yml" - docker_compose_file = open(compose_file_name, "w", encoding='utf-8') - _ = docker_compose_file.write(compose_text) - docker_compose_file.close() + write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), @@ -76,9 +74,9 @@ def test_containerapp_compose_with_command_list(self, resource_group): self.check('[?name==`foo`].properties.template.containers[0].command[0]', "['echo \"hello world\"']"), ]) - if os.path.exists(compose_file_name): - os.remove(compose_file_name) + clean_up_test_file(compose_file_name) + @serial_test() @ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus') def test_containerapp_compose_with_command_list_and_entrypoint(self, resource_group): compose_text = """ @@ -91,9 +89,7 @@ def test_containerapp_compose_with_command_list_and_entrypoint(self, resource_gr - "5000" """ compose_file_name = f"{self._testMethodName}_compose.yml" - docker_compose_file = open(compose_file_name, "w", encoding='utf-8') - _ = docker_compose_file.write(compose_text) - docker_compose_file.close() + write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), @@ -111,5 +107,4 @@ def test_containerapp_compose_with_command_list_and_entrypoint(self, resource_gr self.check('[?name==`foo`].properties.template.containers[0].args[0]', "['echo \"hello world\"']"), ]) - if os.path.exists(compose_file_name): - os.remove(compose_file_name) + clean_up_test_file(compose_file_name) diff --git a/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_environment.py b/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_environment.py index 569c8348821..6ce64accc3a 100644 --- a/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_environment.py +++ b/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_environment.py @@ -3,16 +3,18 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -import os import unittest # pylint: disable=unused-import -from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer) +from azure.cli.testsdk import (ResourceGroupPreparer) +from azure.cli.testsdk.decorators import serial_test +from azext_containerapp_compose.tests.latest.common import (ContainerappComposePreviewScenarioTest, # pylint: disable=unused-import + write_test_file, + clean_up_test_file, + TEST_DIR) -TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) - - -class ContainerappComposePreviewEnvironmentSettingsScenarioTest(ScenarioTest): +class ContainerappComposePreviewEnvironmentSettingsScenarioTest(ContainerappComposePreviewScenarioTest): + @serial_test() @ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus') def test_containerapp_compose_create_with_environment(self, resource_group): compose_text = """ @@ -25,9 +27,7 @@ def test_containerapp_compose_create_with_environment(self, resource_group): - BAZ="snafu" """ compose_file_name = f"{self._testMethodName}_compose.yml" - docker_compose_file = open(compose_file_name, "w", encoding='utf-8') - _ = docker_compose_file.write(compose_text) - docker_compose_file.close() + write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), @@ -49,11 +49,11 @@ def test_containerapp_compose_create_with_environment(self, resource_group): self.check('[?name==`foo`].properties.template.containers[0].env[2].value', ['"snafu"']) ]) - if os.path.exists(compose_file_name): - os.remove(compose_file_name) + clean_up_test_file(compose_file_name) -class ContainerappComposePreviewEnvironmentSettingsExpectedExceptionScenarioTest(ScenarioTest): +class ContainerappComposePreviewEnvironmentSettingsExpectedExceptionScenarioTest(ContainerappComposePreviewScenarioTest): # pylint: disable=line-too-long + @serial_test() @ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus') def test_containerapp_compose_create_with_environment_prompt(self, resource_group): compose_text = """ @@ -64,9 +64,7 @@ def test_containerapp_compose_create_with_environment_prompt(self, resource_grou - LOREM= """ compose_file_name = f"{self._testMethodName}_compose.yml" - docker_compose_file = open(compose_file_name, "w", encoding='utf-8') - _ = docker_compose_file.write(compose_text) - docker_compose_file.close() + write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), @@ -83,5 +81,4 @@ def test_containerapp_compose_create_with_environment_prompt(self, resource_grou # This test fails because prompts are not supported in NoTTY environments self.cmd(command_string, expect_failure=True) - if os.path.exists(compose_file_name): - os.remove(compose_file_name) + clean_up_test_file(compose_file_name) diff --git a/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_ingress.py b/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_ingress.py index 28e23e0ac5a..71ebb8dc20c 100644 --- a/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_ingress.py +++ b/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_ingress.py @@ -3,16 +3,18 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -import os import unittest # pylint: disable=unused-import -from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer) +from azure.cli.testsdk import (ResourceGroupPreparer) +from azure.cli.testsdk.decorators import serial_test +from azext_containerapp_compose.tests.latest.common import (ContainerappComposePreviewScenarioTest, # pylint: disable=unused-import + write_test_file, + clean_up_test_file, + TEST_DIR) -TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) - - -class ContainerappComposePreviewIngressScenarioTest(ScenarioTest): +class ContainerappComposePreviewIngressScenarioTest(ContainerappComposePreviewScenarioTest): + @serial_test() @ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus') def test_containerapp_compose_create_with_ingress_external(self, resource_group): compose_text = """ @@ -22,9 +24,7 @@ def test_containerapp_compose_create_with_ingress_external(self, resource_group) ports: 8080:80 """ compose_file_name = f"{self._testMethodName}_compose.yml" - docker_compose_file = open(compose_file_name, "w", encoding='utf-8') - _ = docker_compose_file.write(compose_text) - docker_compose_file.close() + write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), @@ -42,11 +42,11 @@ def test_containerapp_compose_create_with_ingress_external(self, resource_group) self.check('[?name==`foo`].properties.configuration.ingress.external', [True]), ]) - if os.path.exists(compose_file_name): - os.remove(compose_file_name) + clean_up_test_file(compose_file_name) -class ContainerappComposePreviewIngressInternalScenarioTest(ScenarioTest): +class ContainerappComposePreviewIngressInternalScenarioTest(ContainerappComposePreviewScenarioTest): + @serial_test() @ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus') def test_containerapp_compose_create_with_ingress_internal(self, resource_group): compose_text = """ @@ -57,9 +57,7 @@ def test_containerapp_compose_create_with_ingress_internal(self, resource_group) - "3000" """ compose_file_name = f"{self._testMethodName}_compose.yml" - docker_compose_file = open(compose_file_name, "w", encoding='utf-8') - _ = docker_compose_file.write(compose_text) - docker_compose_file.close() + write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), @@ -77,11 +75,11 @@ def test_containerapp_compose_create_with_ingress_internal(self, resource_group) self.check('[?name==`foo`].properties.configuration.ingress.external', [False]), ]) - if os.path.exists(compose_file_name): - os.remove(compose_file_name) + clean_up_test_file(compose_file_name) -class ContainerappComposePreviewIngressBothScenarioTest(ScenarioTest): +class ContainerappComposePreviewIngressBothScenarioTest(ContainerappComposePreviewScenarioTest): + @serial_test() @ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus') def test_containerapp_compose_create_with_ingress_both(self, resource_group): compose_text = """ @@ -93,9 +91,7 @@ def test_containerapp_compose_create_with_ingress_both(self, resource_group): - "5000" """ compose_file_name = f"{self._testMethodName}_compose.yml" - docker_compose_file = open(compose_file_name, "w", encoding='utf-8') - _ = docker_compose_file.write(compose_text) - docker_compose_file.close() + write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), @@ -113,11 +109,11 @@ def test_containerapp_compose_create_with_ingress_both(self, resource_group): self.check('[?name==`foo`].properties.configuration.ingress.external', [True]), ]) - if os.path.exists(compose_file_name): - os.remove(compose_file_name) + clean_up_test_file(compose_file_name) -class ContainerappComposePreviewIngressPromptScenarioTest(ScenarioTest): +class ContainerappComposePreviewIngressPromptScenarioTest(ContainerappComposePreviewScenarioTest): + @serial_test() @ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus') def test_containerapp_compose_create_with_ingress_prompt(self, resource_group): compose_text = """ @@ -134,9 +130,7 @@ def test_containerapp_compose_create_with_ingress_prompt(self, resource_group): - "443" """ compose_file_name = f"{self._testMethodName}_compose.yml" - docker_compose_file = open(compose_file_name, "w", encoding='utf-8') - _ = docker_compose_file.write(compose_text) - docker_compose_file.close() + write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), @@ -153,5 +147,4 @@ def test_containerapp_compose_create_with_ingress_prompt(self, resource_group): # This test fails because prompts are not supported in NoTTY environments self.cmd(command_string, expect_failure=True) - if os.path.exists(compose_file_name): - os.remove(compose_file_name) + clean_up_test_file(compose_file_name) diff --git a/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_registries.py b/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_registries.py index 2fe7948b14c..6f4fd764e4f 100644 --- a/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_registries.py +++ b/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_registries.py @@ -3,16 +3,18 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -import os import unittest # pylint: disable=unused-import -from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer) +from azure.cli.testsdk import (ResourceGroupPreparer) +from azure.cli.testsdk.decorators import serial_test +from azext_containerapp_compose.tests.latest.common import (ContainerappComposePreviewScenarioTest, # pylint: disable=unused-import + write_test_file, + clean_up_test_file, + TEST_DIR) -TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) - - -class ContainerappComposePreviewRegistryAllArgsScenarioTest(ScenarioTest): +class ContainerappComposePreviewRegistryAllArgsScenarioTest(ContainerappComposePreviewScenarioTest): + @serial_test() @ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus') def test_containerapp_compose_create_with_registry_all_args(self, resource_group): compose_text = """ @@ -22,9 +24,7 @@ def test_containerapp_compose_create_with_registry_all_args(self, resource_group ports: 8080:80 """ compose_file_name = f"{self._testMethodName}_compose.yml" - docker_compose_file = open(compose_file_name, "w", encoding='utf-8') - _ = docker_compose_file.write(compose_text) - docker_compose_file.close() + write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), @@ -50,11 +50,11 @@ def test_containerapp_compose_create_with_registry_all_args(self, resource_group self.check('[?name==`foo`].properties.configuration.registries[0].passwordSecretRef', ["foobarazurecrio-foobar"]), # pylint: disable=C0301 ]) - if os.path.exists(compose_file_name): - os.remove(compose_file_name) + clean_up_test_file(compose_file_name) -class ContainerappComposePreviewRegistryServerArgOnlyScenarioTest(ScenarioTest): +class ContainerappComposePreviewRegistryServerArgOnlyScenarioTest(ContainerappComposePreviewScenarioTest): + @serial_test() @ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus') def test_containerapp_compose_create_with_registry_server_arg_only(self, resource_group): compose_text = """ @@ -64,9 +64,7 @@ def test_containerapp_compose_create_with_registry_server_arg_only(self, resourc ports: 8080:80 """ compose_file_name = f"{self._testMethodName}_compose.yml" - docker_compose_file = open(compose_file_name, "w", encoding='utf-8') - _ = docker_compose_file.write(compose_text) - docker_compose_file.close() + write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), @@ -85,5 +83,4 @@ def test_containerapp_compose_create_with_registry_server_arg_only(self, resourc # This test fails because prompts are not supported in NoTTY environments self.cmd(command_string, expect_failure=True) - if os.path.exists(compose_file_name): - os.remove(compose_file_name) + clean_up_test_file(compose_file_name) diff --git a/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_resources.py b/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_resources.py index c9e99de17fa..dad05925812 100644 --- a/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_resources.py +++ b/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_resources.py @@ -3,16 +3,18 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -import os import unittest # pylint: disable=unused-import -from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer) +from azure.cli.testsdk import (ResourceGroupPreparer) +from azure.cli.testsdk.decorators import serial_test +from azext_containerapp_compose.tests.latest.common import (ContainerappComposePreviewScenarioTest, # pylint: disable=unused-import + write_test_file, + clean_up_test_file, + TEST_DIR) -TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) - - -class ContainerappComposePreviewResourceSettingsScenarioTest(ScenarioTest): +class ContainerappComposePreviewResourceSettingsScenarioTest(ContainerappComposePreviewScenarioTest): + @serial_test() @ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus') def test_containerapp_compose_create_with_resources_from_service_cpus(self, resource_group): compose_text = """ @@ -24,9 +26,7 @@ def test_containerapp_compose_create_with_resources_from_service_cpus(self, reso - "3000" """ compose_file_name = f"{self._testMethodName}_compose.yml" - docker_compose_file = open(compose_file_name, "w", encoding='utf-8') - _ = docker_compose_file.write(compose_text) - docker_compose_file.close() + write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), @@ -43,9 +43,9 @@ def test_containerapp_compose_create_with_resources_from_service_cpus(self, reso self.check('[?name==`foo`].properties.template.containers[0].resources.cpu', [1.25]), ]) - if os.path.exists(compose_file_name): - os.remove(compose_file_name) + clean_up_test_file(compose_file_name) + @serial_test() @ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus') def test_containerapp_compose_create_with_resources_from_deploy_cpu(self, resource_group): compose_text = """ @@ -60,9 +60,7 @@ def test_containerapp_compose_create_with_resources_from_deploy_cpu(self, resour - "3000" """ compose_file_name = f"{self._testMethodName}_compose.yml" - docker_compose_file = open(compose_file_name, "w", encoding='utf-8') - _ = docker_compose_file.write(compose_text) - docker_compose_file.close() + write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), @@ -79,9 +77,9 @@ def test_containerapp_compose_create_with_resources_from_deploy_cpu(self, resour self.check('[?name==`foo`].properties.template.containers[0].resources.cpu', [1.25]), ]) - if os.path.exists(compose_file_name): - os.remove(compose_file_name) + clean_up_test_file(compose_file_name) + @serial_test() @ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus') def test_containerapp_compose_create_with_resources_from_both_cpus_and_deploy_cpu(self, resource_group): compose_text = """ @@ -97,9 +95,7 @@ def test_containerapp_compose_create_with_resources_from_both_cpus_and_deploy_cp - "3000" """ compose_file_name = f"{self._testMethodName}_compose.yml" - docker_compose_file = open(compose_file_name, "w", encoding='utf-8') - _ = docker_compose_file.write(compose_text) - docker_compose_file.close() + write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), @@ -116,5 +112,4 @@ def test_containerapp_compose_create_with_resources_from_both_cpus_and_deploy_cp self.check('[?name==`foo`].properties.template.containers[0].resources.cpu', [1.25]), ]) - if os.path.exists(compose_file_name): - os.remove(compose_file_name) + clean_up_test_file(compose_file_name) diff --git a/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_scale.py b/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_scale.py index 654a425c815..1884909f6c0 100644 --- a/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_scale.py +++ b/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_scale.py @@ -3,16 +3,18 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -import os import unittest # pylint: disable=unused-import -from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer) +from azure.cli.testsdk import (ResourceGroupPreparer) +from azure.cli.testsdk.decorators import serial_test +from azext_containerapp_compose.tests.latest.common import (ContainerappComposePreviewScenarioTest, # pylint: disable=unused-import + write_test_file, + clean_up_test_file, + TEST_DIR) -TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) - - -class ContainerappComposePreviewReplicasScenarioTest(ScenarioTest): +class ContainerappComposePreviewReplicasScenarioTest(ContainerappComposePreviewScenarioTest): + @serial_test() @ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus') def test_containerapp_compose_create_with_replicas_global_scale(self, resource_group): compose_text = """ @@ -26,9 +28,7 @@ def test_containerapp_compose_create_with_replicas_global_scale(self, resource_g replicas: 6 """ compose_file_name = f"{self._testMethodName}_compose.yml" - docker_compose_file = open(compose_file_name, "w", encoding='utf-8') - _ = docker_compose_file.write(compose_text) - docker_compose_file.close() + write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), @@ -47,9 +47,9 @@ def test_containerapp_compose_create_with_replicas_global_scale(self, resource_g self.check('[?name==`foo`].properties.template.scale.maxReplicas', [1]), ]) - if os.path.exists(compose_file_name): - os.remove(compose_file_name) + clean_up_test_file(compose_file_name) + @serial_test() @ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus') def test_containerapp_compose_create_with_replicas_replicated_mode(self, resource_group): compose_text = """ @@ -62,9 +62,7 @@ def test_containerapp_compose_create_with_replicas_replicated_mode(self, resourc replicas: 6 """ compose_file_name = f"{self._testMethodName}_compose.yml" - docker_compose_file = open(compose_file_name, "w", encoding='utf-8') - _ = docker_compose_file.write(compose_text) - docker_compose_file.close() + write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), @@ -83,5 +81,4 @@ def test_containerapp_compose_create_with_replicas_replicated_mode(self, resourc self.check('[?name==`foo`].properties.template.scale.maxReplicas', [6]), ]) - if os.path.exists(compose_file_name): - os.remove(compose_file_name) + clean_up_test_file(compose_file_name) diff --git a/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_secrets.py b/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_secrets.py index 15b05f3dc1a..5f96225fc6b 100644 --- a/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_secrets.py +++ b/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_secrets.py @@ -3,16 +3,18 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -import os import unittest # pylint: disable=unused-import -from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer) +from azure.cli.testsdk import (ResourceGroupPreparer) +from azure.cli.testsdk.decorators import serial_test +from azext_containerapp_compose.tests.latest.common import (ContainerappComposePreviewScenarioTest, # pylint: disable=unused-import + write_test_file, + clean_up_test_file, + TEST_DIR) -TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) - - -class ContainerappComposePreviewSecretsScenarioTest(ScenarioTest): +class ContainerappComposePreviewSecretsScenarioTest(ContainerappComposePreviewScenarioTest): + @serial_test() @ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus') def test_containerapp_compose_create_with_secrets(self, resource_group): compose_text = """ @@ -32,14 +34,11 @@ def test_containerapp_compose_create_with_secrets(self, resource_group): external: true """ compose_file_name = f"{self._testMethodName}_compose.yml" - docker_compose_file = open(compose_file_name, "w", encoding='utf-8') - _ = docker_compose_file.write(compose_text) - docker_compose_file.close() + write_test_file(compose_file_name, compose_text) secrets_file_name = "./my_secret.txt" - docker_secrets_file = open(secrets_file_name, "w", encoding='utf-8') - _ = docker_secrets_file.write("Lorem Ipsum\n") - docker_secrets_file.close() + secrets_text = "Lorem Ipsum\n" + write_test_file(secrets_file_name, secrets_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), @@ -59,12 +58,10 @@ def test_containerapp_compose_create_with_secrets(self, resource_group): self.check('[?name==`foo`].properties.template.containers[0].env[0].secretRef', ["redis-secret"]) # pylint: disable=C0301 ]) - if os.path.exists(compose_file_name): - os.remove(compose_file_name) - - if os.path.exists(secrets_file_name): - os.remove(secrets_file_name) + clean_up_test_file(compose_file_name) + clean_up_test_file(secrets_file_name) + @serial_test() @ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus') def test_containerapp_compose_create_with_secrets_and_existing_environment(self, resource_group): compose_text = """ @@ -90,14 +87,11 @@ def test_containerapp_compose_create_with_secrets_and_existing_environment(self, external: true """ compose_file_name = f"{self._testMethodName}_compose.yml" - docker_compose_file = open(compose_file_name, "w", encoding='utf-8') - _ = docker_compose_file.write(compose_text) - docker_compose_file.close() + write_test_file(compose_file_name, compose_text) secrets_file_name = "./snafu.txt" - docker_secrets_file = open(secrets_file_name, "w", encoding='utf-8') - _ = docker_secrets_file.write("Lorem Ipsum\n") - docker_secrets_file.close() + secrets_text = "Lorem Ipsum\n" + write_test_file(secrets_file_name, secrets_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), @@ -115,12 +109,10 @@ def test_containerapp_compose_create_with_secrets_and_existing_environment(self, self.check('length([?name==`foo`].properties.template.containers[0].env[].name)', 6), ]) - if os.path.exists(compose_file_name): - os.remove(compose_file_name) - - if os.path.exists(secrets_file_name): - os.remove(secrets_file_name) + clean_up_test_file(compose_file_name) + clean_up_test_file(secrets_file_name) + @serial_test() @ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus') def test_containerapp_compose_create_with_secrets_and_existing_environment_conflict(self, resource_group): compose_text = """ @@ -136,14 +128,11 @@ def test_containerapp_compose_create_with_secrets_and_existing_environment_confl file: ./database__client.txt """ compose_file_name = f"{self._testMethodName}_compose.yml" - docker_compose_file = open(compose_file_name, "w", encoding='utf-8') - _ = docker_compose_file.write(compose_text) - docker_compose_file.close() + write_test_file(compose_file_name, compose_text) secrets_file_name = "./database__client.txt" - docker_secrets_file = open(secrets_file_name, "w", encoding='utf-8') - _ = docker_secrets_file.write("Lorem Ipsum\n") - docker_secrets_file.close() + secrets_text = "Lorem Ipsum\n" + write_test_file(secrets_file_name, secrets_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), @@ -160,8 +149,5 @@ def test_containerapp_compose_create_with_secrets_and_existing_environment_confl # This test fails with duplicate environment variable names self.cmd(command_string, expect_failure=True) - if os.path.exists(compose_file_name): - os.remove(compose_file_name) - - if os.path.exists(secrets_file_name): - os.remove(secrets_file_name) + clean_up_test_file(compose_file_name) + clean_up_test_file(secrets_file_name) diff --git a/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_transport_overrides.py b/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_transport_overrides.py index d002592f0f1..8c0d36268b0 100644 --- a/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_transport_overrides.py +++ b/src/containerapp-compose/azext_containerapp_compose/tests/latest/test_containerapp_preview_transport_overrides.py @@ -3,16 +3,18 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -import os import unittest # pylint: disable=unused-import -from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer) +from azure.cli.testsdk import (ResourceGroupPreparer) +from azure.cli.testsdk.decorators import serial_test +from azext_containerapp_compose.tests.latest.common import (ContainerappComposePreviewScenarioTest, # pylint: disable=unused-import + write_test_file, + clean_up_test_file, + TEST_DIR) -TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) - - -class ContainerappComposePreviewTransportOverridesScenarioTest(ScenarioTest): +class ContainerappComposePreviewTransportOverridesScenarioTest(ContainerappComposePreviewScenarioTest): + @serial_test() @ResourceGroupPreparer(name_prefix='cli_test_containerapp_preview', location='eastus') def test_containerapp_compose_create_with_transport_arg(self, resource_group): compose_text = """ @@ -22,9 +24,7 @@ def test_containerapp_compose_create_with_transport_arg(self, resource_group): ports: 8080:80 """ compose_file_name = f"{self._testMethodName}_compose.yml" - docker_compose_file = open(compose_file_name, "w", encoding='utf-8') - _ = docker_compose_file.write(compose_text) - docker_compose_file.close() + write_test_file(compose_file_name, compose_text) self.kwargs.update({ 'environment': self.create_random_name(prefix='containerapp-compose', length=24), @@ -45,5 +45,4 @@ def test_containerapp_compose_create_with_transport_arg(self, resource_group): self.check('[?name==`foo`].properties.configuration.ingress.transport', ["Http2"]), ]) - if os.path.exists(compose_file_name): - os.remove(compose_file_name) + clean_up_test_file(compose_file_name) diff --git a/src/containerapp-compose/setup.py b/src/containerapp-compose/setup.py index 451923f82d5..8f863a41cd0 100644 --- a/src/containerapp-compose/setup.py +++ b/src/containerapp-compose/setup.py @@ -32,7 +32,7 @@ 'License :: OSI Approved :: MIT License', ] -DEPENDENCIES = ['azure-cli-core', 'pycomposefile>=0.0.26'] +DEPENDENCIES = ['pycomposefile>=0.0.26'] with open('README.rst', 'r', encoding='utf-8') as f: README = f.read()