forked from retoor/devplacepy
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08b791d67a |
File diff suppressed because one or more lines are too long
@@ -439,8 +439,8 @@ class VoteForm(BaseModel):
|
|||||||
@field_validator("value")
|
@field_validator("value")
|
||||||
@classmethod
|
@classmethod
|
||||||
def valid_value(cls, value):
|
def valid_value(cls, value):
|
||||||
if value not in (1, -1, 0):
|
if value not in (1, -1):
|
||||||
raise ValueError("value must be 1, -1, or 0")
|
raise ValueError("value must be 1 or -1")
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ ENGAGEMENT_ACTIONS: tuple[Action, ...] = (
|
|||||||
),
|
),
|
||||||
body(
|
body(
|
||||||
"value",
|
"value",
|
||||||
"Vote value: 1 to upvote, -1 to downvote, 0 to retract.",
|
"Vote value: 1 to upvote, -1 to downvote (re-send to remove).",
|
||||||
required=True,
|
required=True,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -407,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"
|
||||||
|
|||||||
@@ -135,13 +135,3 @@ def test_non_ajax_vote_redirects_to_referer(app_server):
|
|||||||
)
|
)
|
||||||
assert r.status_code == 302
|
assert r.status_code == 302
|
||||||
assert r.headers["location"] == "/gists"
|
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