-
Notifications
You must be signed in to change notification settings - Fork 3.3k
webapp: Adding E2E tests for az webapp up #11774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+151 KB
src/azure-cli/azure/cli/command_modules/appservice/tests/latest/dotnetcore-hello-up.zip
Binary file not shown.
Binary file added
BIN
+343 KB
...zure-cli/azure/cli/command_modules/appservice/tests/latest/html-static-hello-world-up.zip
Binary file not shown.
Binary file added
BIN
+4.25 MB
src/azure-cli/azure/cli/command_modules/appservice/tests/latest/node-Express-up.zip
Binary file not shown.
Binary file added
BIN
+61.4 KB
src/azure-cli/azure/cli/command_modules/appservice/tests/latest/python-hello-world-up.zip
Binary file not shown.
296 changes: 296 additions & 0 deletions
296
src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_webapp_up_commands.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,296 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| # pylint: disable=line-too-long | ||
| # pylint: disable=too-few-public-methods | ||
|
|
||
| import json | ||
| import unittest | ||
| import jmespath | ||
| import tempfile | ||
| import os | ||
|
|
||
| from azure.cli.testsdk import ( | ||
| ScenarioTest, ResourceGroupPreparer, JMESPathCheck, live_only) | ||
|
|
||
| TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) | ||
|
|
||
|
|
||
| class WebAppUpE2ETests(ScenarioTest): | ||
| @live_only() | ||
| @ResourceGroupPreparer() | ||
| def test_webapp_up_node_e2e(self, resource_group): | ||
| plan = self.create_random_name('up-nodeplan', 24) | ||
| webapp_name = self.create_random_name('up-nodeapp', 24) | ||
| zip_file_name = os.path.join(TEST_DIR, 'node-Express-up.zip') | ||
|
|
||
| # create a temp directory and unzip the code to this folder | ||
| import zipfile | ||
| import tempfile | ||
| temp_dir = tempfile.mkdtemp() | ||
| zip_ref = zipfile.ZipFile(zip_file_name, 'r') | ||
| zip_ref.extractall(temp_dir) | ||
| current_working_dir = os.getcwd() | ||
|
|
||
| # change the working dir to the dir where the code has been extracted to | ||
| up_working_dir = os.path.join(temp_dir, 'myExpressApp') | ||
| os.chdir(up_working_dir) | ||
|
|
||
| # test dryrun operation | ||
| result = self.cmd( | ||
| 'webapp up -n {} --dryrun'.format(webapp_name)).get_output_in_json() | ||
| self.assertTrue(result['sku'].lower() == 'premiumv2') | ||
| self.assertTrue(result['name'].startswith(webapp_name)) | ||
| self.assertTrue(result['src_path'].replace( | ||
| os.sep + os.sep, os.sep), up_working_dir) | ||
| self.assertTrue(result['runtime_version'] == 'node|10.14') | ||
| self.assertTrue(result['os'].lower() == 'linux') | ||
|
|
||
| # test the full E2E operation works | ||
| full_result = self.cmd( | ||
| 'webapp up -n {} -g {} --plan {}'.format(webapp_name, resource_group, plan)).get_output_in_json() | ||
| self.assertTrue(result['name'] == full_result['name']) | ||
|
|
||
| # Verify app is created | ||
| # since we set local context, -n and -g are no longer required | ||
| self.cmd('webapp show', checks=[ | ||
| JMESPathCheck('name', webapp_name), | ||
| JMESPathCheck('httpsOnly', True), | ||
| JMESPathCheck('kind', 'app,linux'), | ||
| JMESPathCheck('resourceGroup', resource_group) | ||
| ]) | ||
|
|
||
| self.cmd('webapp config show', checks=[ | ||
| JMESPathCheck('linuxFxVersion', result['runtime_version']), | ||
| JMESPathCheck('tags.cli', 'webapp_up'), | ||
| ]) | ||
|
|
||
| self.cmd('webapp config appsettings list', checks=[ | ||
| JMESPathCheck('[0].name', 'SCM_DO_BUILD_DURING_DEPLOYMENT'), | ||
| JMESPathCheck('[0].value', 'True') | ||
| ]) | ||
|
|
||
| self.cmd('appservice plan show', checks=[ | ||
| JMESPathCheck('reserved', True), | ||
| JMESPathCheck('name', plan), | ||
| JMESPathCheck('sku.tier', 'PremiumV2'), | ||
| JMESPathCheck('sku.name', 'P1v2') | ||
| ]) | ||
|
|
||
| # cleanup | ||
| # switch back the working dir | ||
| os.chdir(current_working_dir) | ||
| # delete temp_dir | ||
| import shutil | ||
| shutil.rmtree(temp_dir) | ||
|
|
||
| @live_only() | ||
| @ResourceGroupPreparer() | ||
| def test_webapp_up_python_e2e(self, resource_group): | ||
| plan = self.create_random_name('up-pythonplan', 24) | ||
| webapp_name = self.create_random_name('up-pythonapp', 24) | ||
| zip_file_name = os.path.join(TEST_DIR, 'python-hello-world-up.zip') | ||
|
|
||
| # create a temp directory and unzip the code to this folder | ||
| import zipfile | ||
| import tempfile | ||
| temp_dir = tempfile.mkdtemp() | ||
| zip_ref = zipfile.ZipFile(zip_file_name, 'r') | ||
| zip_ref.extractall(temp_dir) | ||
| current_working_dir = os.getcwd() | ||
|
|
||
| # change the working dir to the dir where the code has been extracted to | ||
| up_working_dir = os.path.join(temp_dir, 'python-docs-hello-world') | ||
| os.chdir(up_working_dir) | ||
|
|
||
| # test dryrun operation | ||
| result = self.cmd('webapp up -n {} --sku S1 --dryrun' | ||
| .format(webapp_name)).get_output_in_json() | ||
| self.assertTrue(result['sku'].lower() == 'standard') | ||
| self.assertTrue(result['name'].startswith(webapp_name)) | ||
| self.assertTrue(result['src_path'].replace( | ||
| os.sep + os.sep, os.sep), up_working_dir) | ||
| self.assertTrue(result['runtime_version'] == 'python|3.7') | ||
| self.assertTrue(result['os'].lower() == 'linux') | ||
|
|
||
| # test the full E2E operation works | ||
| full_result = self.cmd( | ||
| 'webapp up -n {} --sku S1 -g {} --plan {}'.format(webapp_name, resource_group, plan)).get_output_in_json() | ||
| self.assertTrue(result['name'] == full_result['name']) | ||
|
|
||
| # Verify app is created | ||
| # since we set local context, -n and -g are no longer required | ||
| self.cmd('webapp show', checks=[ | ||
| JMESPathCheck('name', webapp_name), | ||
| JMESPathCheck('httpsOnly', True), | ||
| JMESPathCheck('kind', 'app,linux'), | ||
| JMESPathCheck('resourceGroup', resource_group) | ||
| ]) | ||
|
|
||
| self.cmd('webapp config show', checks=[ | ||
| JMESPathCheck('linuxFxVersion', result['runtime_version']), | ||
| JMESPathCheck('tags.cli', 'webapp_up'), | ||
| ]) | ||
|
|
||
| self.cmd('webapp config appsettings list', checks=[ | ||
| JMESPathCheck('[0].name', 'SCM_DO_BUILD_DURING_DEPLOYMENT'), | ||
| JMESPathCheck('[0].value', 'True') | ||
| ]) | ||
|
|
||
| # verify SKU and kind of ASP created | ||
| self.cmd('appservice plan show', checks=[ | ||
| JMESPathCheck('reserved', True), | ||
| JMESPathCheck('name', plan), | ||
| JMESPathCheck('sku.tier', 'Standard'), | ||
| JMESPathCheck('sku.name', 'S1') | ||
| ]) | ||
|
|
||
| # cleanup | ||
| # switch back the working dir | ||
| os.chdir(current_working_dir) | ||
| # delete temp_dir | ||
| import shutil | ||
| shutil.rmtree(temp_dir) | ||
|
|
||
| @live_only() | ||
| @ResourceGroupPreparer() | ||
| def test_webapp_up_dotnetcore_e2e(self, resource_group): | ||
| plan = self.create_random_name('up-dotnetcoreplan', 24) | ||
| webapp_name = self.create_random_name('up-dotnetcoreapp', 24) | ||
| zip_file_name = os.path.join(TEST_DIR, 'dotnetcore-hello-up.zip') | ||
|
|
||
| # create a temp directory and unzip the code to this folder | ||
| import zipfile | ||
| import tempfile | ||
| temp_dir = tempfile.mkdtemp() | ||
| zip_ref = zipfile.ZipFile(zip_file_name, 'r') | ||
| zip_ref.extractall(temp_dir) | ||
| current_working_dir = os.getcwd() | ||
|
|
||
| # change the working dir to the dir where the code has been extracted to | ||
| up_working_dir = os.path.join(temp_dir, 'hellodotnetcore') | ||
| os.chdir(up_working_dir) | ||
|
|
||
| # test dryrun operation | ||
| result = self.cmd('webapp up -n {} --dryrun' | ||
| .format(webapp_name)).get_output_in_json() | ||
| self.assertTrue(result['sku'].lower() == 'free') | ||
| self.assertTrue(result['name'].startswith(webapp_name)) | ||
| self.assertTrue(result['src_path'].replace( | ||
| os.sep + os.sep, os.sep), up_working_dir) | ||
| self.assertTrue(result['runtime_version'] == 'dotnetcore|2.2') | ||
| self.assertTrue(result['os'].lower() == 'windows') | ||
|
|
||
| # test the full E2E operation works | ||
| full_result = self.cmd( | ||
| 'webapp up -n {} -g {} --plan {}'.format(webapp_name, resource_group, plan)).get_output_in_json() | ||
| self.assertTrue(result['name'] == full_result['name']) | ||
|
|
||
| # Verify app is created | ||
| # since we set local context, -n and -g are no longer required | ||
| self.cmd('webapp show', checks=[ | ||
| JMESPathCheck('name', webapp_name), | ||
| JMESPathCheck('httpsOnly', True), | ||
| JMESPathCheck('kind', 'app'), | ||
| JMESPathCheck('resourceGroup', resource_group) | ||
| ]) | ||
|
|
||
| self.cmd('webapp config show', checks=[ | ||
| JMESPathCheck('tags.cli', 'webapp_up'), | ||
| JMESPathCheck('windowsFxVersion', None) | ||
| ]) | ||
|
|
||
| self.cmd('webapp config appsettings list', checks=[ | ||
| JMESPathCheck('[1].name', 'SCM_DO_BUILD_DURING_DEPLOYMENT'), | ||
| JMESPathCheck('[1].value', 'True') | ||
| ]) | ||
|
|
||
| # verify SKU and kind of ASP created | ||
| self.cmd('appservice plan show', checks=[ | ||
| JMESPathCheck('reserved', False), | ||
| JMESPathCheck('name', plan), | ||
| JMESPathCheck('sku.tier', 'Free'), | ||
| JMESPathCheck('sku.name', 'F1') | ||
| ]) | ||
|
|
||
| # cleanup | ||
| # switch back the working dir | ||
| os.chdir(current_working_dir) | ||
| # delete temp_dir | ||
| import shutil | ||
| shutil.rmtree(temp_dir) | ||
|
|
||
| @live_only() | ||
| @ResourceGroupPreparer() | ||
| def test_webapp_up_statichtml_e2e(self, resource_group): | ||
| plan = self.create_random_name('up-statichtmlplan', 24) | ||
| webapp_name = self.create_random_name('up-statichtmlapp', 24) | ||
| zip_file_name = os.path.join( | ||
| TEST_DIR, 'html-static-hello-world-up.zip') | ||
|
|
||
| # create a temp directory and unzip the code to this folder | ||
| import zipfile | ||
| import tempfile | ||
| temp_dir = tempfile.mkdtemp() | ||
| zip_ref = zipfile.ZipFile(zip_file_name, 'r') | ||
| zip_ref.extractall(temp_dir) | ||
| current_working_dir = os.getcwd() | ||
|
|
||
| # change the working dir to the dir where the code has been extracted to | ||
| up_working_dir = os.path.join(temp_dir, 'html-docs-hello-world-master') | ||
| os.chdir(up_working_dir) | ||
|
|
||
| # test dryrun operation | ||
| result = self.cmd('webapp up -n {} --dryrun --html' | ||
| .format(webapp_name)).get_output_in_json() | ||
| self.assertTrue(result['sku'].lower() == 'free') | ||
| self.assertTrue(result['name'].startswith(webapp_name)) | ||
| self.assertTrue(result['src_path'].replace( | ||
| os.sep + os.sep, os.sep), up_working_dir) | ||
| self.assertTrue(result['runtime_version'] == '-') | ||
| self.assertTrue(result['os'].lower() == 'windows') | ||
|
|
||
| # test the full E2E operation works | ||
| full_result = self.cmd( | ||
| 'webapp up -n {} -g {} --plan {} --html'.format(webapp_name, resource_group, plan)).get_output_in_json() | ||
| self.assertTrue(result['name'] == full_result['name']) | ||
|
|
||
| # Verify app is created | ||
| # since we set local context, -n and -g are no longer required | ||
| self.cmd('webapp show', checks=[ | ||
| JMESPathCheck('name', webapp_name), | ||
| JMESPathCheck('httpsOnly', True), | ||
| JMESPathCheck('kind', 'app'), | ||
| JMESPathCheck('resourceGroup', resource_group) | ||
| ]) | ||
|
|
||
| self.cmd('webapp config show', checks=[ | ||
| JMESPathCheck('tags.cli', 'webapp_up'), | ||
| JMESPathCheck('windowsFxVersion', None) | ||
| ]) | ||
|
|
||
| self.cmd('webapp config appsettings list', checks=[ | ||
| JMESPathCheck('[1].name', 'SCM_DO_BUILD_DURING_DEPLOYMENT'), | ||
| JMESPathCheck('[1].value', 'True') | ||
| ]) | ||
|
|
||
| # verify SKU and kind of ASP created | ||
| self.cmd('appservice plan show', checks=[ | ||
| JMESPathCheck('reserved', False), | ||
| JMESPathCheck('name', plan), | ||
| JMESPathCheck('sku.tier', 'Free'), | ||
| JMESPathCheck('sku.name', 'F1') | ||
| ]) | ||
|
|
||
| # cleanup | ||
| # switch back the working dir | ||
| os.chdir(current_working_dir) | ||
| # delete temp_dir | ||
| import shutil | ||
| shutil.rmtree(temp_dir) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@panchagnula may I know that why you make all your test live_only()? In this way, CI system still will skip the test.