|
7 | 7 | from django.test import TestCase |
8 | 8 | from django.utils import six |
9 | 9 | from django.utils.six.moves.urllib.parse import parse_qsl, urlparse |
| 10 | +from django_otp.util import random_hex |
10 | 11 |
|
11 | | -from two_factor.models import PhoneDevice |
| 12 | +from two_factor.models import PhoneDevice, random_hex_str |
12 | 13 | from two_factor.utils import ( |
13 | 14 | backup_phones, default_device, get_otpauth_url, totp_digits, |
14 | 15 | ) |
@@ -102,3 +103,15 @@ def test_get_totp_digits(self): |
102 | 103 | for no_digits in (6, 8): |
103 | 104 | with self.settings(TWO_FACTOR_TOTP_DIGITS=no_digits): |
104 | 105 | self.assertEqual(totp_digits(), no_digits) |
| 106 | + |
| 107 | + def test_random_hex(self): |
| 108 | + # test that returned random_hex_str is string |
| 109 | + h = random_hex_str() |
| 110 | + self.assertIsInstance(h, six.string_types) |
| 111 | + # hex string must be 40 characters long. If cannot be longer, because CharField max_length=40 |
| 112 | + self.assertEqual(len(h), 40) |
| 113 | + |
| 114 | + # Added tests to verify that we can safely remove IF statement from random_hex_str function |
| 115 | + hh = random_hex().decode('utf-8') |
| 116 | + self.assertIsInstance(hh, six.string_types) |
| 117 | + self.assertEqual(len(hh), 40) |
0 commit comments