# Path: virtool/users/utils.py
# PERMISSIONS = [
#     "cancel_job",
#     "create_ref",
#     "create_sample",
#     "modify_hmm",
#     "modify_subtraction",
#     "remove_file",
#     "remove_job",
#     "upload_file",
# ]
# 
# def hash_password(password: str) -> str:
#     """
#     Salt and hash a unicode password. Uses bcrypt.
# 
#     :param password: a password string to salt and hash
#     :return: a salt and hashed password
# 
#     """
#     return bcrypt.hashpw(password.encode(), bcrypt.gensalt(12))


import pytest
from virtool.users.utils import PERMISSIONS, hash_password
        assert resp.status == 201
        assert await resp.json() == snapshot
        assert await client.db.keys.find_one({"id": "foobar_1"}) == snapshot


class TestUpdateAPIKey:
    @pytest.mark.parametrize("has_admin", [True, False])
    @pytest.mark.parametrize("has_perm", [True, False])
    async def test(self, has_admin, has_perm, snapshot, spawn_client, static_time):
        client = await spawn_client(authorize=True)

        await client.db.users.update_one(
            {"_id": "test"},
            {
                "$set": {
                    "administrator": has_admin,
                    "permissions.create_sample": True,
                    "permissions.modify_subtraction": has_perm,
                }
            },
        )

        await client.db.keys.insert_one(
            {
                "_id": "foobar",
                "id": "foobar_0",
                "name": "Foobar",
                "created_at": static_time.datetime,
                "user": {"id": "test"},
                "groups": [],

# Path: virtool/users/utils.py
# PERMISSIONS = [
#     "cancel_job",
#     "create_ref",
#     "create_sample",
#     "modify_hmm",
#     "modify_subtraction",
#     "remove_file",
#     "remove_job",
#     "upload_file",
# ]
# 
# def hash_password(password: str) -> str:
#     """
#     Salt and hash a unicode password. Uses bcrypt.
# 
#     :param password: a password string to salt and hash
#     :return: a salt and hashed password
# 
#     """
#     return bcrypt.hashpw(password.encode(), bcrypt.gensalt(12))


# Path: tests/account/test_api.py
import pytest
from virtool.users.utils import PERMISSIONS, hash_password

        assert resp.status == 201
        assert await resp.json() == snapshot
        assert await client.db.keys.find_one({"id": "foobar_1"}) == snapshot


class TestUpdateAPIKey:
    @pytest.mark.parametrize("has_admin", [True, False])
    @pytest.mark.parametrize("has_perm", [True, False])
    async def test(self, has_admin, has_perm, snapshot, spawn_client, static_time):
        client = await spawn_client(authorize=True)

        await client.db.users.update_one(
            {"_id": "test"},
            {
                "$set": {
                    "administrator": has_admin,
                    "permissions.create_sample": True,
                    "permissions.modify_subtraction": has_perm,
                }
            },
        )

        await client.db.keys.insert_one(
            {
                "_id": "foobar",
                "id": "foobar_0",
                "name": "Foobar",
                "created_at": static_time.datetime,
                "user": {"id": "test"},
                "groups": [],

                "permissions": {p: False for p in PERMISSIONS},