summaryrefslogtreecommitdiff
path: root/passlib/tests
diff options
context:
space:
mode:
Diffstat (limited to 'passlib/tests')
-rw-r--r--passlib/tests/test_context.py6
-rw-r--r--passlib/tests/test_handlers_argon2.py3
-rw-r--r--passlib/tests/test_totp.py3
-rw-r--r--passlib/tests/test_utils.py10
-rw-r--r--passlib/tests/test_utils_handlers.py10
-rw-r--r--passlib/tests/utils.py29
6 files changed, 29 insertions, 32 deletions
diff --git a/passlib/tests/test_context.py b/passlib/tests/test_context.py
index 5a82d90..f323080 100644
--- a/passlib/tests/test_context.py
+++ b/passlib/tests/test_context.py
@@ -15,7 +15,7 @@ from passlib import hash
from passlib.context import CryptContext, LazyCryptContext
from passlib.exc import PasslibConfigWarning, PasslibHashWarning
from passlib.utils import tick, to_unicode
-from passlib.utils.compat import unicode, str_to_uascii
+from passlib.utils.compat import str_to_uascii
import passlib.utils.handlers as uh
from passlib.tests.utils import (TestCase, set_file, TICK_RESOLUTION,
quicksleep, time_call, handler_derived_from)
@@ -1153,7 +1153,7 @@ sha512_crypt__min_rounds = 45000
def _calc_checksum(self, secret):
from hashlib import md5
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
return str_to_uascii(md5(secret).hexdigest())
@@ -1708,7 +1708,7 @@ class DelayHash(uh.StaticHandler):
def _calc_checksum(self, secret):
time.sleep(self.delay)
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
return str_to_uascii(hashlib.sha1(b"prefix" + secret).hexdigest())
diff --git a/passlib/tests/test_handlers_argon2.py b/passlib/tests/test_handlers_argon2.py
index e771769..a5309d2 100644
--- a/passlib/tests/test_handlers_argon2.py
+++ b/passlib/tests/test_handlers_argon2.py
@@ -10,7 +10,6 @@ import warnings
# site
# pkg
from passlib import hash
-from passlib.utils.compat import unicode
from passlib.tests.utils import HandlerCase, TEST_MODE
from passlib.tests.test_handlers import UPASS_TABLE, PASS_TABLE_UTF8
# module
@@ -303,7 +302,7 @@ class _base_argon2_test(HandlerCase):
# check supported type_values
for value in cls.type_values:
- self.assertIsInstance(value, unicode)
+ self.assertIsInstance(value, str)
self.assertTrue("i" in cls.type_values)
self.assertTrue("d" in cls.type_values)
diff --git a/passlib/tests/test_totp.py b/passlib/tests/test_totp.py
index 4dc16ed..999c799 100644
--- a/passlib/tests/test_totp.py
+++ b/passlib/tests/test_totp.py
@@ -12,7 +12,6 @@ import time as _time
# site
# pkg
from passlib import exc
-from passlib.utils.compat import unicode
from passlib.tests.utils import TestCase, time_call
# subject
from passlib import totp as totp_module
@@ -871,7 +870,7 @@ class TotpTest(TestCase):
time = self.randtime()
result = otp.generate(time)
token = result.token
- self.assertIsInstance(token, unicode)
+ self.assertIsInstance(token, str)
start_time = result.counter * 30
# should generate same token for next 29s
diff --git a/passlib/tests/test_utils.py b/passlib/tests/test_utils.py
index e954422..ceea26a 100644
--- a/passlib/tests/test_utils.py
+++ b/passlib/tests/test_utils.py
@@ -9,7 +9,7 @@ import warnings
# pkg
# module
from passlib.utils import is_ascii_safe, to_bytes
-from passlib.utils.compat import unicode, join_bytes, PYPY
+from passlib.utils.compat import join_bytes, PYPY
from passlib.tests.utils import TestCase, hb, run_with_fixed_seeds
#=============================================================================
@@ -121,7 +121,7 @@ class MiscTest(TestCase):
# letters
x = wrapper(u'abc', 32)
y = wrapper(u'abc', 32)
- self.assertIsInstance(x, unicode)
+ self.assertIsInstance(x, str)
self.assertNotEqual(x,y)
self.assertEqual(sorted(set(x)), [u'a',u'b',u'c'])
@@ -195,18 +195,18 @@ class MiscTest(TestCase):
# helpers to generate hashes & config strings to work with
def get_hash(secret):
- assert isinstance(secret, unicode)
+ assert isinstance(secret, str)
hash = hasher.hash(secret)
if isinstance(hash, bytes): # py2
hash = hash.decode("utf-8")
- assert isinstance(hash, unicode)
+ assert isinstance(hash, str)
return hash
# test ascii password & return type
s1 = u"test"
h1 = get_hash(s1)
result = safe_crypt(s1, h1)
- self.assertIsInstance(result, unicode)
+ self.assertIsInstance(result, str)
self.assertEqual(result, h1)
self.assertEqual(safe_crypt(to_bytes(s1), to_bytes(h1)), h1)
diff --git a/passlib/tests/test_utils_handlers.py b/passlib/tests/test_utils_handlers.py
index 0a98978..8527304 100644
--- a/passlib/tests/test_utils_handlers.py
+++ b/passlib/tests/test_utils_handlers.py
@@ -12,7 +12,7 @@ import warnings
from passlib.hash import ldap_md5, sha256_crypt
from passlib.exc import MissingBackendError, PasslibHashWarning
from passlib.utils.compat import str_to_uascii, \
- uascii_to_str, unicode
+ uascii_to_str
import passlib.utils.handlers as uh
from passlib.tests.utils import HandlerCase, TestCase
# module
@@ -155,7 +155,7 @@ class SkeletonTest(TestCase):
# relaxed
# NOTE: this could be turned back on if we test _norm_checksum() directly...
- #with self.assertWarningList("checksum should be unicode"):
+ #with self.assertWarningList("checksum should be str"):
# self.assertEqual(norm_checksum(b'xxzx', relaxed=True), u'xxzx')
#self.assertRaises(TypeError, norm_checksum, 1, relaxed=True)
@@ -174,7 +174,7 @@ class SkeletonTest(TestCase):
# test bytes
self.assertEqual(norm_checksum(b'1234'), b'1234')
- # test unicode
+ # test str
self.assertRaises(TypeError, norm_checksum, u'xxyx')
# NOTE: this could be turned back on if we test _norm_checksum() directly...
@@ -746,7 +746,7 @@ class UnsaltedHash(uh.StaticHandler):
checksum_size = 40
def _calc_checksum(self, secret):
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
data = b"boblious" + secret
return str_to_uascii(hashlib.sha1(data).hexdigest())
@@ -776,7 +776,7 @@ class SaltedHash(uh.HasSalt, uh.GenericHandler):
return uascii_to_str(hash)
def _calc_checksum(self, secret):
- if isinstance(secret, unicode):
+ if isinstance(secret, str):
secret = secret.encode("utf-8")
data = self.salt.encode("ascii") + secret + self.salt.encode("ascii")
return str_to_uascii(hashlib.sha1(data).hexdigest())
diff --git a/passlib/tests/utils.py b/passlib/tests/utils.py
index be46bdd..28ddf49 100644
--- a/passlib/tests/utils.py
+++ b/passlib/tests/utils.py
@@ -28,7 +28,6 @@ import passlib.registry as registry
from passlib.utils import has_rounds_info, has_salt_info, rounds_cost_values, \
rng as sys_rng, getrandstr, is_ascii_safe, to_native_str, \
repeat_string, tick, batch
-from passlib.utils.compat import unicode
from passlib.utils.decor import classproperty
import passlib.utils.handlers as uh
# local
@@ -218,7 +217,7 @@ def patch_calc_min_rounds(handler):
#=============================================================================
def set_file(path, content):
"""set file to specified bytes"""
- if isinstance(content, unicode):
+ if isinstance(content, str):
content = content.encode("utf-8")
with open(path, "wb") as fh:
fh.write(content)
@@ -1447,7 +1446,7 @@ class HandlerCase(TestCase):
if getattr(self.handler, "_salt_is_bytes", False):
return bytes
else:
- return unicode
+ return str
def test_15_salt_type(self):
"""test non-string salt values"""
@@ -1461,7 +1460,7 @@ class HandlerCase(TestCase):
self.assertRaises(TypeError, self.do_encrypt, 'stub', salt=fake())
# unicode should be accepted only if salt_type is unicode.
- if salt_type is not unicode:
+ if salt_type is not str:
self.assertRaises(TypeError, self.do_encrypt, 'stub', salt=u'x' * salt_size)
# bytes should be accepted only if salt_type is bytes
@@ -1941,24 +1940,24 @@ class HandlerCase(TestCase):
# check ident_values list
for value in cls.ident_values:
- self.assertIsInstance(value, unicode,
- "cls.ident_values must be unicode:")
+ self.assertIsInstance(value, str,
+ "cls.ident_values must be str:")
self.assertTrue(len(cls.ident_values)>1,
"cls.ident_values must have 2+ elements:")
# check default_ident value
- self.assertIsInstance(cls.default_ident, unicode,
- "cls.default_ident must be unicode:")
+ self.assertIsInstance(cls.default_ident, str,
+ "cls.default_ident must be str:")
self.assertTrue(cls.default_ident in cls.ident_values,
"cls.default_ident must specify member of cls.ident_values")
# check optional aliases list
if cls.ident_aliases:
for alias, ident in cls.ident_aliases.items():
- self.assertIsInstance(alias, unicode,
- "cls.ident_aliases keys must be unicode:") # XXX: allow ints?
- self.assertIsInstance(ident, unicode,
- "cls.ident_aliases values must be unicode:")
+ self.assertIsInstance(alias, str,
+ "cls.ident_aliases keys must be str:") # XXX: allow ints?
+ self.assertIsInstance(ident, str,
+ "cls.ident_aliases values must be str:")
self.assertTrue(ident in cls.ident_values,
"cls.ident_aliases must map to cls.ident_values members: %r" % (ident,))
@@ -2581,7 +2580,7 @@ class HandlerCase(TestCase):
"""
if value is None:
return
- self.assertIsInstance(value, unicode)
+ self.assertIsInstance(value, str)
# assumes mask_value() defaults will never show more than <show> chars (4);
# and show nothing if size less than 1/<pct> (8).
ref = value if len(value) < 8 else value[4:]
@@ -2799,7 +2798,7 @@ class HandlerCase(TestCase):
used by fuzz testing.
verifiers should be callable with signature
- ``func(password: unicode, hash: ascii str) -> ok: bool``.
+ ``func(password: str, hash: ascii str) -> ok: bool``.
"""
handler = self.handler
verifiers = []
@@ -2983,7 +2982,7 @@ class HandlerCase(TestCase):
result = getrandstr(rng, self.password_alphabet, size)
# trim ones that encode past truncate point.
- if truncate_size and isinstance(result, unicode):
+ if truncate_size and isinstance(result, str):
while len(result.encode("utf-8")) > truncate_size:
result = result[:-1]