#239 added token type validation

This commit is contained in:
Oleg A 2019-11-23 12:45:47 +03:00
parent 89b0754b33
commit 4523a1cab3
2 changed files with 11 additions and 1 deletions

View file

@ -24,8 +24,14 @@ def check_token(token: str) -> bool:
:param token:
:return:
"""
if not isinstance(token, str):
message = (f"Token is invalid! "
f"It must be 'str' type instead of {type(token)} type.")
raise exceptions.ValidationError(message)
if any(x.isspace() for x in token):
raise exceptions.ValidationError('Token is invalid!')
message = "Token is invalid! It can't contains spaces."
raise exceptions.ValidationError(message)
left, sep, right = token.partition(':')
if (not sep) or (not left.isdigit()) or (not right):

View file

@ -10,6 +10,10 @@ INVALID_TOKENS = [
':AABBCCDDEEFFaabbccddeeff123456789', # there is no left part
'123456789:', # there is no right part
'ABC AABBCCDDEEFFaabbccddeeff123456789', # there is no ':' separator
None, # is None
12345678, # is digit
{}, # is dict
[], # is dict
]