Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cuenca_validations/types/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime as dt
import random
import uuid
from base64 import urlsafe_b64encode
from typing import Callable, Optional, Union
Expand All @@ -12,7 +13,10 @@

def uuid_field(prefix: str = '') -> Callable[[], str]:
def base64_uuid_func() -> str:
return prefix + urlsafe_b64encode(uuid.uuid4().bytes).decode()[:-2]
base64_str = urlsafe_b64encode(uuid.uuid4().bytes).decode()[:-2]
rnd = str(random.randint(0, 9))
sanitized = base64_str.replace('-', rnd).replace('_', rnd)
return prefix + sanitized

return base64_uuid_func

Expand Down
2 changes: 1 addition & 1 deletion cuenca_validations/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.1.21'
__version__ = '2.1.22'
7 changes: 7 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ def test_multiple_generators():
assert uuid1.startswith('CA')
assert uuid2.startswith('TR')
assert uuid1 != uuid2


def test_sanitized_uuid():
generator = uuid_field('US')
uuid_str = generator()
assert "-" not in uuid_str
assert "_" not in uuid_str
Loading