Fix error in resource_help and add UT
The func should be used in the condition of 'policies to policy' Add test UT in test_resource_helper Change-Id: I41fa8b0b029398ea9c3977fabd649a094a9538ac
This commit is contained in:
parent
a3670e4b68
commit
f9414c99e8
@ -30,7 +30,12 @@ def build_plural_mappings(special_mappings, resource_map):
|
|||||||
"""
|
"""
|
||||||
plural_mappings = {}
|
plural_mappings = {}
|
||||||
for plural in resource_map:
|
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
|
plural_mappings[plural] = singular
|
||||||
return plural_mappings
|
return plural_mappings
|
||||||
|
|
||||||
|
61
tacker/tests/unit/api/v1/test_resource_helper.py
Normal file
61
tacker/tests/unit/api/v1/test_resource_helper.py
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user