fix: preserve data granularity and recover tasks safely

This commit is contained in:
Codex
2026-10-11 14:18:56 +08:00
parent 23f3a15a15
commit 603184549b
29 changed files with 4557 additions and 418 deletions
+58
View File
@@ -64,3 +64,61 @@ def test_same_year_different_college_lines_are_not_attached_arbitrarily(tmp_path
db.upsert_scores(select_score_lines(rows, "081200", "10001", "北京大学", 2026))
assert db.query_catalog({"year": 2026})["items"][0]["score_total"] is None
def test_special_plan_score_does_not_overwrite_regular_admission_line(tmp_path):
db = Database(tmp_path / "studio.db")
db.upsert_catalog(normalize_catalog(raw_catalog(), 2026))
rows = [{"code": "081200", "total": "320", "depart_id": "001", "note": ""}, {"code": "081200", "total": "260", "depart_id": "001", "note": "少干专项计划"}]
db.upsert_scores(select_score_lines(rows, "081200", "10001", "北京大学", 2026))
assert db.overview()["scores"] == 2
assert db.query_catalog({})["items"][0]["score_total"] == 320
def test_special_plan_full_names_are_not_used_as_regular_reference_line(tmp_path):
db = Database(tmp_path / 'studio.db')
db.upsert_catalog(normalize_catalog(raw_catalog(), 2026))
rows = [{'code': '081200', 'total': 320, 'depart_id': '001', 'note': ''}, {'code': '081200', 'total': 260, 'depart_id': '001', 'note': '少数民族骨干计划'}, {'code': '081200', 'total': 250, 'depart_id': '001', 'note': '退役大学生士兵计划'}]
db.upsert_scores(select_score_lines(rows, '081200', '10001', '北京大学', 2026))
assert db.query_catalog({})['items'][0]['score_total'] == 320
def test_spreadsheet_roundtrip_preserves_record_identity(tmp_path):
from studio.imports import export_sheet, import_file
db = Database(tmp_path / 'studio.db')
records = normalize_catalog(raw_catalog(), 2027)
db.upsert_catalog(records)
for kind in ('csv', 'xlsx'):
path = tmp_path / ('data.' + kind)
path.write_bytes(export_sheet(records, kind))
imported, _ = import_file(path)
db.upsert_catalog(imported)
assert db.query_catalog({})['total'] == 2
def test_known_historical_school_levels_are_available_in_filters(tmp_path):
db = Database(tmp_path / 'studio.db')
db.upsert_catalog(normalize_catalog(raw_catalog(), 2027))
assert db.query_catalog({'level': '985'})['total'] == 2
assert db.query_catalog({'level': '211'})['total'] == 2
def test_imported_college_quota_cannot_be_promoted_by_numeric_column():
from studio.imports import row_record
row = row_record({'school_name':'Test','major_code':'081200','enrollment_text':'学院:100','enrollment_count':100},2026)
assert row['quota'] is None
assert row['quota_scope'] == 'college'
def test_job_school_keyword_does_not_match_department_names(tmp_path):
db = Database(tmp_path / 'studio.db')
item = raw_catalog()
item['yxsmc'] = '信息学院'
db.upsert_catalog(normalize_catalog(item, 2027))
assert db.query_catalog({'school_keyword': '信息'})['total'] == 0
def test_yam_reference_books_are_arrays_for_the_detail_view():
from studio.imports import row_record
row = row_record({'school_name':'Test','major_code':'081200','reference_books':'[]'},2026)
assert row['reference_books'] == []