Path: blob/develop/tests/unit/customizations/gamelift/test_getlog.py
1569 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.12from argparse import Namespace13import os1415from botocore.session import get_session1617from awscli.testutils import unittest, mock, FileCreator18from awscli.customizations.gamelift.getlog import GetGameSessionLogCommand19from awscli.compat import BytesIO202122class TestGetGameSessionLogCommand(unittest.TestCase):23def setUp(self):24self.create_client_patch = mock.patch(25'botocore.session.Session.create_client')26self.mock_create_client = self.create_client_patch.start()27self.session = get_session()2829self.client = mock.Mock()30self.mock_create_client.return_value = self.client3132self.cmd = GetGameSessionLogCommand(self.session)3334self.contents = b'mycontents'35self.file_creator = FileCreator()36self.urlopen_patch = mock.patch(37'awscli.customizations.gamelift.getlog.urlopen')38self.urlopen_mock = self.urlopen_patch.start()39self.urlopen_mock.return_value = BytesIO(self.contents)4041def tearDown(self):42self.create_client_patch.stop()43self.file_creator.remove_all()44self.urlopen_patch.stop()4546def test_get_game_session_log(self):47session_id = 'mysessionid'48save_as = os.path.join(self.file_creator.rootdir, 'mylog')4950args = [51'--game-session-id', session_id,52'--save-as', save_as53]54global_args = Namespace()55global_args.region = 'us-west-2'56global_args.endpoint_url = None57global_args.verify_ssl = None5859presigned_url = 'mypresignedurl'60self.client.get_game_session_log_url.return_value = {61'PreSignedUrl': presigned_url62}6364# Call the command65self.cmd(args, global_args)6667# Ensure the client was created properly68self.mock_create_client.assert_called_once_with(69'gamelift', region_name='us-west-2', endpoint_url=None,70verify=None71)7273# Ensure the client was called correctly74self.client.get_game_session_log_url.assert_called_once_with(75GameSessionId=session_id)7677# Ensure the presigned url was used78self.urlopen_mock.assert_called_once_with(presigned_url)7980# Ensure the contents were saved to the file81with open(save_as, 'rb') as f:82self.assertEqual(f.read(), self.contents)838485