forked from retoor/devplacepy
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a6e6716b1 |
File diff suppressed because one or more lines are too long
@@ -470,19 +470,9 @@ class SeoRunForm(BaseModel):
|
||||
text = value.strip()
|
||||
if not text:
|
||||
raise ValueError("A URL is required")
|
||||
if "://" in text:
|
||||
scheme = text.split("://", 1)[0]
|
||||
if scheme not in ("http", "https"):
|
||||
raise ValueError(f"Only http and https URLs are allowed; got '{scheme}://'")
|
||||
else:
|
||||
text = f"https://{text}"
|
||||
if not SEO_URL_PATTERN.match(text):
|
||||
raise ValueError("URL must be a valid http or https source location")
|
||||
return text
|
||||
|
||||
|
||||
SEO_URL_PATTERN = re.compile(r"^https?://[a-zA-Z0-9][\w./:@~^?&#%=;-]*$")
|
||||
|
||||
ISSLOP_URL_PATTERN = re.compile(r"^(https?://|git://|ssh://|git@)[\w./:@~^-]+$", re.IGNORECASE)
|
||||
ISSLOP_SINGLE_SLASH_PATTERN = re.compile(r"^(https?|git|ssh):/(?!/)", re.IGNORECASE)
|
||||
ISSLOP_SCHEME_PATTERN = re.compile(r"^[a-z][a-z0-9+.-]*://", re.IGNORECASE)
|
||||
|
||||
@@ -46,6 +46,7 @@ from devplacepy.utils import (
|
||||
track_action,
|
||||
build_achievements,
|
||||
)
|
||||
from devplacepy.utils.rewards import LEVEL_XP
|
||||
from devplacepy.responses import respond, action_result, wants_json
|
||||
from devplacepy.schemas import ProfileOut
|
||||
from devplacepy.avatar import avatar_url, avatar_seed
|
||||
@@ -380,6 +381,10 @@ async def profile_page(
|
||||
],
|
||||
)
|
||||
|
||||
xp = profile_user.get("xp") or 0
|
||||
xp_progress_pct = xp % LEVEL_XP
|
||||
xp_next_level = ((xp // LEVEL_XP) + 1) * LEVEL_XP
|
||||
|
||||
return respond(
|
||||
request,
|
||||
"profile.html",
|
||||
@@ -439,6 +444,8 @@ async def profile_page(
|
||||
"awards_pagination": awards_pagination,
|
||||
"awards_count": awards_count,
|
||||
"prominent_award": prominent_award,
|
||||
"xp_progress_pct": xp_progress_pct,
|
||||
"xp_next_level": xp_next_level,
|
||||
"can_give_award": can_give,
|
||||
},
|
||||
model=ProfileOut,
|
||||
|
||||
@@ -80,6 +80,8 @@ class ProfileOut(_Out):
|
||||
awards_count: int = 0
|
||||
prominent_award: Optional[AwardOut] = None
|
||||
can_give_award: bool = False
|
||||
xp_progress_pct: Optional[int] = None
|
||||
xp_next_level: Optional[int] = None
|
||||
|
||||
|
||||
class TelegramPairOut(_Out):
|
||||
|
||||
@@ -267,6 +267,37 @@ def test_activity_comment_card_renders_overlay_link(app_server):
|
||||
assert f'class="card-link" href="/posts/{post_slug}#comment-{comment_uid}"' in r.text
|
||||
|
||||
|
||||
def test_profile_json_contains_xp_progress(app_server):
|
||||
from devplacepy.database import get_table, refresh_snapshot
|
||||
import time
|
||||
|
||||
name = f"xp{int(time.time() * 1000)}"
|
||||
session = requests.Session()
|
||||
session.post(
|
||||
f"{BASE_URL}/auth/signup",
|
||||
data={
|
||||
"username": name,
|
||||
"email": f"{name}@t.dev",
|
||||
"password": "secret123",
|
||||
"confirm_password": "secret123",
|
||||
},
|
||||
allow_redirects=True,
|
||||
)
|
||||
|
||||
user = get_table("users").find_one(username=name)
|
||||
assert user is not None
|
||||
get_table("users").update({"uid": user["uid"], "xp": 250}, ["uid"])
|
||||
refresh_snapshot()
|
||||
|
||||
r = session.get(
|
||||
f"{BASE_URL}/profile/{name}", headers={"Accept": "application/json"}
|
||||
)
|
||||
assert r.status_code == 200, f"status {r.status_code}: {r.text[:200]}"
|
||||
body = r.json()
|
||||
assert body["xp_progress_pct"] == 50
|
||||
assert body["xp_next_level"] == 300
|
||||
|
||||
|
||||
def test_profile_json_exposes_online_presence(app_server):
|
||||
import time
|
||||
|
||||
|
||||
@@ -89,53 +89,6 @@ def test_run_clamps_max_pages_above_cap(app_server):
|
||||
_clear_seo_jobs()
|
||||
|
||||
|
||||
def test_run_rejects_malformed_scheme(app_server):
|
||||
r = requests.post(
|
||||
f"{BASE_URL}/tools/seo/run",
|
||||
headers=_json_headers(),
|
||||
data={"url": "ahttps://devplace.net/sitem", "mode": "url"},
|
||||
allow_redirects=False,
|
||||
)
|
||||
assert r.status_code in (400, 422), r.text
|
||||
|
||||
|
||||
def test_run_rejects_relative_path(app_server):
|
||||
r = requests.post(
|
||||
f"{BASE_URL}/tools/seo/run",
|
||||
headers=_json_headers(),
|
||||
data={"url": "/feed", "mode": "url"},
|
||||
allow_redirects=False,
|
||||
)
|
||||
assert r.status_code in (400, 422), r.text
|
||||
|
||||
|
||||
def test_run_normalizes_missing_scheme(app_server):
|
||||
try:
|
||||
r = requests.post(
|
||||
f"{BASE_URL}/tools/seo/run",
|
||||
headers=_json_headers(),
|
||||
data={"url": "example.com", "mode": "url", "max_pages": "5"},
|
||||
)
|
||||
assert r.status_code == 200, r.text
|
||||
uid = r.json()["uid"]
|
||||
refresh_snapshot()
|
||||
job = queue.get_job(uid)
|
||||
assert job is not None
|
||||
assert job["payload"]["url"] == "https://example.com"
|
||||
finally:
|
||||
_clear_seo_jobs()
|
||||
|
||||
|
||||
def test_run_rejects_non_http_scheme(app_server):
|
||||
r = requests.post(
|
||||
f"{BASE_URL}/tools/seo/run",
|
||||
headers=_json_headers(),
|
||||
data={"url": "ftp://example.com", "mode": "url"},
|
||||
allow_redirects=False,
|
||||
)
|
||||
assert r.status_code in (400, 422), r.text
|
||||
|
||||
|
||||
def test_run_enforces_one_active_job_per_owner(app_server):
|
||||
try:
|
||||
first = requests.post(
|
||||
|
||||
Reference in New Issue
Block a user