From 9547b5e536ab7541d8acd70ba7ebc4af1083c40f Mon Sep 17 00:00:00 2001 From: Luna Mendes Date: Sat, 17 Nov 2018 18:39:09 -0300 Subject: [PATCH] tests: add test_user - tests.common: add get_uid --- tests/common.py | 12 ++++++++++++ tests/test_user.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 tests/test_user.py diff --git a/tests/common.py b/tests/common.py index da8cde0..1b5f646 100644 --- a/tests/common.py +++ b/tests/common.py @@ -13,3 +13,15 @@ async def login(acc_name: str, test_cli): rjson = await resp.json return rjson['token'] + + +async def get_uid(token, test_cli): + resp = await test_cli.get('/api/v6/users/@me', headers={ + 'Authorization': token + }) + + if resp.status_code != 200: + raise RuntimeError(f'non-200 on get uid: {resp.status_code}') + + rjson = await resp.json + return rjson['id'] diff --git a/tests/test_user.py b/tests/test_user.py new file mode 100644 index 0000000..fda37e1 --- /dev/null +++ b/tests/test_user.py @@ -0,0 +1,46 @@ +import pytest + +from tests.common import login, get_uid + + +@pytest.mark.asyncio +async def test_get_me(test_cli): + token = await login('normal', test_cli) + resp = await test_cli.get('/api/v6/users/@me', headers={ + 'Authorization': token + }) + + assert resp.status_code == 200 + rjson = await resp.json + assert isinstance(rjson, dict) + + +@pytest.mark.asyncio +async def test_get_me_guilds(test_cli): + token = await login('normal', test_cli) + resp = await test_cli.get('/api/v6/users/@me/guilds', headers={ + 'Authorization': token + }) + + assert resp.status_code == 200 + rjson = await resp.json + assert isinstance(rjson, list) + + +@pytest.mark.asyncio +async def test_get_profile_self(test_cli): + token = await login('normal', test_cli) + user_id = await get_uid(token, test_cli) + + resp = await test_cli.get(f'/api/v6/users/{user_id}/profile', headers={ + 'Authorization': token + }) + + assert resp.status_code == 200 + rjson = await resp.json + assert isinstance(rjson, dict) + assert isinstance(rjson['user'], dict) + assert isinstance(rjson['connected_accounts'], list) + assert (rjson['premium_since'] is None + or isinstance(rjson['premium_since'], str)) + assert isinstance(rjson['mutual_guilds'], list)