2022-03-19 20:34:36 +01:00
|
|
|
import random
|
|
|
|
import string
|
2022-04-02 17:16:10 +02:00
|
|
|
from json import loads
|
|
|
|
from typing import Dict, Optional
|
|
|
|
|
|
|
|
from flask import json as flask_json
|
2022-03-19 20:34:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
def random_string(
|
|
|
|
length: Optional[int] = None,
|
|
|
|
prefix: Optional[str] = None,
|
|
|
|
suffix: Optional[str] = None,
|
|
|
|
) -> str:
|
|
|
|
if length is None:
|
|
|
|
length = 10
|
|
|
|
random_str = ''.join(
|
|
|
|
random.choice(string.ascii_letters + string.digits)
|
|
|
|
for _ in range(length)
|
|
|
|
)
|
|
|
|
return (
|
|
|
|
f'{"" if prefix is None else prefix}'
|
|
|
|
f'{random_str}'
|
|
|
|
f'{"" if suffix is None else suffix}'
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def random_email() -> str:
|
|
|
|
return random_string(suffix='@example.com')
|
2022-04-02 17:16:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
def jsonify_dict(data: Dict) -> Dict:
|
|
|
|
return loads(flask_json.dumps(data))
|