Skip to content

create_user

Scope: function | Returns: callable

The create_user fixture returns a callable that creates a user in the test database.

Signature

create_user(
    username: str,
    full_name: str = "Happy User",
    active: bool = True,
    login_type: LoginType = LoginType.DEFAULT,
    user_type: UserType = UserType.STANDARD,
    password_hash: str | None = None,
    password: str | None = None,
    api_key_hash: str | None = None,
    api_key_id: str | None = None,
    sid: str = "",
    external_id: str = "",
    _return_entity: bool = False,
) -> LimeUser | int

Info

By default the callable returns the created user's ID as int. Pass _return_entity=True to get the full LimeUser object instead.

Basic usage

def test_something(create_user):
    user_id = create_user(username="alice")

To get the full user object:

def test_something(create_user):
    user = create_user(username="alice", full_name="Alice", _return_entity=True)
    assert user.username == "alice"

Creating users with specific attributes

from lime_authentication.constants import LoginType, UserType

def test_api_key_user(create_user):
    user = create_user(
        username="integration",
        user_type=UserType.SYSTEM,
        api_key_hash="hashed-key",
        api_key_id="key-id",
        _return_entity=True,
    )