| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
from unittest import mock |
| 16 |
|
| 17 |
from reno.tests import base |
| 18 |
from reno import utils |
| 19 |
|
| 20 |
|
| 21 |
class TestGetRandomString(base.TestCase): |
| 22 |
|
| 23 |
@mock.patch('random.randrange') |
| 24 |
@mock.patch('os.urandom') |
| 25 |
def test_no_urandom(self, urandom, randrange): |
| 26 |
urandom.side_effect = Exception('cannot use this') |
| 27 |
randrange.return_value = ord('a') |
| 28 |
actual = utils.get_random_string() |
| 29 |
expected = '61' * 8 |
| 30 |
self.assertIsInstance(actual, str) |
| 31 |
self.assertEqual(expected, actual) |
| 32 |
|
| 33 |
@mock.patch('random.randrange') |
| 34 |
@mock.patch('os.urandom') |
| 35 |
def test_with_urandom(self, urandom, randrange): |
| 36 |
urandom.return_value = b'\x62' * 8 |
| 37 |
randrange.return_value = ord('a') |
| 38 |
actual = utils.get_random_string() |
| 39 |
expected = '62' * 8 |
| 40 |
self.assertIsInstance(actual, str) |
| 41 |
self.assertEqual(expected, actual) |