diff options
-rw-r--r-- | requirements.txt | 2 | ||||
-rw-r--r-- | tempest_lib/common/utils/data_utils.py | 10 | ||||
-rw-r--r-- | tempest_lib/tests/common/utils/test_data_utils.py | 62 | ||||
-rw-r--r-- | tempest_lib/tests/test_rest_client.py | 30 | ||||
-rw-r--r-- | test-requirements.txt | 4 | ||||
-rw-r--r-- | tox.ini | 2 |
6 files changed, 102 insertions, 8 deletions
diff --git a/requirements.txt b/requirements.txt index 6629585..dd1377e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,4 @@ iso8601>=0.1.9 jsonschema>=2.0.0,<3.0.0 httplib2>=0.7.5 six>=1.9.0 -oslo.log>=0.4.0 # Apache-2.0 +oslo.log>=1.0.0,<1.1.0 # Apache-2.0 diff --git a/tempest_lib/common/utils/data_utils.py b/tempest_lib/common/utils/data_utils.py index eec2474..dc799fe 100644 --- a/tempest_lib/common/utils/data_utils.py +++ b/tempest_lib/common/utils/data_utils.py @@ -27,12 +27,14 @@ def rand_uuid_hex(): return uuid.uuid4().hex -def rand_name(name=''): +def rand_name(name='', prefix=None): randbits = str(random.randint(1, 0x7fffffff)) + rand_name = randbits if name: - return name + '-' + randbits - else: - return randbits + rand_name = name + '-' + rand_name + if prefix: + rand_name = prefix + '-' + rand_name + return rand_name def rand_url(): diff --git a/tempest_lib/tests/common/utils/test_data_utils.py b/tempest_lib/tests/common/utils/test_data_utils.py index 76401cb..e8a7c33 100644 --- a/tempest_lib/tests/common/utils/test_data_utils.py +++ b/tempest_lib/tests/common/utils/test_data_utils.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +import netaddr from tempest_lib.common.utils import data_utils from tempest_lib.tests import base @@ -48,6 +49,20 @@ class TestDataUtils(base.TestCase): self.assertTrue(actual.startswith('foo')) self.assertNotEqual(actual, actual2) + def test_rand_name_with_prefix(self): + actual = data_utils.rand_name(prefix='prefix-str') + self.assertIsInstance(actual, str) + self.assertRegexpMatches(actual, "^prefix-str-") + actual2 = data_utils.rand_name(prefix='prefix-str') + self.assertNotEqual(actual, actual2) + + def test_rand_url(self): + actual = data_utils.rand_url() + self.assertIsInstance(actual, str) + self.assertRegexpMatches(actual, "^https://url-[0-9]*\.com$") + actual2 = data_utils.rand_url() + self.assertNotEqual(actual, actual2) + def test_rand_int(self): actual = data_utils.rand_int_id() self.assertIsInstance(actual, int) @@ -75,3 +90,50 @@ class TestDataUtils(base.TestCase): self.assertEqual(actual, "abc" * int(30 / len("abc"))) actual = data_utils.arbitrary_string(size=5, base_text="deadbeaf") self.assertEqual(actual, "deadb") + + def test_random_bytes(self): + actual = data_utils.random_bytes() # default size=1024 + self.assertIsInstance(actual, str) + self.assertRegexpMatches(actual, "^[\x00-\xFF]{1024}") + actual2 = data_utils.random_bytes() + self.assertNotEqual(actual, actual2) + + actual = data_utils.random_bytes(size=2048) + self.assertRegexpMatches(actual, "^[\x00-\xFF]{2048}") + + def test_get_ipv6_addr_by_EUI64(self): + actual = data_utils.get_ipv6_addr_by_EUI64('2001:db8::', + '00:16:3e:33:44:55') + self.assertIsInstance(actual, netaddr.IPAddress) + self.assertEqual(actual, + netaddr.IPAddress('2001:db8::216:3eff:fe33:4455')) + + def test_get_ipv6_addr_by_EUI64_with_IPv4_prefix(self): + ipv4_prefix = '10.0.8' + mac = '00:16:3e:33:44:55' + self.assertRaises(TypeError, data_utils.get_ipv6_addr_by_EUI64, + ipv4_prefix, mac) + + def test_get_ipv6_addr_by_EUI64_bad_cidr_type(self): + bad_cidr = 123 + mac = '00:16:3e:33:44:55' + self.assertRaises(TypeError, data_utils.get_ipv6_addr_by_EUI64, + bad_cidr, mac) + + def test_get_ipv6_addr_by_EUI64_bad_cidr_value(self): + bad_cidr = 'bb' + mac = '00:16:3e:33:44:55' + self.assertRaises(TypeError, data_utils.get_ipv6_addr_by_EUI64, + bad_cidr, mac) + + def test_get_ipv6_addr_by_EUI64_bad_mac_value(self): + cidr = '2001:db8::' + bad_mac = '00:16:3e:33:44:5Z' + self.assertRaises(TypeError, data_utils.get_ipv6_addr_by_EUI64, + cidr, bad_mac) + + def test_get_ipv6_addr_by_EUI64_bad_mac_type(self): + cidr = '2001:db8::' + bad_mac = 99999999999999999999 + self.assertRaises(TypeError, data_utils.get_ipv6_addr_by_EUI64, + cidr, bad_mac) diff --git a/tempest_lib/tests/test_rest_client.py b/tempest_lib/tests/test_rest_client.py index b48c156..d585b88 100644 --- a/tempest_lib/tests/test_rest_client.py +++ b/tempest_lib/tests/test_rest_client.py @@ -483,3 +483,33 @@ class TestExpectedSuccess(BaseRestClientTestClass): read_code = 202 self.assertRaises(AssertionError, self.rest_client.expected_success, expected_code, read_code) + + +class TestResponseBody(base.TestCase): + + def test_str(self): + response = {'status': 200} + body = {'key1': 'value1'} + actual = rest_client.ResponseBody(response, body) + self.assertEqual("response: %s\nBody: %s" % (response, body), + str(actual)) + + +class TestResponseBodyData(base.TestCase): + + def test_str(self): + response = {'status': 200} + data = 'data1' + actual = rest_client.ResponseBodyData(response, data) + self.assertEqual("response: %s\nBody: %s" % (response, data), + str(actual)) + + +class TestResponseBodyList(base.TestCase): + + def test_str(self): + response = {'status': 200} + body = ['value1', 'value2', 'value3'] + actual = rest_client.ResponseBodyList(response, body) + self.assertEqual("response: %s\nBody: %s" % (response, body), + str(actual)) diff --git a/test-requirements.txt b/test-requirements.txt index aed1f05..0561abf 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -7,8 +7,8 @@ coverage>=3.6 discover python-subunit>=0.0.18 sphinx>=1.1.2,!=1.2.0,!=1.3b1,<1.3 -oslosphinx>=2.2.0 # Apache-2.0 -oslotest>=1.2.0 # Apache-2.0 +oslosphinx>=2.5.0,<2.6.0 # Apache-2.0 +oslotest>=1.5.1,<1.6.0 # Apache-2.0 testrepository>=0.0.18 testscenarios>=0.4 testtools>=0.9.36,!=1.2.0 @@ -20,7 +20,7 @@ commands = flake8 commands = {posargs} [testenv:cover] -commands = python setup.py testr --coverage --coverage-package-name='tempest_lib' --testr-args='{posargs}' +commands = python setup.py test --coverage --coverage-package-name='tempest_lib' --testr-args='{posargs}' [testenv:docs] commands = python setup.py build_sphinx |