forked from retoor/devplacepy
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7332e4dd59 |
File diff suppressed because one or more lines are too long
@@ -439,8 +439,8 @@ class VoteForm(BaseModel):
|
||||
@field_validator("value")
|
||||
@classmethod
|
||||
def valid_value(cls, value):
|
||||
if value not in (1, -1):
|
||||
raise ValueError("value must be 1 or -1")
|
||||
if value not in (1, -1, 0):
|
||||
raise ValueError("value must be 1, -1, or 0")
|
||||
return value
|
||||
|
||||
|
||||
|
||||
@@ -46,7 +46,6 @@ 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
|
||||
@@ -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(
|
||||
request,
|
||||
"profile.html",
|
||||
@@ -444,8 +439,6 @@ 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,8 +80,6 @@ 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):
|
||||
|
||||
@@ -22,7 +22,7 @@ ENGAGEMENT_ACTIONS: tuple[Action, ...] = (
|
||||
),
|
||||
body(
|
||||
"value",
|
||||
"Vote value: 1 to upvote, -1 to downvote (re-send to remove).",
|
||||
"Vote value: 1 to upvote, -1 to downvote, 0 to retract.",
|
||||
required=True,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -135,3 +135,13 @@ def test_non_ajax_vote_redirects_to_referer(app_server):
|
||||
)
|
||||
assert r.status_code == 302
|
||||
assert r.headers["location"] == "/gists"
|
||||
|
||||
|
||||
def test_explicit_zero_retracts_vote(app_server):
|
||||
s_a, a_name = _session_votes()
|
||||
s_b, _ = _session_votes()
|
||||
post_uid = _make_post_votes(_uid_votes(a_name))
|
||||
s_b.post(f"{BASE_URL}/votes/post/{post_uid}", data={"value": "1"}, headers=AJAX_votes)
|
||||
r = s_b.post(f"{BASE_URL}/votes/post/{post_uid}", data={"value": "0"}, headers=AJAX_votes)
|
||||
assert r.json()["value"] == 0
|
||||
assert r.json()["net"] == 0
|
||||
|
||||
Reference in New Issue
Block a user