mirror of https://gitlab.com/litecord/litecord.git
test_cli_admin -> test_cli_staff
This commit is contained in:
parent
cc4e4c53a9
commit
7b07254741
|
|
@ -32,6 +32,7 @@ from tests.common import email, TestClient
|
||||||
from run import app as main_app, set_blueprints
|
from run import app as main_app, set_blueprints
|
||||||
|
|
||||||
from litecord.auth import create_user
|
from litecord.auth import create_user
|
||||||
|
from litecord.enums import UserFlags
|
||||||
from litecord.blueprints.auth import make_token
|
from litecord.blueprints.auth import make_token
|
||||||
from litecord.blueprints.users import delete_user
|
from litecord.blueprints.users import delete_user
|
||||||
|
|
||||||
|
|
@ -75,8 +76,6 @@ async def _user_fixture_setup(app):
|
||||||
password = secrets.token_hex(6)
|
password = secrets.token_hex(6)
|
||||||
user_email = email()
|
user_email = email()
|
||||||
|
|
||||||
# TODO context?
|
|
||||||
|
|
||||||
user_id, pwd_hash = await create_user(
|
user_id, pwd_hash = await create_user(
|
||||||
username, user_email, password, app.db, app.loop)
|
username, user_email, password, app.db, app.loop)
|
||||||
|
|
||||||
|
|
@ -108,27 +107,25 @@ async def test_cli_user(test_cli, test_user):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def test_cli_admin(test_cli):
|
async def test_cli_staff(test_cli):
|
||||||
"""Yield a TestClient referencing an admin.
|
"""Yield a TestClient with a staff user."""
|
||||||
|
# This does not use the test_user because if a given test uses both
|
||||||
|
# test_cli_user and test_cli_admin, test_cli_admin will just point to that
|
||||||
|
# same test_cli_user, which isn't acceptable.
|
||||||
|
app = test_cli.app
|
||||||
|
test_user = await _user_fixture_setup(app)
|
||||||
|
user_id = test_user['id']
|
||||||
|
|
||||||
This does not use the test_user because if a given test uses both
|
# copied from manage.cmd.users.set_user_staff.
|
||||||
test_cli_user and test_cli_admin, test_cli_admin will just point to that
|
old_flags = await app.db.fetchval("""
|
||||||
same test_cli_user, which isn't acceptable.
|
SELECT flags FROM users WHERE id = $1
|
||||||
"""
|
""", user_id)
|
||||||
test_user = await _user_fixture_setup(test_cli.app)
|
|
||||||
|
|
||||||
await test_cli.app.db.execute("""
|
new_flags = old_flags | UserFlags.staff
|
||||||
UPDATE users SET admin = true WHERE user_id = $1
|
|
||||||
""", test_user['id'])
|
|
||||||
|
|
||||||
await test_cli.app.db.execute("""
|
await app.db.execute("""
|
||||||
INSERT INTO domain_owners (domain_id, user_id)
|
UPDATE users SET flags = $1 WHERE id = $2
|
||||||
VALUES (0, $1)
|
""", new_flags, user_id)
|
||||||
ON CONFLICT ON CONSTRAINT domain_owners_pkey
|
|
||||||
DO UPDATE
|
|
||||||
SET user_id = $1
|
|
||||||
WHERE domain_owners.domain_id = 0
|
|
||||||
""", test_user['id'])
|
|
||||||
|
|
||||||
yield TestClient(test_cli, test_user)
|
yield TestClient(test_cli, test_user)
|
||||||
await _user_fixture_teardown(test_cli.app, test_user)
|
await _user_fixture_teardown(test_cli.app, test_user)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue