- 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.
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
import pytest
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_settings_curd():
|
|
"""测试数据库的增删改查"""
|
|
from sqlmodels import database
|
|
from sqlmodels.setting import Setting
|
|
|
|
await database.init_db(url='sqlite:///:memory:')
|
|
|
|
# 测试增 Create
|
|
await Setting.add(
|
|
type='example_type',
|
|
name='example_name',
|
|
value='example_value')
|
|
|
|
# 测试查 Read
|
|
setting = await Setting.get(
|
|
type='example_type',
|
|
name='example_name')
|
|
|
|
assert setting is not None, "设置项应该存在"
|
|
assert setting == 'example_value', "设置值不匹配"
|
|
|
|
# 测试改 Update
|
|
await Setting.set(
|
|
type='example_type',
|
|
name='example_name',
|
|
value='updated_value')
|
|
|
|
after_update_setting = await Setting.get(
|
|
type='example_type',
|
|
name='example_name'
|
|
)
|
|
|
|
assert after_update_setting is not None, "设置项应该存在"
|
|
assert after_update_setting == 'updated_value', "更新后的设置值不匹配"
|
|
|
|
# 测试删 Delete
|
|
await Setting.delete(
|
|
type='example_type',
|
|
name='example_name')
|
|
|
|
after_delete_setting = await Setting.get(
|
|
type='example_type',
|
|
name='example_name'
|
|
)
|
|
|
|
assert after_delete_setting is None, "设置项应该被删除" |