Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/functional/gamelift/test_upload_build.py
1567 views
1
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
import os
14
from awscli.testutils import BaseAWSCommandParamsTest, FileCreator, mock
15
16
17
class TestUploadBuild(BaseAWSCommandParamsTest):
18
19
prefix = 'gamelift upload-build'
20
21
def setUp(self):
22
super(TestUploadBuild, self).setUp()
23
self.files = FileCreator()
24
25
def tearDown(self):
26
super(TestUploadBuild, self).tearDown()
27
self.files.remove_all()
28
29
def test_upload_build(self):
30
self.files.create_file('tmpfile', 'Some contents')
31
cmdline = self.prefix
32
cmdline += ' --name mybuild --build-version myversion'
33
cmdline += ' --build-root %s' % self.files.rootdir
34
35
self.parsed_responses = [
36
{'Build': {'BuildId': 'myid'}},
37
{'StorageLocation': {
38
'Bucket': 'mybucket',
39
'Key': 'mykey'},
40
'UploadCredentials': {
41
'AccessKeyId': 'myaccesskey',
42
'SecretAccessKey': 'mysecretkey',
43
'SessionToken': 'mytoken'}},
44
{}
45
]
46
47
stdout, stderr, rc = self.run_cmd(cmdline, expected_rc=0)
48
49
# First the build is created.
50
self.assertEqual(len(self.operations_called), 3)
51
self.assertEqual(self.operations_called[0][0].name, 'CreateBuild')
52
self.assertEqual(
53
self.operations_called[0][1],
54
{'Name': 'mybuild', 'Version': 'myversion'}
55
)
56
57
# Second the credentials are requested.
58
self.assertEqual(
59
self.operations_called[1][0].name, 'RequestUploadCredentials')
60
self.assertEqual(
61
self.operations_called[1][1], {'BuildId': 'myid'})
62
63
# The build is then uploaded to S3.
64
self.assertEqual(self.operations_called[2][0].name, 'PutObject')
65
self.assertEqual(
66
self.operations_called[2][1],
67
{'Body': mock.ANY, 'Bucket': 'mybucket', 'Key': 'mykey'}
68
)
69
70
# Check the output of the command.
71
self.assertIn(
72
'Successfully uploaded %s to AWS GameLift' % self.files.rootdir,
73
stdout)
74
self.assertIn('Build ID: myid', stdout)
75
76
def test_upload_build_with_operating_system_param(self):
77
self.files.create_file('tmpfile', 'Some contents')
78
cmdline = self.prefix
79
cmdline += ' --name mybuild --build-version myversion'
80
cmdline += ' --build-root %s' % self.files.rootdir
81
cmdline += ' --operating-system WINDOWS_2012'
82
83
self.parsed_responses = [
84
{'Build': {'BuildId': 'myid'}},
85
{'StorageLocation': {
86
'Bucket': 'mybucket',
87
'Key': 'mykey'},
88
'UploadCredentials': {
89
'AccessKeyId': 'myaccesskey',
90
'SecretAccessKey': 'mysecretkey',
91
'SessionToken': 'mytoken'}},
92
{}
93
]
94
95
stdout, stderr, rc = self.run_cmd(cmdline, expected_rc=0)
96
97
# First the build is created.
98
self.assertEqual(len(self.operations_called), 3)
99
self.assertEqual(self.operations_called[0][0].name, 'CreateBuild')
100
self.assertEqual(
101
self.operations_called[0][1],
102
{'Name': 'mybuild', 'Version': 'myversion',
103
'OperatingSystem': 'WINDOWS_2012'}
104
)
105
106
# Second the credentials are requested.
107
self.assertEqual(
108
self.operations_called[1][0].name, 'RequestUploadCredentials')
109
self.assertEqual(
110
self.operations_called[1][1], {'BuildId': 'myid'})
111
112
# The build is then uploaded to S3.
113
self.assertEqual(self.operations_called[2][0].name, 'PutObject')
114
self.assertEqual(
115
self.operations_called[2][1],
116
{'Body': mock.ANY, 'Bucket': 'mybucket', 'Key': 'mykey'}
117
)
118
119
# Check the output of the command.
120
self.assertIn(
121
'Successfully uploaded %s to AWS GameLift' % self.files.rootdir,
122
stdout)
123
self.assertIn('Build ID: myid', stdout)
124
125
def test_upload_build_with_empty_directory(self):
126
cmdline = self.prefix
127
cmdline += ' --name mybuild --build-version myversion'
128
cmdline += ' --build-root %s' % self.files.rootdir
129
130
self.parsed_responses = [
131
{'Build': {'BuildId': 'myid'}},
132
{'StorageLocation': {
133
'Bucket': 'mybucket',
134
'Key': 'mykey'},
135
'UploadCredentials': {
136
'AccessKeyId': 'myaccesskey',
137
'SecretAccessKey': 'mysecretkey',
138
'SessionToken': 'mytoken'}},
139
{}
140
]
141
142
stdout, stderr, rc = self.run_cmd(cmdline, expected_rc=255)
143
144
self.assertIn(
145
'Fail to upload %s. '
146
'The build root directory is empty or does not exist.\n'
147
% self.files.rootdir,
148
stderr)
149
150
def test_upload_build_with_nonexistent_directory(self):
151
dir_not_exist = os.path.join(self.files.rootdir, 'does_not_exist')
152
153
cmdline = self.prefix
154
cmdline += ' --name mybuild --build-version myversion'
155
cmdline += ' --build-root %s' % dir_not_exist
156
157
self.parsed_responses = [
158
{'Build': {'BuildId': 'myid'}},
159
{'StorageLocation': {
160
'Bucket': 'mybucket',
161
'Key': 'mykey'},
162
'UploadCredentials': {
163
'AccessKeyId': 'myaccesskey',
164
'SecretAccessKey': 'mysecretkey',
165
'SessionToken': 'mytoken'}},
166
{}
167
]
168
169
stdout, stderr, rc = self.run_cmd(cmdline, expected_rc=255)
170
171
self.assertIn(
172
'Fail to upload %s. '
173
'The build root directory is empty or does not exist.\n'
174
% dir_not_exist,
175
stderr)
176
177
def test_upload_build_with_nonprovided_directory(self):
178
cmdline = self.prefix
179
cmdline += ' --name mybuild --build-version myversion'
180
cmdline += ' --build-root %s' % '""'
181
182
self.parsed_responses = [
183
{'Build': {'BuildId': 'myid'}},
184
{'StorageLocation': {
185
'Bucket': 'mybucket',
186
'Key': 'mykey'},
187
'UploadCredentials': {
188
'AccessKeyId': 'myaccesskey',
189
'SecretAccessKey': 'mysecretkey',
190
'SessionToken': 'mytoken'}},
191
{}
192
]
193
194
stdout, stderr, rc = self.run_cmd(cmdline, expected_rc=255)
195
196
self.assertIn(
197
'Fail to upload %s. '
198
'The build root directory is empty or does not exist.\n'
199
% '""',
200
stderr)
201
202
def test_upload_build_with_server_sdk_version_param(self):
203
self.files.create_file('tmpfile', 'Some contents')
204
cmdline = self.prefix
205
cmdline += ' --name mybuild --build-version myversion'
206
cmdline += ' --build-root %s' % self.files.rootdir
207
cmdline += ' --server-sdk-version 4.0.2'
208
209
self.parsed_responses = [
210
{'Build': {'BuildId': 'myid'}},
211
{'StorageLocation': {
212
'Bucket': 'mybucket',
213
'Key': 'mykey'},
214
'UploadCredentials': {
215
'AccessKeyId': 'myaccesskey',
216
'SecretAccessKey': 'mysecretkey',
217
'SessionToken': 'mytoken'}},
218
{}
219
]
220
221
stdout, stderr, rc = self.run_cmd(cmdline, expected_rc=0)
222
223
# First the build is created.
224
self.assertEqual(len(self.operations_called), 3)
225
self.assertEqual(self.operations_called[0][0].name, 'CreateBuild')
226
self.assertEqual(
227
self.operations_called[0][1],
228
{'Name': 'mybuild', 'Version': 'myversion',
229
'ServerSdkVersion': '4.0.2'}
230
)
231
232
# Second the credentials are requested.
233
self.assertEqual(
234
self.operations_called[1][0].name, 'RequestUploadCredentials')
235
self.assertEqual(
236
self.operations_called[1][1], {'BuildId': 'myid'})
237
238
# The build is then uploaded to S3.
239
self.assertEqual(self.operations_called[2][0].name, 'PutObject')
240
self.assertEqual(
241
self.operations_called[2][1],
242
{'Body': mock.ANY, 'Bucket': 'mybucket', 'Key': 'mykey'}
243
)
244
245
# Check the output of the command.
246
self.assertIn(
247
'Successfully uploaded %s to AWS GameLift' % self.files.rootdir,
248
stdout)
249
self.assertIn('Build ID: myid', stdout)
250
251