Files
disknext/tests/test_db_settings.py
于小丘 69f852a4ce
Some checks failed
Test / test (push) Failing after 1m4s
fix: align all 212 tests with current API and add CI workflows
Update integration tests to match actual endpoint responses: remove
data wrappers, use snake_case fields, correct HTTP methods (PUT→POST
for directory create), status codes (200→204 for mutations), and
request formats (params→json for 2FA). Fix root-level and unit tests
for DatabaseManager migration, model CRUD patterns, and JWT setup.
Add GitHub Actions and Gitea CI configs with ubuntu-latest + Python 3.13.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 14:21:40 +08:00

47 lines
1.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
设置模型 CRUD 测试(使用 db_session fixture
"""
import pytest
from sqlmodel.ext.asyncio.session import AsyncSession
from sqlmodels.setting import Setting, SettingsType
@pytest.mark.asyncio
async def test_settings_curd(db_session: AsyncSession):
"""测试设置的增删改查"""
# 测试增 Create
setting = Setting(
type=SettingsType.BASIC,
name='example_name',
value='example_value',
)
setting = await setting.save(db_session)
assert setting.id is not None
# 测试查 Read
fetched = await Setting.get(
db_session,
(Setting.type == SettingsType.BASIC) & (Setting.name == 'example_name')
)
assert fetched is not None
assert fetched.value == 'example_value'
# 测试改 Update
update_data = Setting(type=SettingsType.BASIC, name='example_name', value='updated_value')
updated = await fetched.update(db_session, update_data)
assert updated is not None
assert updated.value == 'updated_value'
# 测试删 Delete
await Setting.delete(db_session, instances=updated)
deleted = await Setting.get(
db_session,
(Setting.type == SettingsType.BASIC) & (Setting.name == 'example_name')
)
assert deleted is None