feat: 新账号默认不开定时启动,首次登录不自动学习
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
"""新账号默认不开定时启动。已有账号保持原来的开关。"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
revision = "0010_schedule_off_by_default"
|
||||
down_revision = "0009_account_heartbeat"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
with op.batch_alter_table("accounts") as batch:
|
||||
batch.alter_column(
|
||||
"study_schedule_enabled",
|
||||
existing_type=sa.Boolean(),
|
||||
existing_nullable=False,
|
||||
server_default=sa.text("0"),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
with op.batch_alter_table("accounts") as batch:
|
||||
batch.alter_column(
|
||||
"study_schedule_enabled",
|
||||
existing_type=sa.Boolean(),
|
||||
existing_nullable=False,
|
||||
server_default=sa.text("1"),
|
||||
)
|
||||
@@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Boolean, DateTime, Index, String, Text, UniqueConstraint, false as sql_false, text, true as sql_true
|
||||
from sqlalchemy import Boolean, DateTime, Index, String, Text, UniqueConstraint, false as sql_false, text
|
||||
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ class Account(Base):
|
||||
study_paused: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, server_default=sql_false())
|
||||
study_stop_month: Mapped[str] = mapped_column(String(7), nullable=False, default="", server_default=text("''"))
|
||||
study_ignore_window: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, server_default=sql_false())
|
||||
study_schedule_enabled: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True, server_default=sql_true())
|
||||
study_schedule_enabled: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, server_default=sql_false())
|
||||
heartbeat_mode: Mapped[str] = mapped_column(String(16), nullable=False, default="auto", server_default="auto")
|
||||
heartbeat_video_seconds: Mapped[int] = mapped_column(nullable=False, default=30, server_default="30")
|
||||
heartbeat_document_seconds: Mapped[int] = mapped_column(nullable=False, default=120, server_default="120")
|
||||
|
||||
@@ -727,7 +727,7 @@ def test_user_can_set_monthly_study_start(monkeypatch) -> None:
|
||||
"hour": 0,
|
||||
"minute": 0,
|
||||
"second": 0,
|
||||
"enabled": True,
|
||||
"enabled": False,
|
||||
"label": "每月8日 00:00:00",
|
||||
}
|
||||
saved = client.put("/api/settings/study-start", json={"day": 5, "hour": 16, "minute": 0, "second": 7, "enabled": False})
|
||||
@@ -755,6 +755,32 @@ def _freeze_beijing(monkeypatch, year: int, month: int, day: int) -> None:
|
||||
monkeypatch.setattr("euniv.study_window.as_cn", frozen)
|
||||
|
||||
|
||||
def test_new_account_does_not_study_until_the_user_asks(monkeypatch) -> None:
|
||||
import euniv.api as api_module
|
||||
import euniv.service as service_module
|
||||
from euniv.autostudy import work_running
|
||||
|
||||
monkeypatch.setattr(
|
||||
api_module,
|
||||
"login_and_store",
|
||||
lambda db, employee_id, password, manual=False, auto_attempts=3: service_module.login_and_store(
|
||||
db, employee_id, password, FakeClient, manual=manual, auto_attempts=auto_attempts
|
||||
),
|
||||
)
|
||||
client = TestClient(api_module.app)
|
||||
_freeze_beijing(monkeypatch, 2026, 11, 15)
|
||||
assert client.post("/api/login", json={"employee_id": "6650000146", "password": "secret-pass"}).status_code == 200
|
||||
first = client.get("/api/settings/study-control").json()
|
||||
assert first["window_open"] is True
|
||||
assert first["schedule_enabled"] is False
|
||||
assert first["started"] is False
|
||||
assert first["active"] is False
|
||||
assert work_running("6650000146") is False
|
||||
client.put("/api/settings/study-start", json={"day": 8, "hour": 0, "minute": 0, "second": 0, "enabled": True})
|
||||
assert work_running("6650000146") is True
|
||||
assert client.get("/api/settings/study-control").json()["started"] is True
|
||||
|
||||
|
||||
def test_user_can_start_and_stop_study_immediately(monkeypatch) -> None:
|
||||
import euniv.api as api_module
|
||||
import euniv.service as service_module
|
||||
|
||||
Reference in New Issue
Block a user