Path: blob/develop/tests/unit/customizations/cloudtrail/test_utils.py
1569 views
# Copyright 2013 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 awscli.customizations.cloudtrail import utils13from awscli.testutils import mock, unittest141516class TestCloudTrailUtils(unittest.TestCase):17def test_gets_sts_account_id(self):18mock_sts_client = mock.Mock()19user_info = {'Account': '1234'}20mock_sts_client.get_caller_identity.return_value = user_info21account_id = utils.get_account_id(mock_sts_client)22self.assertEqual(account_id, '1234')2324def test_gets_account_id_from_arn(self):25arn = 'foo:bar:baz:qux:1234'26self.assertEqual('1234', utils.get_account_id_from_arn(arn))2728def test_gets_trail_by_arn(self):29cloudtrail_client = mock.Mock()30cloudtrail_client.describe_trails.return_value = {'trailList': [31{'TrailARN': 'a', 'Foo': 'Baz'},32{'TrailARN': 'b', 'Foo': 'Bar'}33]}34result = utils.get_trail_by_arn(cloudtrail_client, 'b')35self.assertEqual('Bar', result['Foo'])3637def test_throws_when_unable_to_get_trail_by_arn(self):38cloudtrail_client = mock.Mock()39cloudtrail_client.describe_trails.return_value = {'trailList': []}40self.assertRaises(41ValueError, utils.get_trail_by_arn, cloudtrail_client, 'b')424344