2026-05-06 22:16:58 +03:30
|
|
|
import uuid
|
|
|
|
|
import redis
|
|
|
|
|
|
|
|
|
|
from utils.http_client import http_request
|
|
|
|
|
from utils.yaml_loader import load_config
|
|
|
|
|
from utils.template import render
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config = load_config()
|
|
|
|
|
|
|
|
|
|
BASE_URL = config["base_url"]
|
2026-05-06 22:41:53 +03:30
|
|
|
flow = config["flows"]["auth"]
|
2026-05-06 22:16:58 +03:30
|
|
|
|
|
|
|
|
redis_client = redis.Redis(
|
|
|
|
|
host="redis",
|
|
|
|
|
port=6379,
|
|
|
|
|
decode_responses=True
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_auth_flow():
|
|
|
|
|
|
|
|
|
|
context = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# -------- register --------
|
|
|
|
|
|
|
|
|
|
login = flow["login"]
|
|
|
|
|
|
|
|
|
|
body = render(login["body"], context)
|
|
|
|
|
|
|
|
|
|
res = http_request(
|
|
|
|
|
login["method"],
|
|
|
|
|
BASE_URL + login["path"],
|
2026-05-06 22:41:53 +03:30
|
|
|
authenticated=False,
|
2026-05-06 22:16:58 +03:30
|
|
|
json=body
|
|
|
|
|
)
|
2026-05-06 22:41:53 +03:30
|
|
|
print(res)
|
2026-05-06 22:16:58 +03:30
|
|
|
|
2026-05-06 22:41:53 +03:30
|
|
|
assert res["status"] == login["expected_status"]
|
2026-05-06 22:16:58 +03:30
|
|
|
|
|
|
|
|
token_field = login["extract"]["token"]
|
|
|
|
|
|
2026-05-06 22:41:53 +03:30
|
|
|
token = res["data"][token_field]
|
2026-05-06 22:16:58 +03:30
|
|
|
|
|
|
|
|
assert token is not None
|
|
|
|
|
|
|
|
|
|
context["token"] = token
|
|
|
|
|
|
|
|
|
|
# -------- redis store --------
|
|
|
|
|
|
|
|
|
|
redis_cfg = login["store_redis"]
|
|
|
|
|
|
|
|
|
|
key = render(redis_cfg["key"], context)
|
|
|
|
|
|
|
|
|
|
redis_client.set(
|
|
|
|
|
key,
|
|
|
|
|
token,
|
|
|
|
|
ex=redis_cfg["ttl"]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
saved_token = redis_client.get(key)
|
|
|
|
|
|
|
|
|
|
assert saved_token == token
|
|
|
|
|
|