Files
cms-SiteForge/tests/test_p0_backup.py
T
浅念 8cea7dee20 chore: baseline V8.10.0-dev.1 with v8_workflows type-mapping fix and trade-pro spec
- SiteForge Enterprise V8.10.0-dev.1 upstream source (210 tests)
- Fix: v8_workflows._mapped_input now reads both 类型/分类 columns so WXR
  imports keep post/product types instead of collapsing to page
- Docs: trade-pro theme port spec (R3) and implementation plan

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-10-22 16:49:25 +08:00

29 lines
1.2 KiB
Python

"""Offline SQLite backup + restore smoke in an isolated directory."""
import sqlite3
import zipfile
from pathlib import Path
from app import db, backup
from scripts.restore_backup import restore
def test_sqlite_backup_and_restore_with_media(tmp_path,monkeypatch):
storage=tmp_path/'original'
storage.mkdir()
monkeypatch.setattr(db,'DATA',storage)
monkeypatch.setattr(db,'DB_FILE',storage/'siteforge.sqlite3')
db.init()
db.execute('INSERT INTO sites(id,name,created_at,updated_at) VALUES (?,?,?,?)',
('restorecheck','Recovered Site',db.now(),db.now()))
media=storage/'media'/'restorecheck'/'logo.svg'
media.parent.mkdir(parents=True)
media.write_text('<svg/>',encoding='utf-8')
dest=backup.backup()
with zipfile.ZipFile(dest) as z:
assert 'siteforge.sqlite3' in z.namelist()
assert 'media/restorecheck/logo.svg' in z.namelist()
recovered=tmp_path/'restored'
restore(dest,recovered,confirmed=True)
with sqlite3.connect(recovered/'siteforge.sqlite3') as c:
assert c.execute("SELECT name FROM sites WHERE id='restorecheck'").fetchone()[0]=='Recovered Site'
assert (recovered/'media'/'restorecheck'/'logo.svg').read_text(encoding='utf-8')=='<svg/>'