forked from retoor/devplacepy
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08b791d67a |
File diff suppressed because one or more lines are too long
@@ -46,7 +46,6 @@ from devplacepy.utils import (
|
|||||||
track_action,
|
track_action,
|
||||||
build_achievements,
|
build_achievements,
|
||||||
)
|
)
|
||||||
from devplacepy.utils.rewards import LEVEL_XP
|
|
||||||
from devplacepy.responses import respond, action_result, wants_json
|
from devplacepy.responses import respond, action_result, wants_json
|
||||||
from devplacepy.schemas import ProfileOut
|
from devplacepy.schemas import ProfileOut
|
||||||
from devplacepy.avatar import avatar_url, avatar_seed
|
from devplacepy.avatar import avatar_url, avatar_seed
|
||||||
@@ -381,10 +380,6 @@ 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(
|
return respond(
|
||||||
request,
|
request,
|
||||||
"profile.html",
|
"profile.html",
|
||||||
@@ -444,8 +439,6 @@ async def profile_page(
|
|||||||
"awards_pagination": awards_pagination,
|
"awards_pagination": awards_pagination,
|
||||||
"awards_count": awards_count,
|
"awards_count": awards_count,
|
||||||
"prominent_award": prominent_award,
|
"prominent_award": prominent_award,
|
||||||
"xp_progress_pct": xp_progress_pct,
|
|
||||||
"xp_next_level": xp_next_level,
|
|
||||||
"can_give_award": can_give,
|
"can_give_award": can_give,
|
||||||
},
|
},
|
||||||
model=ProfileOut,
|
model=ProfileOut,
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
|
from pydantic import Field
|
||||||
|
|
||||||
from devplacepy.schemas.base import _Out
|
from devplacepy.schemas.base import _Out
|
||||||
|
|
||||||
|
|
||||||
@@ -62,7 +64,7 @@ class PollOut(_Out):
|
|||||||
|
|
||||||
|
|
||||||
class BadgeOut(_Out):
|
class BadgeOut(_Out):
|
||||||
name: Optional[str] = None
|
name: Optional[str] = Field(None, alias="badge_name")
|
||||||
created_at: Optional[str] = None
|
created_at: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -80,8 +80,6 @@ class ProfileOut(_Out):
|
|||||||
awards_count: int = 0
|
awards_count: int = 0
|
||||||
prominent_award: Optional[AwardOut] = None
|
prominent_award: Optional[AwardOut] = None
|
||||||
can_give_award: bool = False
|
can_give_award: bool = False
|
||||||
xp_progress_pct: Optional[int] = None
|
|
||||||
xp_next_level: Optional[int] = None
|
|
||||||
|
|
||||||
|
|
||||||
class TelegramPairOut(_Out):
|
class TelegramPairOut(_Out):
|
||||||
|
|||||||
+40
-31
@@ -267,37 +267,6 @@ 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
|
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):
|
def test_profile_json_exposes_online_presence(app_server):
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@@ -438,3 +407,43 @@ def test_viewing_profile_marks_notification_read(app_server):
|
|||||||
|
|
||||||
refresh_snapshot()
|
refresh_snapshot()
|
||||||
assert bool(get_table("notifications").find_one(uid=notif_uid)["read"]) is True
|
assert bool(get_table("notifications").find_one(uid=notif_uid)["read"]) is True
|
||||||
|
|
||||||
|
|
||||||
|
def test_profile_json_badge_names_non_null(app_server):
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
from uuid import uuid4
|
||||||
|
from devplacepy.database import get_table, refresh_snapshot
|
||||||
|
from devplacepy.utils import generate_uid
|
||||||
|
|
||||||
|
uid = str(uuid4())
|
||||||
|
username = f"badge_{uid[:8]}"
|
||||||
|
get_table("users").insert(
|
||||||
|
{
|
||||||
|
"uid": uid,
|
||||||
|
"username": username,
|
||||||
|
"email": f"{uid[:8]}@badge.test",
|
||||||
|
"password_hash": "x",
|
||||||
|
"role": "Member",
|
||||||
|
"is_active": True,
|
||||||
|
"created_at": datetime.now(timezone.utc).isoformat(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
badge_uid = generate_uid()
|
||||||
|
get_table("badges").insert(
|
||||||
|
{
|
||||||
|
"uid": badge_uid,
|
||||||
|
"user_uid": uid,
|
||||||
|
"badge_name": "On Fire",
|
||||||
|
"created_at": datetime.now(timezone.utc).isoformat(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
refresh_snapshot()
|
||||||
|
|
||||||
|
r = requests.get(
|
||||||
|
f"{BASE_URL}/profile/{username}", headers={"Accept": "application/json"}
|
||||||
|
)
|
||||||
|
assert r.status_code == 200
|
||||||
|
body = r.json()
|
||||||
|
for badge in body.get("badges", []):
|
||||||
|
assert badge["name"] is not None, f"Badge name is None: {badge}"
|
||||||
|
assert badge["name"] == "On Fire"
|
||||||
|
|||||||
Reference in New Issue
Block a user