From 0a429ee47eaceeaaf6a221c8aca973b831c6e6d7 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 29 Aug 2021 15:53:00 -0300 Subject: [PATCH] add support for user.bio, user.accent_color CRUD --- litecord/blueprints/users.py | 22 ++++++++++++++++++++++ litecord/storage.py | 2 ++ tests/test_user.py | 18 ++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/litecord/blueprints/users.py b/litecord/blueprints/users.py index 7a46a78..5a91735 100644 --- a/litecord/blueprints/users.py +++ b/litecord/blueprints/users.py @@ -227,6 +227,28 @@ async def patch_me(): 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: raise BadRequest("missing password", {"password": "Please set a password."}) diff --git a/litecord/storage.py b/litecord/storage.py index e3ac555..fe826ad 100644 --- a/litecord/storage.py +++ b/litecord/storage.py @@ -110,6 +110,8 @@ class Storage: "flags", "bot", "premium_since", + "bio", + "accent_color", ] if secure: diff --git a/tests/test_user.py b/tests/test_user.py index 0caf14b..9e0c77a 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -102,3 +102,21 @@ async def test_create_user(test_cli): """, 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