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.
13import os
14
15from tests import mock
16from tests import unittest
17
18import botocore.session
19
20
21# Basic sanity checks for loader functionality.
22# We're not using BaseEnvVar here because we don't actually
23# want to patch out all of os.environ, we just want to ensure
24# AWS_DATA_PATH doesn't affect our test results.
25class TestLoaderBasicFunctionality(unittest.TestCase):
26    def setUp(self):
27        self.environ = os.environ.copy()
28        self.patched = mock.patch('os.environ', self.environ)
29        self.patched.start()
30        self.environ.pop('AWS_DATA_PATH', None)
31
32        self.session = botocore.session.get_session()
33        self.loader = self.session.get_component('data_loader')
34
35    def tearDown(self):
36        self.patched.stop()
37
38    def test_search_path_has_at_least_one_entry(self):
39        self.assertTrue(len(self.loader.search_paths) > 0)
40
41    def test_can_list_available_services(self):
42        # We don't want an exact check, as this list changes over time.
43        # We just need a basic sanity check.
44        available_services = self.loader.list_available_services(
45            type_name='service-2')
46        self.assertIn('ec2', available_services)
47        self.assertIn('s3', available_services)
48
49    def test_can_determine_latest_version(self):
50        api_versions = self.loader.list_api_versions(
51            service_name='ec2', type_name='service-2')
52        self.assertEqual(
53            self.loader.determine_latest_version(
54                service_name='ec2', type_name='service-2'),
55            max(api_versions))
56
57    def test_can_load_service_model(self):
58        waiters = self.loader.load_service_model(
59            service_name='ec2', type_name='waiters-2')
60        self.assertIn('waiters', waiters)
61
62    def test_can_load_data(self):
63        api_version = self.loader.determine_latest_version(
64            service_name='ec2', type_name='service-2')
65        data = self.loader.load_data(
66            os.path.join('ec2', api_version, 'service-2'))
67        self.assertIn('metadata', data)
68