# Path: virtool/users/utils.py
# 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 hashlib
import pytest
import virtool.errors
from aiohttp.test_utils import make_mocked_coro
from virtool.db.transforms import apply_transforms
from virtool.users.db import (
    AttachUserTransform,
    B2CUserAttributes,
    compose_force_reset_update,
    compose_groups_update,
    compose_password_update,
    compose_primary_group_update,
    create,
    edit,
    find_or_create_b2c_user,
    generate_handle,
    update_sessions_and_keys,
    validate_credentials,
)
from virtool.users.utils import hash_password
from virtool.utils import random_alphanumeric




@pytest.mark.parametrize("multiple", [True, False])
async def test_attach_user_transform(multiple, snapshot, dbi, fake):
    user_1 = await fake.users.insert()
    user_2 = await fake.users.insert()

    documents = {"_id": "bar", "user": {"id": user_1["_id"]}}

    if multiple:
        documents = [
            documents,
            {"_id": "foo", "user": {"id": user_2["_id"]}},
            {"_id": "baz", "user": {"id": user_1["_id"]}},

# Path: virtool/users/utils.py
# 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/users/test_db.py
import hashlib
import pytest
import virtool.errors
from aiohttp.test_utils import make_mocked_coro
from virtool.db.transforms import apply_transforms
from virtool.users.db import (
    AttachUserTransform,
    B2CUserAttributes,
    compose_force_reset_update,
    compose_groups_update,
    compose_password_update,
    compose_primary_group_update,
    create,
    edit,
    find_or_create_b2c_user,
    generate_handle,
    update_sessions_and_keys,
    validate_credentials,
)
from virtool.users.utils import hash_password
from virtool.utils import random_alphanumeric





@pytest.mark.parametrize("multiple", [True, False])
async def test_attach_user_transform(multiple, snapshot, dbi, fake):
    user_1 = await fake.users.insert()
    user_2 = await fake.users.insert()

    documents = {"_id": "bar", "user": {"id": user_1["_id"]}}

    if multiple:
        documents = [
            documents,
            {"_id": "foo", "user": {"id": user_2["_id"]}},
            {"_id": "baz", "user": {"id": user_1["_id"]}},

        ]