Masayuki Igawa | ce7c696 | 2014-03-10 16:14:52 +0900 | [diff] [blame] | 1 | # Copyright 2014 NEC Corporation. |
| 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
| 16 | |
| 17 | from tempest.common.utils import data_utils |
| 18 | from tempest.tests import base |
| 19 | |
| 20 | |
| 21 | class TestDataUtils(base.TestCase): |
| 22 | |
| 23 | def test_rand_uuid(self): |
| 24 | actual = data_utils.rand_uuid() |
| 25 | self.assertIsInstance(actual, str) |
| 26 | self.assertRegexpMatches(actual, "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]" |
| 27 | "{4}-[0-9a-f]{4}-[0-9a-f]{12}$") |
| 28 | actual2 = data_utils.rand_uuid() |
| 29 | self.assertNotEqual(actual, actual2) |
| 30 | |
| 31 | def test_rand_uuid_hex(self): |
| 32 | actual = data_utils.rand_uuid_hex() |
| 33 | self.assertIsInstance(actual, str) |
| 34 | self.assertRegexpMatches(actual, "^[0-9a-f]{32}$") |
| 35 | |
| 36 | actual2 = data_utils.rand_uuid_hex() |
| 37 | self.assertNotEqual(actual, actual2) |
| 38 | |
| 39 | def test_rand_name(self): |
| 40 | actual = data_utils.rand_name() |
| 41 | self.assertIsInstance(actual, str) |
| 42 | actual2 = data_utils.rand_name() |
| 43 | self.assertNotEqual(actual, actual2) |
| 44 | |
| 45 | actual = data_utils.rand_name('foo') |
| 46 | self.assertTrue(actual.startswith('foo')) |
| 47 | actual2 = data_utils.rand_name('foo') |
| 48 | self.assertTrue(actual.startswith('foo')) |
| 49 | self.assertNotEqual(actual, actual2) |
| 50 | |
| 51 | def test_rand_int(self): |
| 52 | actual = data_utils.rand_int_id() |
| 53 | self.assertIsInstance(actual, int) |
| 54 | |
| 55 | actual2 = data_utils.rand_int_id() |
| 56 | self.assertNotEqual(actual, actual2) |
| 57 | |
| 58 | def test_rand_mac_address(self): |
| 59 | actual = data_utils.rand_mac_address() |
| 60 | self.assertIsInstance(actual, str) |
| 61 | self.assertRegexpMatches(actual, "^([0-9a-f][0-9a-f]:){5}" |
| 62 | "[0-9a-f][0-9a-f]$") |
| 63 | |
| 64 | actual2 = data_utils.rand_mac_address() |
| 65 | self.assertNotEqual(actual, actual2) |
| 66 | |
| 67 | def test_parse_image_id(self): |
| 68 | actual = data_utils.parse_image_id("/foo/bar/deadbeaf") |
| 69 | self.assertEqual("deadbeaf", actual) |
| 70 | |
| 71 | def test_arbitrary_string(self): |
| 72 | actual = data_utils.arbitrary_string() |
| 73 | self.assertEqual(actual, "test") |
| 74 | actual = data_utils.arbitrary_string(size=30, base_text="abc") |
| 75 | self.assertEqual(actual, "abc" * (30 / len("abc"))) |
| 76 | actual = data_utils.arbitrary_string(size=5, base_text="deadbeaf") |
| 77 | self.assertEqual(actual, "deadb") |