"Fossies" - the Fresh Open Source Software Archive

Member "ec2-api-12.0.0/ec2api/tests/unit/test_availability_zone.py" (14 Apr 2021, 4444 Bytes) of package /linux/misc/openstack/ec2-api-12.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "test_availability_zone.py": 9.0.0_vs_10.0.0.

    1 # Copyright 2014
    2 # The Cloudscaling Group, Inc.
    3 #
    4 # Licensed under the Apache License, Version 2.0 (the "License");
    5 # you may not use this file except in compliance with the License.
    6 # You may obtain a copy of the License at
    7 # http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 # Unless required by applicable law or agreed to in writing, software
   10 # distributed under the License is distributed on an "AS IS" BASIS,
   11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   12 # See the License for the specific language governing permissions and
   13 # limitations under the License.
   14 
   15 from unittest import mock
   16 
   17 from ec2api.tests.unit import base
   18 from ec2api.tests.unit import fakes
   19 from ec2api.tests.unit import matchers
   20 
   21 
   22 class AvailabilityZoneCase(base.ApiTestCase):
   23 
   24     def setUp(self):
   25         super(AvailabilityZoneCase, self).setUp()
   26 
   27     def test_describe_availability_zones(self):
   28         self.nova.availability_zones.list.return_value = [
   29             fakes.NovaAvailabilityZone(fakes.OS_AVAILABILITY_ZONE),
   30             fakes.NovaAvailabilityZone(fakes.OS_AVAILABILITY_ZONE_INTERNAL)]
   31         resp = self.execute('DescribeAvailabilityZones', {})
   32         self.assertThat(resp['availabilityZoneInfo'],
   33                         matchers.ListMatches([fakes.EC2_AVAILABILITY_ZONE]))
   34         self.nova.availability_zones.list.assert_called_once_with(
   35             detailed=False)
   36 
   37         self.check_filtering(
   38             'DescribeAvailabilityZones', 'availabilityZoneInfo',
   39             [('state', 'available'),
   40              ('zone-name', fakes.NAME_AVAILABILITY_ZONE)])
   41 
   42     def test_describe_availability_zones_verbose(self):
   43         self.nova.availability_zones.list.return_value = [
   44             fakes.NovaAvailabilityZone(fakes.OS_AVAILABILITY_ZONE),
   45             fakes.NovaAvailabilityZone(fakes.OS_AVAILABILITY_ZONE_INTERNAL)]
   46         resp = self.execute('DescribeAvailabilityZones',
   47                             {'zoneName.1': 'verbose'})
   48         self.assertEqual(len(resp['availabilityZoneInfo']), 7)
   49         self.nova.availability_zones.list.assert_called_once_with()
   50 
   51     def test_regions(self):
   52         resp = self.execute('DescribeRegions', {})
   53         self.assertEqual(resp['regionInfo'][0]['regionName'], 'RegionOne')
   54         self.assertTrue(resp['regionInfo'][0].get('regionEndpoint')
   55                         is not None)
   56 
   57     @mock.patch('ec2api.api.ec2utils.check_and_create_default_vpc')
   58     def test_describe_account_attributes(self, check_and_create):
   59         self.nova.quotas.get.return_value = mock.Mock(instances=77)
   60 
   61         resp = self.execute('DescribeAccountAttributes', {})
   62         self.assertThat(resp['accountAttributeSet'],
   63                         matchers.ListMatches(
   64                             [{'attributeName': 'supported-platforms',
   65                               'attributeValueSet': [
   66                                   {'attributeValue': 'EC2'},
   67                                   {'attributeValue': 'VPC'}]},
   68                              {'attributeName': 'default-vpc',
   69                               'attributeValueSet': [
   70                                   {'attributeValue': 'none'}]},
   71                              {'attributeName': 'max-instances',
   72                               'attributeValueSet': [
   73                                   {'attributeValue': 77}]}],
   74                             orderless_lists=True))
   75         self.nova.quotas.get.assert_called_once_with(
   76             fakes.ID_OS_PROJECT, fakes.ID_OS_USER)
   77 
   78         self.configure(disable_ec2_classic=True)
   79         check_and_create.return_value = fakes.DB_VPC_DEFAULT
   80 
   81         resp = self.execute('DescribeAccountAttributes', {})
   82         self.assertThat(resp['accountAttributeSet'],
   83                         matchers.ListMatches(
   84                             [{'attributeName': 'supported-platforms',
   85                               'attributeValueSet': [
   86                                   {'attributeValue': 'VPC'}]},
   87                              {'attributeName': 'default-vpc',
   88                               'attributeValueSet': [
   89                                   {'attributeValue':
   90                                    fakes.ID_EC2_VPC_DEFAULT}]},
   91                              {'attributeName': 'max-instances',
   92                               'attributeValueSet': [
   93                                   {'attributeValue': 77}]}],
   94                             orderless_lists=True))
   95         check_and_create.assert_called_once_with(mock.ANY)