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
|
2022-05-27 18:19:12 +02:00
|
|
|
from uuid import uuid4
|
2022-04-02 17:16:10 +02:00
|
|
|
|
|
|
|
from flask import json as flask_json
|
2022-03-19 20:34:36 +01:00
|
|
|
|
2022-05-27 18:19:12 +02:00
|
|
|
from fittrackee.workouts.utils.short_id import encode_uuid
|
|
|
|
|
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}'
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-05-27 13:28:26 +02:00
|
|
|
def random_domain() -> str:
|
|
|
|
return random_string(prefix='https://', suffix='.com')
|
|
|
|
|
|
|
|
|
2022-03-19 20:34:36 +01:00
|
|
|
def random_email() -> str:
|
|
|
|
return random_string(suffix='@example.com')
|
2022-04-02 17:16:10 +02:00
|
|
|
|
|
|
|
|
2022-09-15 13:14:55 +02:00
|
|
|
def random_int(min_val: int = 0, max_val: int = 999999) -> int:
|
|
|
|
return random.randint(min_val, max_val)
|
|
|
|
|
|
|
|
|
2022-05-27 18:19:12 +02:00
|
|
|
def random_short_id() -> str:
|
|
|
|
return encode_uuid(uuid4())
|
|
|
|
|
|
|
|
|
2022-04-02 17:16:10 +02:00
|
|
|
def jsonify_dict(data: Dict) -> Dict:
|
|
|
|
return loads(flask_json.dumps(data))
|
2022-05-27 16:02:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
TEST_OAUTH_CLIENT_METADATA = {
|
|
|
|
'client_name': random_string(),
|
|
|
|
'client_uri': random_domain(),
|
|
|
|
'redirect_uris': [random_domain()],
|
2022-06-15 19:16:14 +02:00
|
|
|
'scope': 'profile:read workouts:read',
|
2022-05-27 16:02:05 +02:00
|
|
|
}
|
2023-05-21 16:13:14 +02:00
|
|
|
|
|
|
|
OAUTH_SCOPES = {
|
|
|
|
"application:write": False,
|
|
|
|
"profile:read": False,
|
|
|
|
"profile:write": False,
|
|
|
|
"users:read": False,
|
|
|
|
"users:write": False,
|
|
|
|
"workouts:read": False,
|
|
|
|
"workouts:write": False,
|
|
|
|
}
|