2026-06-13 14:32:33 +00:00
|
|
|
# retoor <retoor@molodetz.nl>
|
|
|
|
|
|
|
|
|
|
import time
|
|
|
|
|
import requests
|
|
|
|
|
from tests.conftest import BASE_URL
|
|
|
|
|
def _session_validation():
|
|
|
|
|
s = requests.Session()
|
|
|
|
|
name = f"val_{int(time.time() * 1000)}"
|
|
|
|
|
s.post(
|
|
|
|
|
f"{BASE_URL}/auth/signup",
|
|
|
|
|
data={
|
|
|
|
|
"username": name,
|
|
|
|
|
"email": f"{name}@t.dev",
|
|
|
|
|
"password": "secret123",
|
|
|
|
|
"confirm_password": "secret123",
|
2026-08-09 00:18:20 +02:00
|
|
|
"birth_date": "1990-01-01",
|
|
|
|
|
"accept_terms": "1",
|
2026-06-13 14:32:33 +00:00
|
|
|
},
|
|
|
|
|
allow_redirects=True,
|
|
|
|
|
)
|
|
|
|
|
return s
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_signup_short_username_rerenders_with_message(app_server):
|
|
|
|
|
r = requests.post(
|
|
|
|
|
f"{BASE_URL}/auth/signup",
|
|
|
|
|
data={
|
|
|
|
|
"username": "ab",
|
|
|
|
|
"email": "x@y.zz",
|
|
|
|
|
"password": "secret123",
|
|
|
|
|
"confirm_password": "secret123",
|
2026-08-09 00:18:20 +02:00
|
|
|
"birth_date": "1990-01-01",
|
|
|
|
|
"accept_terms": "1",
|
2026-06-13 14:32:33 +00:00
|
|
|
},
|
|
|
|
|
allow_redirects=False,
|
|
|
|
|
)
|
|
|
|
|
assert r.status_code == 400
|
|
|
|
|
assert "Username must be between 3 and 32 characters" in r.text
|
2026-10-14 07:13:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_signup_json_returns_api_key_and_admin_flag(seeded_db):
|
|
|
|
|
from devplacepy.database import get_table, refresh_snapshot
|
|
|
|
|
|
|
|
|
|
name = f"sgk{int(time.time() * 1000000)}"
|
|
|
|
|
r = requests.post(
|
|
|
|
|
f"{BASE_URL}/auth/signup",
|
|
|
|
|
headers={"Accept": "application/json"},
|
|
|
|
|
data={
|
|
|
|
|
"username": name,
|
|
|
|
|
"email": f"{name}@t.dev",
|
|
|
|
|
"password": "secret123",
|
|
|
|
|
"confirm_password": "secret123",
|
|
|
|
|
"birth_date": "1990-01-01",
|
|
|
|
|
"accept_terms": "1",
|
|
|
|
|
},
|
|
|
|
|
allow_redirects=False,
|
|
|
|
|
)
|
|
|
|
|
assert r.status_code == 200, r.text[:300]
|
|
|
|
|
body = r.json()
|
|
|
|
|
assert body["ok"] is True
|
|
|
|
|
assert body["data"]["username"] == name
|
|
|
|
|
assert body["data"]["email"] == f"{name}@t.dev"
|
|
|
|
|
assert body["data"]["is_admin"] is False
|
|
|
|
|
refresh_snapshot()
|
|
|
|
|
row = get_table("users").find_one(username=name)
|
|
|
|
|
assert row is not None
|
|
|
|
|
assert body["data"]["api_key"] == row["api_key"]
|
|
|
|
|
me = requests.get(
|
|
|
|
|
f"{BASE_URL}/profile",
|
|
|
|
|
headers={
|
|
|
|
|
"Accept": "application/json",
|
|
|
|
|
"X-API-KEY": body["data"]["api_key"],
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
assert me.status_code == 200
|
|
|
|
|
assert me.json()["profile_user"]["username"] == name
|