Path: blob/develop/tests/functional/gamelift/test_upload_build.py
1567 views
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.1#2# Licensed under the Apache License, Version 2.0 (the "License"). You3# may not use this file except in compliance with the License. A copy of4# the License is located at5#6# http://aws.amazon.com/apache2.0/7#8# or in the "license" file accompanying this file. This file is9# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF10# ANY KIND, either express or implied. See the License for the specific11# language governing permissions and limitations under the License.12import os13from awscli.testutils import BaseAWSCommandParamsTest, FileCreator, mock141516class TestUploadBuild(BaseAWSCommandParamsTest):1718prefix = 'gamelift upload-build'1920def setUp(self):21super(TestUploadBuild, self).setUp()22self.files = FileCreator()2324def tearDown(self):25super(TestUploadBuild, self).tearDown()26self.files.remove_all()2728def test_upload_build(self):29self.files.create_file('tmpfile', 'Some contents')30cmdline = self.prefix31cmdline += ' --name mybuild --build-version myversion'32cmdline += ' --build-root %s' % self.files.rootdir3334self.parsed_responses = [35{'Build': {'BuildId': 'myid'}},36{'StorageLocation': {37'Bucket': 'mybucket',38'Key': 'mykey'},39'UploadCredentials': {40'AccessKeyId': 'myaccesskey',41'SecretAccessKey': 'mysecretkey',42'SessionToken': 'mytoken'}},43{}44]4546stdout, stderr, rc = self.run_cmd(cmdline, expected_rc=0)4748# First the build is created.49self.assertEqual(len(self.operations_called), 3)50self.assertEqual(self.operations_called[0][0].name, 'CreateBuild')51self.assertEqual(52self.operations_called[0][1],53{'Name': 'mybuild', 'Version': 'myversion'}54)5556# Second the credentials are requested.57self.assertEqual(58self.operations_called[1][0].name, 'RequestUploadCredentials')59self.assertEqual(60self.operations_called[1][1], {'BuildId': 'myid'})6162# The build is then uploaded to S3.63self.assertEqual(self.operations_called[2][0].name, 'PutObject')64self.assertEqual(65self.operations_called[2][1],66{'Body': mock.ANY, 'Bucket': 'mybucket', 'Key': 'mykey'}67)6869# Check the output of the command.70self.assertIn(71'Successfully uploaded %s to AWS GameLift' % self.files.rootdir,72stdout)73self.assertIn('Build ID: myid', stdout)7475def test_upload_build_with_operating_system_param(self):76self.files.create_file('tmpfile', 'Some contents')77cmdline = self.prefix78cmdline += ' --name mybuild --build-version myversion'79cmdline += ' --build-root %s' % self.files.rootdir80cmdline += ' --operating-system WINDOWS_2012'8182self.parsed_responses = [83{'Build': {'BuildId': 'myid'}},84{'StorageLocation': {85'Bucket': 'mybucket',86'Key': 'mykey'},87'UploadCredentials': {88'AccessKeyId': 'myaccesskey',89'SecretAccessKey': 'mysecretkey',90'SessionToken': 'mytoken'}},91{}92]9394stdout, stderr, rc = self.run_cmd(cmdline, expected_rc=0)9596# First the build is created.97self.assertEqual(len(self.operations_called), 3)98self.assertEqual(self.operations_called[0][0].name, 'CreateBuild')99self.assertEqual(100self.operations_called[0][1],101{'Name': 'mybuild', 'Version': 'myversion',102'OperatingSystem': 'WINDOWS_2012'}103)104105# Second the credentials are requested.106self.assertEqual(107self.operations_called[1][0].name, 'RequestUploadCredentials')108self.assertEqual(109self.operations_called[1][1], {'BuildId': 'myid'})110111# The build is then uploaded to S3.112self.assertEqual(self.operations_called[2][0].name, 'PutObject')113self.assertEqual(114self.operations_called[2][1],115{'Body': mock.ANY, 'Bucket': 'mybucket', 'Key': 'mykey'}116)117118# Check the output of the command.119self.assertIn(120'Successfully uploaded %s to AWS GameLift' % self.files.rootdir,121stdout)122self.assertIn('Build ID: myid', stdout)123124def test_upload_build_with_empty_directory(self):125cmdline = self.prefix126cmdline += ' --name mybuild --build-version myversion'127cmdline += ' --build-root %s' % self.files.rootdir128129self.parsed_responses = [130{'Build': {'BuildId': 'myid'}},131{'StorageLocation': {132'Bucket': 'mybucket',133'Key': 'mykey'},134'UploadCredentials': {135'AccessKeyId': 'myaccesskey',136'SecretAccessKey': 'mysecretkey',137'SessionToken': 'mytoken'}},138{}139]140141stdout, stderr, rc = self.run_cmd(cmdline, expected_rc=255)142143self.assertIn(144'Fail to upload %s. '145'The build root directory is empty or does not exist.\n'146% self.files.rootdir,147stderr)148149def test_upload_build_with_nonexistent_directory(self):150dir_not_exist = os.path.join(self.files.rootdir, 'does_not_exist')151152cmdline = self.prefix153cmdline += ' --name mybuild --build-version myversion'154cmdline += ' --build-root %s' % dir_not_exist155156self.parsed_responses = [157{'Build': {'BuildId': 'myid'}},158{'StorageLocation': {159'Bucket': 'mybucket',160'Key': 'mykey'},161'UploadCredentials': {162'AccessKeyId': 'myaccesskey',163'SecretAccessKey': 'mysecretkey',164'SessionToken': 'mytoken'}},165{}166]167168stdout, stderr, rc = self.run_cmd(cmdline, expected_rc=255)169170self.assertIn(171'Fail to upload %s. '172'The build root directory is empty or does not exist.\n'173% dir_not_exist,174stderr)175176def test_upload_build_with_nonprovided_directory(self):177cmdline = self.prefix178cmdline += ' --name mybuild --build-version myversion'179cmdline += ' --build-root %s' % '""'180181self.parsed_responses = [182{'Build': {'BuildId': 'myid'}},183{'StorageLocation': {184'Bucket': 'mybucket',185'Key': 'mykey'},186'UploadCredentials': {187'AccessKeyId': 'myaccesskey',188'SecretAccessKey': 'mysecretkey',189'SessionToken': 'mytoken'}},190{}191]192193stdout, stderr, rc = self.run_cmd(cmdline, expected_rc=255)194195self.assertIn(196'Fail to upload %s. '197'The build root directory is empty or does not exist.\n'198% '""',199stderr)200201def test_upload_build_with_server_sdk_version_param(self):202self.files.create_file('tmpfile', 'Some contents')203cmdline = self.prefix204cmdline += ' --name mybuild --build-version myversion'205cmdline += ' --build-root %s' % self.files.rootdir206cmdline += ' --server-sdk-version 4.0.2'207208self.parsed_responses = [209{'Build': {'BuildId': 'myid'}},210{'StorageLocation': {211'Bucket': 'mybucket',212'Key': 'mykey'},213'UploadCredentials': {214'AccessKeyId': 'myaccesskey',215'SecretAccessKey': 'mysecretkey',216'SessionToken': 'mytoken'}},217{}218]219220stdout, stderr, rc = self.run_cmd(cmdline, expected_rc=0)221222# First the build is created.223self.assertEqual(len(self.operations_called), 3)224self.assertEqual(self.operations_called[0][0].name, 'CreateBuild')225self.assertEqual(226self.operations_called[0][1],227{'Name': 'mybuild', 'Version': 'myversion',228'ServerSdkVersion': '4.0.2'}229)230231# Second the credentials are requested.232self.assertEqual(233self.operations_called[1][0].name, 'RequestUploadCredentials')234self.assertEqual(235self.operations_called[1][1], {'BuildId': 'myid'})236237# The build is then uploaded to S3.238self.assertEqual(self.operations_called[2][0].name, 'PutObject')239self.assertEqual(240self.operations_called[2][1],241{'Body': mock.ANY, 'Bucket': 'mybucket', 'Key': 'mykey'}242)243244# Check the output of the command.245self.assertIn(246'Successfully uploaded %s to AWS GameLift' % self.files.rootdir,247stdout)248self.assertIn('Build ID: myid', stdout)249250251