ticket #114 attempt 1
Some checks failed
DevPlace CI / test (pull_request) Failing after 11s
Some checks failed
DevPlace CI / test (pull_request) Failing after 11s
This commit is contained in:
parent
ad1736ebf1
commit
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
|
||||
|
||||
|
||||
|
||||
@ -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,
|
||||
),
|
||||
),
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user