Files
disknext/tests/test_db_user.py
于小丘 209cb24ab4 feat: add models for physical files, policies, and user management
- Implement PhysicalFile model to manage physical file references and reference counting.
- Create Policy model with associated options and group links for storage policies.
- Introduce Redeem and Report models for handling redeem codes and reports.
- Add Settings model for site configuration and user settings management.
- Develop Share model for sharing objects with unique codes and associated metadata.
- Implement SourceLink model for managing download links associated with objects.
- Create StoragePack model for managing user storage packages.
- Add Tag model for user-defined tags with manual and automatic types.
- Implement Task model for managing background tasks with status tracking.
- Develop User model with comprehensive user management features including authentication.
- Introduce UserAuthn model for managing WebAuthn credentials.
- Create WebDAV model for managing WebDAV accounts associated with users.
2026-02-10 19:07:48 +08:00

58 lines
1.8 KiB
Python

import pytest
@pytest.mark.asyncio
async def test_user_curd():
"""测试数据库的增删改查"""
from sqlmodels import database, migration
from sqlmodels.group import Group
from sqlmodels.user import User
await database.init_db(url='sqlite+aiosqlite:///:memory:')
await migration.migration()
async for session in database.get_session():
# 新建一个测试用户组
test_user_group = Group(name='test_user_group')
created_group = await test_user_group.save(session)
test_user = User(
email='test_user@test.local',
password='test_password',
group_id=created_group.id
)
# 测试增 Create
created_user = await test_user.save(session)
# 验证用户是否存在
assert created_user.id is not None
assert created_user.email == 'test_user@test.local'
assert created_user.password == 'test_password'
assert created_user.group_id == created_group.id
# 测试查 Read
fetched_user = await User.get(session, User.id == created_user.id)
assert fetched_user is not None
assert fetched_user.email == 'test_user@test.local'
assert fetched_user.password == 'test_password'
assert fetched_user.group_id == created_group.id
# 测试改 Update
updated_user = await fetched_user.update(
session,
{"email": "updated_user@test.local", "password": "updated_password"}
)
assert updated_user is not None
assert updated_user.email == 'updated_user@test.local'
assert updated_user.password == 'updated_password'
# 测试删除 Delete
await updated_user.delete(session)
deleted_user = await User.get(session, User.id == updated_user.id)
assert deleted_user is None
break