diff --git a/backend/apps/generation/views.py b/backend/apps/generation/views.py index ebec6a7..a4b014b 100644 --- a/backend/apps/generation/views.py +++ b/backend/apps/generation/views.py @@ -1907,6 +1907,8 @@ def _settings_dict(config): 'base_token_price_video': float(config.base_token_price_video), 'base_token_price_fast': float(config.base_token_price_fast), 'base_token_price_fast_video': float(config.base_token_price_fast_video), + 'base_token_price_1080p': float(config.base_token_price_1080p), + 'base_token_price_1080p_video': float(config.base_token_price_1080p_video), 'announcement': config.announcement, 'announcement_enabled': config.announcement_enabled, 'max_desktop_sessions': config.max_desktop_sessions, diff --git a/backend/tests/test_1080p_api.py b/backend/tests/test_1080p_api.py index 72e348a..3b8398b 100644 --- a/backend/tests/test_1080p_api.py +++ b/backend/tests/test_1080p_api.py @@ -127,5 +127,38 @@ class TestVideoGenerateResolution(TestCase): self.assertNotEqual(body.get('error'), 'invalid_resolution') +class TestAdminSettingsResponse(TestCase): + """GET /api/v1/admin/settings 必须返回所有 token_price 字段, + 以防 v0.19.0 那种"字段在 serializer 里加了、但 _settings_dict 漏了"的回归。""" + + def setUp(self): + QuotaConfig.objects.get_or_create(pk=1) + self.admin = User.objects.create_user( + username='test_admin_settings', + email='test_admin_settings@example.com', + password='testpass123', + is_staff=True, + is_superuser=True, + ) + self.client = APIClient() + self.client.force_authenticate(user=self.admin) + + def test_get_returns_all_token_price_fields(self): + """GET 返回 4 档单价(全部分辨率 + 是否含视频),缺一不可 — 缺字段会导致前端输入框显示空。""" + resp = self.client.get('/api/v1/admin/settings') + self.assertEqual(resp.status_code, 200) + body = resp.json() + for field in ( + 'base_token_price', + 'base_token_price_video', + 'base_token_price_fast', + 'base_token_price_fast_video', + 'base_token_price_1080p', + 'base_token_price_1080p_video', + ): + self.assertIn(field, body, f'GET /admin/settings response missing {field!r} — 前端这个输入框会显示空') + self.assertIsInstance(body[field], (int, float), f'{field} 应该是数字类型') + + if __name__ == '__main__': unittest.main(verbosity=2)