33 lines
995 B
Python
33 lines
995 B
Python
## Copyright © 2026 Olaf Kolkman
|
|
## SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
import os
|
|
import tempfile
|
|
|
|
import pytest
|
|
|
|
|
|
TEST_DATABASE_DIRECTORY = tempfile.TemporaryDirectory(prefix='linklog-tests-')
|
|
TEST_DATABASE_PATH = os.path.join(TEST_DATABASE_DIRECTORY.name, 'linklog.db')
|
|
os.environ['LINKLOG_DATABASE_PATH'] = TEST_DATABASE_PATH
|
|
|
|
|
|
@pytest.fixture(scope='session', autouse=True)
|
|
def test_users():
|
|
from backend.app.database import get_connection, hash_password, init_db
|
|
|
|
init_db()
|
|
with get_connection() as conn:
|
|
conn.executemany(
|
|
'''INSERT INTO users
|
|
(id, username, email, password_hash, is_admin, email_verified)
|
|
VALUES (?, ?, ?, ?, ?, 1)''',
|
|
[
|
|
('user-1', 'alice', 'alice@example.com', hash_password('secret123'), 1),
|
|
('user-2', 'bob', 'bob@example.com', hash_password('secret123'), 0),
|
|
],
|
|
)
|
|
conn.commit()
|
|
yield
|
|
TEST_DATABASE_DIRECTORY.cleanup()
|