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:
parent
385f274a8f
commit
2f37da8e8e
@ -59,6 +59,8 @@
|
|||||||
description: |
|
description: |
|
||||||
Run py27 test for fm-rest-api
|
Run py27 test for fm-rest-api
|
||||||
nodeset: ubuntu-xenial
|
nodeset: ubuntu-xenial
|
||||||
|
required-projects:
|
||||||
|
- starlingx/config
|
||||||
vars:
|
vars:
|
||||||
tox_envlist: py27
|
tox_envlist: py27
|
||||||
tox_extra_args: -c fm-rest-api/fm/tox.ini
|
tox_extra_args: -c fm-rest-api/fm/tox.ini
|
||||||
@ -69,6 +71,8 @@
|
|||||||
description: |
|
description: |
|
||||||
Run py35 test for fm-rest-api
|
Run py35 test for fm-rest-api
|
||||||
nodeset: ubuntu-xenial
|
nodeset: ubuntu-xenial
|
||||||
|
required-projects:
|
||||||
|
- starlingx/config
|
||||||
vars:
|
vars:
|
||||||
tox_envlist: py35
|
tox_envlist: py35
|
||||||
tox_extra_args: -c fm-rest-api/fm/tox.ini
|
tox_extra_args: -c fm-rest-api/fm/tox.ini
|
||||||
|
@ -19,8 +19,14 @@ Allows overriding of config for use of fakes, and some black magic for
|
|||||||
inline callbacks.
|
inline callbacks.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
import fixtures
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
|
from oslo_log import log as logging
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
|
|
||||||
|
|
||||||
class TestCase(testtools.TestCase):
|
class TestCase(testtools.TestCase):
|
||||||
"""Test case base class for all unit tests."""
|
"""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."""
|
"""Run before each test method to initialize test environment."""
|
||||||
super(TestCase, self).setUp()
|
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):
|
def tearDown(self):
|
||||||
super(TestCase, self).tearDown()
|
super(TestCase, self).tearDown()
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
from fm.common import timeutils
|
from fm.common import timeutils
|
||||||
|
from fm.common import utils
|
||||||
|
|
||||||
from fm.tests import base
|
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, "bad input")
|
||||||
self.assertRaises(ValueError, timeutils.parse_isotime, isotime)
|
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 "))
|
||||||
|
@ -8,3 +8,6 @@ iso8601
|
|||||||
stestr
|
stestr
|
||||||
mock
|
mock
|
||||||
cython
|
cython
|
||||||
|
oslo.log
|
||||||
|
oslo.concurrency
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ setenv = VIRTUAL_ENV={envdir}
|
|||||||
OS_STDERR_CAPTURE=1
|
OS_STDERR_CAPTURE=1
|
||||||
OS_TEST_TIMEOUT=60
|
OS_TEST_TIMEOUT=60
|
||||||
deps = -r{toxinidir}/test-requirements.txt
|
deps = -r{toxinidir}/test-requirements.txt
|
||||||
|
-e{[tox]stxdir}/config/tsconfig/tsconfig
|
||||||
|
|
||||||
[testenv:venv]
|
[testenv:venv]
|
||||||
basepython = python3
|
basepython = python3
|
||||||
|
@ -3,9 +3,3 @@ bashate >= 0.2
|
|||||||
PyYAML >= 3.1.0
|
PyYAML >= 3.1.0
|
||||||
yamllint >= 0.5.2
|
yamllint >= 0.5.2
|
||||||
#spec_cleaner>=1.0.9
|
#spec_cleaner>=1.0.9
|
||||||
stestr
|
|
||||||
testtools!=1.2.0,>=0.9.36
|
|
||||||
iso8601
|
|
||||||
stestr
|
|
||||||
mock
|
|
||||||
cython
|
|
||||||
|
Loading…
Reference in New Issue
Block a user