diff --git a/tacker/api/v1/resource_helper.py b/tacker/api/v1/resource_helper.py index 0f1c482e1..3390d4dad 100644 --- a/tacker/api/v1/resource_helper.py +++ b/tacker/api/v1/resource_helper.py @@ -30,7 +30,12 @@ def build_plural_mappings(special_mappings, resource_map): """ plural_mappings = {} for plural in resource_map: - singular = special_mappings.get(plural, plural[:-1]) + singular = special_mappings.get(plural) + if not singular: + if plural.endswith('ies'): + singular = "%sy" % plural[:-3] + else: + singular = plural[:-1] plural_mappings[plural] = singular return plural_mappings diff --git a/tacker/tests/unit/api/v1/test_resource_helper.py b/tacker/tests/unit/api/v1/test_resource_helper.py new file mode 100644 index 000000000..026823f5f --- /dev/null +++ b/tacker/tests/unit/api/v1/test_resource_helper.py @@ -0,0 +1,61 @@ +# Copyright (c) 2014-2018 China Mobile (SuZhou) Software Technology Co.,Ltd. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from tacker.api.v1.resource_helper import build_plural_mappings +from tacker.tests import base + + +class ResourceHelperTestCase(base.BaseTestCase): + + def test_build_plural_mappings(self): + special_mappings = {} + resource_map = { + 'vims': { + 'id': { + 'allow_post': False, + 'allow_put': False, + } + }, + 'vnffgs': { + 'id': { + 'allow_post': False, + 'allow_put': False, + } + }, + } + + expected_res = {'vnffgs': 'vnffg', 'vims': 'vim'} + result = build_plural_mappings(special_mappings, resource_map) + self.assertEqual(expected_res, result) + + def test_build_plural_mappings_with_suffix_y(self): + special_mappings = {} + resource_map = { + 'policies': { + 'id': { + 'allow_post': False, + } + }, + 'vnffgs': { + 'id': { + 'allow_post': False, + 'allow_put': False, + } + }, + } + + expected_res = {'vnffgs': 'vnffg', 'policies': 'policy'} + result = build_plural_mappings(special_mappings, resource_map) + self.assertEqual(expected_res, result)