add support for user.bio, user.accent_color CRUD

This commit is contained in:
Luna 2021-08-29 15:53:00 -03:00
parent 266bb0a07b
commit 0a429ee47e
3 changed files with 42 additions and 0 deletions

View File

@ -227,6 +227,28 @@ async def patch_me():
user_id, user_id,
) )
if to_update(j, user, "bio"):
await app.db.execute(
"""
UPDATE users
SET bio = $1
WHERE id = $2
""",
j["bio"],
user_id,
)
if to_update(j, user, "accent_color"):
await app.db.execute(
"""
UPDATE users
SET accent_color = $1
WHERE id = $2
""",
j["accent_color"],
user_id,
)
if user["email"] is None and "new_password" not in j: if user["email"] is None and "new_password" not in j:
raise BadRequest("missing password", {"password": "Please set a password."}) raise BadRequest("missing password", {"password": "Please set a password."})

View File

@ -110,6 +110,8 @@ class Storage:
"flags", "flags",
"bot", "bot",
"premium_since", "premium_since",
"bio",
"accent_color",
] ]
if secure: if secure:

View File

@ -102,3 +102,21 @@ async def test_create_user(test_cli):
""", """,
int(rjson["id"]), int(rjson["id"]),
) )
WANTED_BIO = "hello world!"
WANTED_ACCENT_COLOR = 0x424242
@pytest.mark.asyncio
async def test_patch_me_bio_accent_color(test_cli_user):
resp = await test_cli_user.patch(
"/api/v6/users/@me",
json={"bio": WANTED_BIO, "accent_color": WANTED_ACCENT_COLOR},
)
assert resp.status_code == 200
rjson = await resp.json
assert isinstance(rjson, dict)
assert rjson["bio"] == WANTED_BIO
assert rjson["accent_color"] == WANTED_ACCENT_COLOR