Add unit test case for fm-rest-api/fm/fm/common/utils.py

Add test case FaultUtilsTestCase.
Add fake log in tests/base.py.

Story: 2007082
Task: 38093
Task: 38084

Depends-on: https://review.opendev.org/#/c/702175/
Change-Id: I560415ed1519834c21f0090f594f2da6c26f3eca
Signed-off-by: chenyan <yan.chen@intel.com>
This commit is contained in:
chenyan 2020-01-14 14:06:44 +08:00 committed by SidneyAn
parent 385f274a8f
commit 2f37da8e8e
6 changed files with 43 additions and 6 deletions

View File

@ -59,6 +59,8 @@
description: |
Run py27 test for fm-rest-api
nodeset: ubuntu-xenial
required-projects:
- starlingx/config
vars:
tox_envlist: py27
tox_extra_args: -c fm-rest-api/fm/tox.ini
@ -69,6 +71,8 @@
description: |
Run py35 test for fm-rest-api
nodeset: ubuntu-xenial
required-projects:
- starlingx/config
vars:
tox_envlist: py35
tox_extra_args: -c fm-rest-api/fm/tox.ini

View File

@ -19,8 +19,14 @@ Allows overriding of config for use of fakes, and some black magic for
inline callbacks.
"""
import fixtures
import testtools
from oslo_config import cfg
from oslo_log import log as logging
CONF = cfg.CONF
class TestCase(testtools.TestCase):
"""Test case base class for all unit tests."""
@ -29,5 +35,12 @@ class TestCase(testtools.TestCase):
"""Run before each test method to initialize test environment."""
super(TestCase, self).setUp()
def fake_logging_setup(*args):
pass
self.useFixture(
fixtures.MonkeyPatch('oslo_log.log.setup', fake_logging_setup))
logging.register_options(CONF)
def tearDown(self):
super(TestCase, self).tearDown()

View File

@ -15,6 +15,7 @@
import datetime
from fm.common import timeutils
from fm.common import utils
from fm.tests import base
@ -32,3 +33,24 @@ class FaultTimeUtilsTestCase(base.TestCase):
self.assertRaises(ValueError, timeutils.parse_isotime, "bad input")
self.assertRaises(ValueError, timeutils.parse_isotime, isotime)
class FaultUtilsTestCase(base.TestCase):
def test_generate_uuid(self):
uuid = utils.generate_uuid()
self.assertTrue(isinstance(uuid, str))
def test_safe_rstrip(self):
input_int = 1
self.assertEqual(input_int, utils.safe_rstrip(input_int))
input_str = "string input"
self.assertEqual(input_str, utils.safe_rstrip(input_str))
input_str = "string to strip \r\n\t"
output_str = "string to strip"
self.assertEqual(output_str, utils.safe_rstrip(input_str))
input_str = "string to strip ssss"
output_str = "string to strip"
self.assertEqual(output_str, utils.safe_rstrip(input_str, "s "))

View File

@ -8,3 +8,6 @@ iso8601
stestr
mock
cython
oslo.log
oslo.concurrency

View File

@ -11,6 +11,7 @@ setenv = VIRTUAL_ENV={envdir}
OS_STDERR_CAPTURE=1
OS_TEST_TIMEOUT=60
deps = -r{toxinidir}/test-requirements.txt
-e{[tox]stxdir}/config/tsconfig/tsconfig
[testenv:venv]
basepython = python3

View File

@ -3,9 +3,3 @@ bashate >= 0.2
PyYAML >= 3.1.0
yamllint >= 0.5.2
#spec_cleaner>=1.0.9
stestr
testtools!=1.2.0,>=0.9.36
iso8601
stestr
mock
cython