Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/unit/customizations/gamelift/test_getlog.py
1569 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
from argparse import Namespace
14
import os
15
16
from botocore.session import get_session
17
18
from awscli.testutils import unittest, mock, FileCreator
19
from awscli.customizations.gamelift.getlog import GetGameSessionLogCommand
20
from awscli.compat import BytesIO
21
22
23
class TestGetGameSessionLogCommand(unittest.TestCase):
24
def setUp(self):
25
self.create_client_patch = mock.patch(
26
'botocore.session.Session.create_client')
27
self.mock_create_client = self.create_client_patch.start()
28
self.session = get_session()
29
30
self.client = mock.Mock()
31
self.mock_create_client.return_value = self.client
32
33
self.cmd = GetGameSessionLogCommand(self.session)
34
35
self.contents = b'mycontents'
36
self.file_creator = FileCreator()
37
self.urlopen_patch = mock.patch(
38
'awscli.customizations.gamelift.getlog.urlopen')
39
self.urlopen_mock = self.urlopen_patch.start()
40
self.urlopen_mock.return_value = BytesIO(self.contents)
41
42
def tearDown(self):
43
self.create_client_patch.stop()
44
self.file_creator.remove_all()
45
self.urlopen_patch.stop()
46
47
def test_get_game_session_log(self):
48
session_id = 'mysessionid'
49
save_as = os.path.join(self.file_creator.rootdir, 'mylog')
50
51
args = [
52
'--game-session-id', session_id,
53
'--save-as', save_as
54
]
55
global_args = Namespace()
56
global_args.region = 'us-west-2'
57
global_args.endpoint_url = None
58
global_args.verify_ssl = None
59
60
presigned_url = 'mypresignedurl'
61
self.client.get_game_session_log_url.return_value = {
62
'PreSignedUrl': presigned_url
63
}
64
65
# Call the command
66
self.cmd(args, global_args)
67
68
# Ensure the client was created properly
69
self.mock_create_client.assert_called_once_with(
70
'gamelift', region_name='us-west-2', endpoint_url=None,
71
verify=None
72
)
73
74
# Ensure the client was called correctly
75
self.client.get_game_session_log_url.assert_called_once_with(
76
GameSessionId=session_id)
77
78
# Ensure the presigned url was used
79
self.urlopen_mock.assert_called_once_with(presigned_url)
80
81
# Ensure the contents were saved to the file
82
with open(save_as, 'rb') as f:
83
self.assertEqual(f.read(), self.contents)
84
85