| 1 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 |
# not use this file except in compliance with the License. You may obtain |
| 3 |
# a copy of the License at |
| 4 |
# |
| 5 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 |
# |
| 7 |
# Unless required by applicable law or agreed to in writing, software |
| 8 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 |
# License for the specific language governing permissions and limitations |
| 11 |
# under the License. |
| 12 |
|
| 13 |
from unittest import mock |
| 14 |
|
| 15 |
from neutron_lib.api.validators import availability_zone as az_validator |
| 16 |
from neutron_lib.db import constants as db_const |
| 17 |
from neutron_lib import exceptions |
| 18 |
from neutron_lib.tests import _base as base |
| 19 |
|
| 20 |
|
| 21 |
class TestAvailabilityZoneValidator(base.BaseTestCase): |
| 22 |
|
| 23 |
@mock.patch.object(az_validator.validators, |
| 24 |
'validate_list_of_unique_strings', |
| 25 |
return_value='bad') |
| 26 |
def test__validate_availability_zone_hints_unique_strings( |
| 27 |
self, mock_unique_strs): |
| 28 |
self.assertEqual( |
| 29 |
'bad', az_validator._validate_availability_zone_hints(['a', 'a'])) |
| 30 |
|
| 31 |
def test__validate_availability_zone_hints_excessive_len(self): |
| 32 |
self.assertRaisesRegex( |
| 33 |
exceptions.InvalidInput, 'Too many availability_zone_hints', |
| 34 |
az_validator._validate_availability_zone_hints, |
| 35 |
['a' * (db_const.AZ_HINTS_DB_LEN + 1)]) |
| 36 |
|
| 37 |
def test__validate_availability_zone_hints_valid_input(self): |
| 38 |
self.assertIsNone( |
| 39 |
az_validator._validate_availability_zone_hints(['a', 'b', 'c'])) |