Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/functional/gamelift/test_get_game_session_log.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
15
from awscli.testutils import BaseAWSCommandParamsTest, FileCreator, mock
16
from awscli.compat import BytesIO
17
18
19
class TestGetGameSessionLog(BaseAWSCommandParamsTest):
20
21
prefix = 'gamelift get-game-session-log'
22
23
def setUp(self):
24
super(TestGetGameSessionLog, self).setUp()
25
self.files = FileCreator()
26
self.filename = os.path.join(self.files.rootdir, 'myfile')
27
self.urlopen_patch = mock.patch(
28
'awscli.customizations.gamelift.getlog.urlopen')
29
self.contents = b'My Contents'
30
self.urlopen_mock = self.urlopen_patch.start()
31
self.urlopen_mock.return_value = BytesIO(self.contents)
32
33
def tearDown(self):
34
super(TestGetGameSessionLog, self).tearDown()
35
self.files.remove_all()
36
self.urlopen_patch.stop()
37
38
def test_get_game_session_log(self):
39
cmdline = self.prefix
40
cmdline += ' --game-session-id mysession'
41
cmdline += ' --save-as %s' % self.filename
42
43
self.parsed_responses = [{'PreSignedUrl': 'myurl'}]
44
stdout, stderr, rc = self.run_cmd(cmdline, expected_rc=0)
45
self.assertEqual(len(self.operations_called), 1)
46
self.assertEqual(
47
self.operations_called[0][0].name, 'GetGameSessionLogUrl')
48
self.assertEqual(
49
self.operations_called[0][1],
50
{'GameSessionId': 'mysession'}
51
)
52
53
# Ensure the contents were saved to the file
54
self.assertTrue(os.path.exists(self.filename))
55
with open(self.filename, 'rb') as f:
56
self.assertEqual(f.read(), self.contents)
57
58
# Ensure the output is as expected
59
self.assertIn(
60
'Successfully downloaded log archive for game session '
61
'mysession to %s' % self.filename,
62
stdout
63
)
64
65