feat(weibo): 优化协作单详情并增加已上脚本状态
This commit is contained in:
@@ -29,14 +29,13 @@ from web.backend.models import (
|
||||
HuyaExternalOrder,
|
||||
User,
|
||||
WeiboAccount,
|
||||
WeiboExternalOrder,
|
||||
)
|
||||
|
||||
TESTS_DIR = Path(__file__).resolve().parent
|
||||
PROJECT_ROOT = TESTS_DIR.parent
|
||||
VERSIONS_DIR = PROJECT_ROOT / "web" / "backend" / "migrations" / "versions"
|
||||
|
||||
HEAD_REVISION = "20261112_0079"
|
||||
HEAD_REVISION = "20261112_0080"
|
||||
|
||||
# 迁移新增、但不声明在模型里的复合查询索引。
|
||||
EXTRA_INDEXES = (
|
||||
@@ -441,14 +440,16 @@ class TestMigrationSmoke:
|
||||
cfg.set_main_option("sqlalchemy.url", mig_url)
|
||||
command.upgrade(cfg, "20261112_0078")
|
||||
|
||||
with Session(mig_engine) as session:
|
||||
order = WeiboExternalOrder(
|
||||
order_no="MIG-0079-PENDING",
|
||||
status="exchange_pending",
|
||||
exchange_started_at=datetime(2026, 11, 12, 8, 30, tzinfo=UTC),
|
||||
with mig_engine.begin() as conn:
|
||||
conn.execute(
|
||||
text(
|
||||
"INSERT INTO weibo_external_orders "
|
||||
"(order_no, status, exchange_started_at, created_at, updated_at) "
|
||||
"VALUES ('MIG-0079-PENDING', 'exchange_pending', "
|
||||
"'2026-11-12 08:30:00', "
|
||||
"'2026-11-12 08:00:00', '2026-11-12 08:30:00')"
|
||||
)
|
||||
)
|
||||
session.add(order)
|
||||
session.commit()
|
||||
|
||||
command.upgrade(cfg, "20261112_0079")
|
||||
|
||||
@@ -467,3 +468,56 @@ class TestMigrationSmoke:
|
||||
mig_engine.dispose()
|
||||
with admin_engine.begin() as conn:
|
||||
conn.execute(text(f"DROP DATABASE IF EXISTS `{mig_db}`;"))
|
||||
|
||||
def test_0080_backfills_scripted_at_for_done_orders(self):
|
||||
creds = get_mysql_credentials()
|
||||
mig_db = f"douyu_login_mig_{secrets.token_hex(4)}"
|
||||
mig_url = (
|
||||
f"mysql+pymysql://{quote_plus(creds['user'])}:"
|
||||
f"{quote_plus(creds['password'])}@{creds['host']}:{creds['port']}/"
|
||||
f"{mig_db}?charset=utf8mb4"
|
||||
)
|
||||
|
||||
admin_engine = get_test_engine()
|
||||
with admin_engine.begin() as conn:
|
||||
conn.execute(
|
||||
text(
|
||||
f"CREATE DATABASE `{mig_db}` "
|
||||
"CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;"
|
||||
)
|
||||
)
|
||||
|
||||
original_url = database_module.DATABASE_URL
|
||||
mig_engine = create_engine(mig_url)
|
||||
try:
|
||||
database_module.DATABASE_URL = mig_url
|
||||
cfg = _migration_config()
|
||||
cfg.set_main_option("sqlalchemy.url", mig_url)
|
||||
command.upgrade(cfg, "20261112_0079")
|
||||
with mig_engine.begin() as conn:
|
||||
conn.execute(
|
||||
text(
|
||||
"INSERT INTO weibo_external_orders "
|
||||
"(order_no, status, exchange_started_at, done_at, "
|
||||
" created_at, updated_at) "
|
||||
"VALUES ('MIG-0080-DONE', 'done', "
|
||||
"'2026-11-12 08:00:00', '2026-11-12 08:10:00', "
|
||||
"'2026-11-12 07:00:00', '2026-11-12 08:10:00')"
|
||||
)
|
||||
)
|
||||
|
||||
command.upgrade(cfg, "20261112_0080")
|
||||
|
||||
with mig_engine.connect() as conn:
|
||||
row = conn.execute(
|
||||
text(
|
||||
"SELECT scripted_at FROM weibo_external_orders "
|
||||
"WHERE order_no = 'MIG-0080-DONE'"
|
||||
)
|
||||
).one()
|
||||
assert row.scripted_at is not None
|
||||
finally:
|
||||
database_module.DATABASE_URL = original_url
|
||||
mig_engine.dispose()
|
||||
with admin_engine.begin() as conn:
|
||||
conn.execute(text(f"DROP DATABASE IF EXISTS `{mig_db}`;"))
|
||||
|
||||
@@ -146,7 +146,9 @@ def test_exchange_record_unique_match_and_archive(monkeypatch, db):
|
||||
|
||||
monkeypatch.setattr(collab, "WeiboClient", FakeClient)
|
||||
collab.set_status(db, user, first, collab.STATUS_RECHARGED)
|
||||
collab.set_status(db, user, first, collab.STATUS_SCRIPTED)
|
||||
collab.set_status(db, user, second, collab.STATUS_RECHARGED)
|
||||
assert first.scripted_at is not None
|
||||
|
||||
result = collab.check_exchange_records(db, user, [first, second])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user