Settings API and schema for now_playing_mode (phase 4, step 4)
CI / lint (push) Successful in 13s
CI / validate-monitoring (push) Successful in 40s
CI / federation-interop (push) Successful in 1m8s
CI / test (push) Successful in 3m39s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 6s
CI / lint (push) Successful in 13s
CI / validate-monitoring (push) Successful in 40s
CI / federation-interop (push) Successful in 1m8s
CI / test (push) Successful in 3m39s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 6s
now_playing_mode was already in sharing.EDITABLE (step 1), so _settings_body() was already returning it - but SharingSettingsSchema never declared the field, so marshmallow was silently dropping it from every response. Same class of gap phase 3 hit with timezone/ post_weekly_summary/post_milestones. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
This commit is contained in:
1 parent
ba30d5cb15
commit
515acae233
3 files changed
+53
-3
No files matched your search
+19
-1
@@ -4394,6 +4394,15 @@
|
||||
"type": "boolean",
|
||||
"description": "Post scrobble-count, artist-plays and top-10 milestones as you hit them"
|
||||
},
|
||||
"now_playing_mode": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"off",
|
||||
"profile",
|
||||
"posts"
|
||||
],
|
||||
"description": "`off` (default): nothing. `profile`: a \"Now playing\" field on your profile, refreshed at most every 5 minutes and cleared when you stop. `posts`: the profile field, plus a post for each track played 30+ seconds, at most one every 30 minutes, replacing the last one."
|
||||
},
|
||||
"handle": {
|
||||
"type": "string",
|
||||
"readOnly": true,
|
||||
@@ -4474,6 +4483,15 @@
|
||||
"type": "boolean",
|
||||
"description": "Post scrobble-count, artist-plays and top-10 milestones as you hit them"
|
||||
},
|
||||
"now_playing_mode": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"off",
|
||||
"profile",
|
||||
"posts"
|
||||
],
|
||||
"description": "`off` (default): nothing. `profile`: a \"Now playing\" field on your profile, refreshed at most every 5 minutes and cleared when you stop. `posts`: the profile field, plus a post for each track played 30+ seconds, at most one every 30 minutes, replacing the last one."
|
||||
},
|
||||
"handle": {
|
||||
"type": "string",
|
||||
"readOnly": true,
|
||||
@@ -4520,7 +4538,7 @@
|
||||
},
|
||||
"kind": {
|
||||
"type": "string",
|
||||
"description": "weekly or milestone"
|
||||
"description": "weekly, milestone or now_playing"
|
||||
},
|
||||
"text": {
|
||||
"type": "string"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from marshmallow import Schema, ValidationError, fields, validate
|
||||
|
||||
from scrobbler.federation.models import VISIBILITIES
|
||||
from scrobbler.federation.models import NOW_PLAYING_MODES, VISIBILITIES
|
||||
from scrobbler.federation.protocol.schedule import is_valid_timezone
|
||||
|
||||
|
||||
@@ -44,6 +44,17 @@ class SharingSettingsSchema(Schema):
|
||||
"description": "Post scrobble-count, artist-plays and top-10 milestones as you hit them"
|
||||
}
|
||||
)
|
||||
now_playing_mode = fields.String(
|
||||
validate=validate.OneOf(NOW_PLAYING_MODES),
|
||||
metadata={
|
||||
"description": (
|
||||
'`off` (default): nothing. `profile`: a "Now playing" field on your '
|
||||
"profile, refreshed at most every 5 minutes and cleared when you stop. "
|
||||
"`posts`: the profile field, plus a post for each track played 30+ "
|
||||
"seconds, at most one every 30 minutes, replacing the last one."
|
||||
)
|
||||
},
|
||||
)
|
||||
handle = fields.String(dump_only=True, metadata={"example": "@alice@scrobble.example"})
|
||||
actor_url = fields.String(dump_only=True)
|
||||
profile_url = fields.String(dump_only=True)
|
||||
@@ -89,7 +100,7 @@ class BlockSchema(Schema):
|
||||
|
||||
class PostSchema(Schema):
|
||||
id = fields.Integer()
|
||||
kind = fields.String(metadata={"description": "weekly or milestone"})
|
||||
kind = fields.String(metadata={"description": "weekly, milestone or now_playing"})
|
||||
text = fields.String()
|
||||
visibility = fields.String()
|
||||
created_at = fields.DateTime()
|
||||
|
||||
@@ -56,6 +56,27 @@ def test_an_unknown_timezone_is_rejected(fed_client, fed_auth):
|
||||
assert response.status_code == 422
|
||||
|
||||
|
||||
def test_now_playing_mode_defaults_to_off(fed_client, fed_auth):
|
||||
body = fed_client.get("/api/v1/federation/settings", headers=fed_auth).get_json()
|
||||
assert body["now_playing_mode"] == "off"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mode", ["off", "profile", "posts"])
|
||||
def test_now_playing_mode_can_be_changed(fed_client, fed_auth, mode):
|
||||
response = fed_client.patch(
|
||||
"/api/v1/federation/settings", json={"now_playing_mode": mode}, headers=fed_auth
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.get_json()["now_playing_mode"] == mode
|
||||
|
||||
|
||||
def test_an_unknown_now_playing_mode_is_rejected(fed_client, fed_auth):
|
||||
response = fed_client.patch(
|
||||
"/api/v1/federation/settings", json={"now_playing_mode": "always"}, headers=fed_auth
|
||||
)
|
||||
assert response.status_code == 422
|
||||
|
||||
|
||||
def test_enable_and_change_settings(fed_client, fed_auth, metric_delta):
|
||||
enabled = metric_delta("scrobbler_federation_sharing_changes_total", change="enabled")
|
||||
response = fed_client.patch(
|
||||
|
||||
Reference in new issue
Block a user