Path: blob/develop/tests/functional/gamelift/test_get_game_session_log.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 os1314from awscli.testutils import BaseAWSCommandParamsTest, FileCreator, mock15from awscli.compat import BytesIO161718class TestGetGameSessionLog(BaseAWSCommandParamsTest):1920prefix = 'gamelift get-game-session-log'2122def setUp(self):23super(TestGetGameSessionLog, self).setUp()24self.files = FileCreator()25self.filename = os.path.join(self.files.rootdir, 'myfile')26self.urlopen_patch = mock.patch(27'awscli.customizations.gamelift.getlog.urlopen')28self.contents = b'My Contents'29self.urlopen_mock = self.urlopen_patch.start()30self.urlopen_mock.return_value = BytesIO(self.contents)3132def tearDown(self):33super(TestGetGameSessionLog, self).tearDown()34self.files.remove_all()35self.urlopen_patch.stop()3637def test_get_game_session_log(self):38cmdline = self.prefix39cmdline += ' --game-session-id mysession'40cmdline += ' --save-as %s' % self.filename4142self.parsed_responses = [{'PreSignedUrl': 'myurl'}]43stdout, stderr, rc = self.run_cmd(cmdline, expected_rc=0)44self.assertEqual(len(self.operations_called), 1)45self.assertEqual(46self.operations_called[0][0].name, 'GetGameSessionLogUrl')47self.assertEqual(48self.operations_called[0][1],49{'GameSessionId': 'mysession'}50)5152# Ensure the contents were saved to the file53self.assertTrue(os.path.exists(self.filename))54with open(self.filename, 'rb') as f:55self.assertEqual(f.read(), self.contents)5657# Ensure the output is as expected58self.assertIn(59'Successfully downloaded log archive for game session '60'mysession to %s' % self.filename,61stdout62)636465