Browse Source

Fix service_type normalization

The previous version of the function would fail poorly when service_type
is None. Put in an if to fix it.

Change-Id: Ibbeee913afc463705fe781c2ef0918deb1303617
Story: 2003314
Monty Taylor 8 months ago
parent
commit
e11dc0f670
No account linked to committer's email address
2 changed files with 34 additions and 1 deletions
  1. 2
    1
      os_service_types/service_types.py
  2. 32
    0
      os_service_types/tests/test_misc.py

+ 2
- 1
os_service_types/service_types.py View File

@@ -24,7 +24,8 @@ SERVICE_TYPES_URL = "https://service-types.openstack.org/service-types.json"
24 24
 
25 25
 
26 26
 def _normalize_type(service_type):
27
-    return service_type.replace('_', '-')
27
+    if service_type:
28
+        return service_type.replace('_', '-')
28 29
 
29 30
 
30 31
 class ServiceTypes(object):

+ 32
- 0
os_service_types/tests/test_misc.py View File

@@ -0,0 +1,32 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+# not use this file except in compliance with the License. You may obtain
5
+# a copy of the License at
6
+#
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, WITHOUT
11
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+# License for the specific language governing permissions and limitations
13
+# under the License.
14
+
15
+"""
16
+test_misc
17
+---------
18
+
19
+Miscellaneous tests
20
+"""
21
+
22
+from os_service_types import service_types
23
+from os_service_types.tests import base
24
+
25
+
26
+class TestMisc(base.TestCase):
27
+
28
+    def test_normalize(self):
29
+        self.assertEqual('foo-bar', service_types._normalize_type('foo_bar'))
30
+
31
+    def test_normalize_none(self):
32
+        self.assertIsNone(service_types._normalize_type(None))

Loading…
Cancel
Save