Skip to content

Commit bf60878

Browse files
panchagnulaqwordy
authored andcommitted
[Webapp] Adding E2E tests for az webapp up (#11774)
* Adding E2E tests for az webapp up Adding test for az webapp up for Node app Adding test for Python App for az webapp up Adding test for dotnercore for az webapp up Adding tests for static html Rerecording test Removing ResourceGroup preparer Testing with plan & resourcegroup Re-recording once more minus the -live flag * Making az webapp up tests live only
1 parent 7bb6319 commit bf60878

File tree

5 files changed

+296
-0
lines changed

5 files changed

+296
-0
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
# pylint: disable=line-too-long
7+
# pylint: disable=too-few-public-methods
8+
9+
import json
10+
import unittest
11+
import jmespath
12+
import tempfile
13+
import os
14+
15+
from azure.cli.testsdk import (
16+
ScenarioTest, ResourceGroupPreparer, JMESPathCheck, live_only)
17+
18+
TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..'))
19+
20+
21+
class WebAppUpE2ETests(ScenarioTest):
22+
@live_only()
23+
@ResourceGroupPreparer()
24+
def test_webapp_up_node_e2e(self, resource_group):
25+
plan = self.create_random_name('up-nodeplan', 24)
26+
webapp_name = self.create_random_name('up-nodeapp', 24)
27+
zip_file_name = os.path.join(TEST_DIR, 'node-Express-up.zip')
28+
29+
# create a temp directory and unzip the code to this folder
30+
import zipfile
31+
import tempfile
32+
temp_dir = tempfile.mkdtemp()
33+
zip_ref = zipfile.ZipFile(zip_file_name, 'r')
34+
zip_ref.extractall(temp_dir)
35+
current_working_dir = os.getcwd()
36+
37+
# change the working dir to the dir where the code has been extracted to
38+
up_working_dir = os.path.join(temp_dir, 'myExpressApp')
39+
os.chdir(up_working_dir)
40+
41+
# test dryrun operation
42+
result = self.cmd(
43+
'webapp up -n {} --dryrun'.format(webapp_name)).get_output_in_json()
44+
self.assertTrue(result['sku'].lower() == 'premiumv2')
45+
self.assertTrue(result['name'].startswith(webapp_name))
46+
self.assertTrue(result['src_path'].replace(
47+
os.sep + os.sep, os.sep), up_working_dir)
48+
self.assertTrue(result['runtime_version'] == 'node|10.14')
49+
self.assertTrue(result['os'].lower() == 'linux')
50+
51+
# test the full E2E operation works
52+
full_result = self.cmd(
53+
'webapp up -n {} -g {} --plan {}'.format(webapp_name, resource_group, plan)).get_output_in_json()
54+
self.assertTrue(result['name'] == full_result['name'])
55+
56+
# Verify app is created
57+
# since we set local context, -n and -g are no longer required
58+
self.cmd('webapp show', checks=[
59+
JMESPathCheck('name', webapp_name),
60+
JMESPathCheck('httpsOnly', True),
61+
JMESPathCheck('kind', 'app,linux'),
62+
JMESPathCheck('resourceGroup', resource_group)
63+
])
64+
65+
self.cmd('webapp config show', checks=[
66+
JMESPathCheck('linuxFxVersion', result['runtime_version']),
67+
JMESPathCheck('tags.cli', 'webapp_up'),
68+
])
69+
70+
self.cmd('webapp config appsettings list', checks=[
71+
JMESPathCheck('[0].name', 'SCM_DO_BUILD_DURING_DEPLOYMENT'),
72+
JMESPathCheck('[0].value', 'True')
73+
])
74+
75+
self.cmd('appservice plan show', checks=[
76+
JMESPathCheck('reserved', True),
77+
JMESPathCheck('name', plan),
78+
JMESPathCheck('sku.tier', 'PremiumV2'),
79+
JMESPathCheck('sku.name', 'P1v2')
80+
])
81+
82+
# cleanup
83+
# switch back the working dir
84+
os.chdir(current_working_dir)
85+
# delete temp_dir
86+
import shutil
87+
shutil.rmtree(temp_dir)
88+
89+
@live_only()
90+
@ResourceGroupPreparer()
91+
def test_webapp_up_python_e2e(self, resource_group):
92+
plan = self.create_random_name('up-pythonplan', 24)
93+
webapp_name = self.create_random_name('up-pythonapp', 24)
94+
zip_file_name = os.path.join(TEST_DIR, 'python-hello-world-up.zip')
95+
96+
# create a temp directory and unzip the code to this folder
97+
import zipfile
98+
import tempfile
99+
temp_dir = tempfile.mkdtemp()
100+
zip_ref = zipfile.ZipFile(zip_file_name, 'r')
101+
zip_ref.extractall(temp_dir)
102+
current_working_dir = os.getcwd()
103+
104+
# change the working dir to the dir where the code has been extracted to
105+
up_working_dir = os.path.join(temp_dir, 'python-docs-hello-world')
106+
os.chdir(up_working_dir)
107+
108+
# test dryrun operation
109+
result = self.cmd('webapp up -n {} --sku S1 --dryrun'
110+
.format(webapp_name)).get_output_in_json()
111+
self.assertTrue(result['sku'].lower() == 'standard')
112+
self.assertTrue(result['name'].startswith(webapp_name))
113+
self.assertTrue(result['src_path'].replace(
114+
os.sep + os.sep, os.sep), up_working_dir)
115+
self.assertTrue(result['runtime_version'] == 'python|3.7')
116+
self.assertTrue(result['os'].lower() == 'linux')
117+
118+
# test the full E2E operation works
119+
full_result = self.cmd(
120+
'webapp up -n {} --sku S1 -g {} --plan {}'.format(webapp_name, resource_group, plan)).get_output_in_json()
121+
self.assertTrue(result['name'] == full_result['name'])
122+
123+
# Verify app is created
124+
# since we set local context, -n and -g are no longer required
125+
self.cmd('webapp show', checks=[
126+
JMESPathCheck('name', webapp_name),
127+
JMESPathCheck('httpsOnly', True),
128+
JMESPathCheck('kind', 'app,linux'),
129+
JMESPathCheck('resourceGroup', resource_group)
130+
])
131+
132+
self.cmd('webapp config show', checks=[
133+
JMESPathCheck('linuxFxVersion', result['runtime_version']),
134+
JMESPathCheck('tags.cli', 'webapp_up'),
135+
])
136+
137+
self.cmd('webapp config appsettings list', checks=[
138+
JMESPathCheck('[0].name', 'SCM_DO_BUILD_DURING_DEPLOYMENT'),
139+
JMESPathCheck('[0].value', 'True')
140+
])
141+
142+
# verify SKU and kind of ASP created
143+
self.cmd('appservice plan show', checks=[
144+
JMESPathCheck('reserved', True),
145+
JMESPathCheck('name', plan),
146+
JMESPathCheck('sku.tier', 'Standard'),
147+
JMESPathCheck('sku.name', 'S1')
148+
])
149+
150+
# cleanup
151+
# switch back the working dir
152+
os.chdir(current_working_dir)
153+
# delete temp_dir
154+
import shutil
155+
shutil.rmtree(temp_dir)
156+
157+
@live_only()
158+
@ResourceGroupPreparer()
159+
def test_webapp_up_dotnetcore_e2e(self, resource_group):
160+
plan = self.create_random_name('up-dotnetcoreplan', 24)
161+
webapp_name = self.create_random_name('up-dotnetcoreapp', 24)
162+
zip_file_name = os.path.join(TEST_DIR, 'dotnetcore-hello-up.zip')
163+
164+
# create a temp directory and unzip the code to this folder
165+
import zipfile
166+
import tempfile
167+
temp_dir = tempfile.mkdtemp()
168+
zip_ref = zipfile.ZipFile(zip_file_name, 'r')
169+
zip_ref.extractall(temp_dir)
170+
current_working_dir = os.getcwd()
171+
172+
# change the working dir to the dir where the code has been extracted to
173+
up_working_dir = os.path.join(temp_dir, 'hellodotnetcore')
174+
os.chdir(up_working_dir)
175+
176+
# test dryrun operation
177+
result = self.cmd('webapp up -n {} --dryrun'
178+
.format(webapp_name)).get_output_in_json()
179+
self.assertTrue(result['sku'].lower() == 'free')
180+
self.assertTrue(result['name'].startswith(webapp_name))
181+
self.assertTrue(result['src_path'].replace(
182+
os.sep + os.sep, os.sep), up_working_dir)
183+
self.assertTrue(result['runtime_version'] == 'dotnetcore|2.2')
184+
self.assertTrue(result['os'].lower() == 'windows')
185+
186+
# test the full E2E operation works
187+
full_result = self.cmd(
188+
'webapp up -n {} -g {} --plan {}'.format(webapp_name, resource_group, plan)).get_output_in_json()
189+
self.assertTrue(result['name'] == full_result['name'])
190+
191+
# Verify app is created
192+
# since we set local context, -n and -g are no longer required
193+
self.cmd('webapp show', checks=[
194+
JMESPathCheck('name', webapp_name),
195+
JMESPathCheck('httpsOnly', True),
196+
JMESPathCheck('kind', 'app'),
197+
JMESPathCheck('resourceGroup', resource_group)
198+
])
199+
200+
self.cmd('webapp config show', checks=[
201+
JMESPathCheck('tags.cli', 'webapp_up'),
202+
JMESPathCheck('windowsFxVersion', None)
203+
])
204+
205+
self.cmd('webapp config appsettings list', checks=[
206+
JMESPathCheck('[1].name', 'SCM_DO_BUILD_DURING_DEPLOYMENT'),
207+
JMESPathCheck('[1].value', 'True')
208+
])
209+
210+
# verify SKU and kind of ASP created
211+
self.cmd('appservice plan show', checks=[
212+
JMESPathCheck('reserved', False),
213+
JMESPathCheck('name', plan),
214+
JMESPathCheck('sku.tier', 'Free'),
215+
JMESPathCheck('sku.name', 'F1')
216+
])
217+
218+
# cleanup
219+
# switch back the working dir
220+
os.chdir(current_working_dir)
221+
# delete temp_dir
222+
import shutil
223+
shutil.rmtree(temp_dir)
224+
225+
@live_only()
226+
@ResourceGroupPreparer()
227+
def test_webapp_up_statichtml_e2e(self, resource_group):
228+
plan = self.create_random_name('up-statichtmlplan', 24)
229+
webapp_name = self.create_random_name('up-statichtmlapp', 24)
230+
zip_file_name = os.path.join(
231+
TEST_DIR, 'html-static-hello-world-up.zip')
232+
233+
# create a temp directory and unzip the code to this folder
234+
import zipfile
235+
import tempfile
236+
temp_dir = tempfile.mkdtemp()
237+
zip_ref = zipfile.ZipFile(zip_file_name, 'r')
238+
zip_ref.extractall(temp_dir)
239+
current_working_dir = os.getcwd()
240+
241+
# change the working dir to the dir where the code has been extracted to
242+
up_working_dir = os.path.join(temp_dir, 'html-docs-hello-world-master')
243+
os.chdir(up_working_dir)
244+
245+
# test dryrun operation
246+
result = self.cmd('webapp up -n {} --dryrun --html'
247+
.format(webapp_name)).get_output_in_json()
248+
self.assertTrue(result['sku'].lower() == 'free')
249+
self.assertTrue(result['name'].startswith(webapp_name))
250+
self.assertTrue(result['src_path'].replace(
251+
os.sep + os.sep, os.sep), up_working_dir)
252+
self.assertTrue(result['runtime_version'] == '-')
253+
self.assertTrue(result['os'].lower() == 'windows')
254+
255+
# test the full E2E operation works
256+
full_result = self.cmd(
257+
'webapp up -n {} -g {} --plan {} --html'.format(webapp_name, resource_group, plan)).get_output_in_json()
258+
self.assertTrue(result['name'] == full_result['name'])
259+
260+
# Verify app is created
261+
# since we set local context, -n and -g are no longer required
262+
self.cmd('webapp show', checks=[
263+
JMESPathCheck('name', webapp_name),
264+
JMESPathCheck('httpsOnly', True),
265+
JMESPathCheck('kind', 'app'),
266+
JMESPathCheck('resourceGroup', resource_group)
267+
])
268+
269+
self.cmd('webapp config show', checks=[
270+
JMESPathCheck('tags.cli', 'webapp_up'),
271+
JMESPathCheck('windowsFxVersion', None)
272+
])
273+
274+
self.cmd('webapp config appsettings list', checks=[
275+
JMESPathCheck('[1].name', 'SCM_DO_BUILD_DURING_DEPLOYMENT'),
276+
JMESPathCheck('[1].value', 'True')
277+
])
278+
279+
# verify SKU and kind of ASP created
280+
self.cmd('appservice plan show', checks=[
281+
JMESPathCheck('reserved', False),
282+
JMESPathCheck('name', plan),
283+
JMESPathCheck('sku.tier', 'Free'),
284+
JMESPathCheck('sku.name', 'F1')
285+
])
286+
287+
# cleanup
288+
# switch back the working dir
289+
os.chdir(current_working_dir)
290+
# delete temp_dir
291+
import shutil
292+
shutil.rmtree(temp_dir)
293+
294+
295+
if __name__ == '__main__':
296+
unittest.main()

0 commit comments

Comments
 (0)