Support categorized fragments, theme presets, block widths, and server-backed theme editing with onboarding and preview. Include Site Studio, design sources, specification and verification reports; remove the legacy studio-site example.
135 lines
5.8 KiB
Python
135 lines
5.8 KiB
Python
"""Install a wheel and smoke real FastAPI outside the checkout, without design/."""
|
|
|
|
import argparse
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--site", type=Path, default=ROOT / "examples/studio-site")
|
|
args = parser.parse_args()
|
|
with tempfile.TemporaryDirectory(prefix="cms-installed-001-") as tmp:
|
|
work = Path(tmp)
|
|
project = work / "project"
|
|
project.mkdir()
|
|
for name in ("pyproject.toml", "README.md"):
|
|
shutil.copyfile(ROOT / name, project / name)
|
|
shutil.copytree(
|
|
ROOT / "src",
|
|
project / "src",
|
|
ignore=shutil.ignore_patterns("*.egg-info", "__pycache__"),
|
|
)
|
|
subprocess.run(
|
|
[
|
|
sys.executable,
|
|
"-m",
|
|
"pip",
|
|
"wheel",
|
|
str(project),
|
|
"--no-deps",
|
|
"--no-build-isolation",
|
|
"-q",
|
|
"-w",
|
|
str(work / "wheels"),
|
|
],
|
|
check=True,
|
|
)
|
|
wheel = next((work / "wheels").glob("*.whl"))
|
|
target = work / "installed"
|
|
subprocess.run(
|
|
[
|
|
sys.executable,
|
|
"-m",
|
|
"pip",
|
|
"install",
|
|
"--no-deps",
|
|
"--target",
|
|
str(target),
|
|
str(wheel),
|
|
"-q",
|
|
],
|
|
check=True,
|
|
)
|
|
shutil.copytree(
|
|
args.site, work / "site", ignore=shutil.ignore_patterns(".engine")
|
|
)
|
|
env = dict(
|
|
os.environ,
|
|
PYTHONPATH=str(target),
|
|
SITE_ROOT=str(work / "site"),
|
|
SITE_DIST=str(work / "dist"),
|
|
SITE_STATE_DIR=str(work / "state"),
|
|
SITE_COOKIE_SECURE="0",
|
|
SITE_SECRET_KEY="installed-test-secret-" * 3,
|
|
SITE_ADMIN_ORIGIN="http://127.0.0.1:9100",
|
|
SITE_PREVIEW_ORIGIN="http://127.0.0.1:9101",
|
|
)
|
|
program = """
|
|
import html, os, re
|
|
from pathlib import Path
|
|
from fastapi.testclient import TestClient
|
|
from site_engine.services.auth import hash_password
|
|
from site_engine.web.app import create_app
|
|
from site_engine.web.preview_app import create_preview_app
|
|
import site_engine
|
|
assert str(Path(site_engine.__file__).resolve()).startswith(os.environ['PYTHONPATH'])
|
|
from site_engine.core.theme import preset_catalog, resolve_theme
|
|
from site_engine.errors import Report
|
|
for name, preset in preset_catalog().items():
|
|
overrides={k:preset[k] for k in ('colors','type','ui')} if name=='custom' else {}
|
|
report=Report()
|
|
theme=resolve_theme(dict(schema=1,preset=name,preset_version=1,overrides=overrides), report)
|
|
assert theme and report.ok,(name,report)
|
|
from site_engine.build.pipeline import build_site
|
|
build_site(Path(os.environ['SITE_ROOT']),Path(os.environ['SITE_DIST']))
|
|
os.environ['SITE_ADMIN_PASSWORD_HASH']=hash_password('installed wheel password',n=2**10)
|
|
os.environ['SITE_ADMIN_LOGIN']='admin'
|
|
app=create_app()
|
|
with TestClient(app) as client:
|
|
response=client.post('/admin/login',data={'login':'admin','password':'installed wheel password'},headers={'Origin':'http://testserver'})
|
|
assert response.status_code==200
|
|
response=client.get('/admin/pages/index')
|
|
assert response.status_code==200 and 'document-editor' in response.text
|
|
for name in ('antirion-rework.css','shell.css','pages.css','pages.js','admin.css','admin.js','editor.js','builder.css','builder-adapter.css','builder.js','htmx.min.js','theme-studio.css','theme-studio.js'):
|
|
assert client.get('/admin/static/'+name).status_code==200,name
|
|
assert 'pages-screen' in client.get('/admin/pages').text
|
|
cookie=client.cookies.get('se_session')
|
|
principal=app.state.auth.authenticate(cookie)
|
|
csrf=app.state.auth.csrf_token(principal)
|
|
source=(Path(os.environ['SITE_ROOT'])/'pages/index.md').read_text()
|
|
from site_engine.storage.fs import etag_of
|
|
result=client.post('/admin/editor/pages/index/preview',data={'source':source,'etag':etag_of(source.encode()),'csrf':csrf},headers={'Origin':'http://testserver','HX-Request':'true'})
|
|
assert result.status_code==200,result.text
|
|
url=html.unescape(re.search(r"src='([^']+)'",result.text)[1])
|
|
with TestClient(create_preview_app()) as preview:
|
|
result=preview.get(url)
|
|
assert result.status_code==200,result.text
|
|
assert 'preview:ready' in result.text and 'data-preview-id' in result.text
|
|
assert 'data-section-width' in result.text and '--container-max:' in result.text
|
|
assert 'theme-bootstrap' in client.get('/admin/theme').text
|
|
import json
|
|
document={'schema':1,'preset':'dark','preset_version':1,'overrides':{}}
|
|
result=client.post('/admin/theme/validate',data={'csrf':csrf,'payload':json.dumps({'document':document,'revision':17})},headers={'Origin':'http://testserver','HX-Request':'true'})
|
|
assert result.status_code==200 and result.json()['revision']==17,result.text
|
|
result=client.post('/admin/theme/preview',data={'csrf':csrf,'payload':json.dumps({'document':document,'revision':17})},headers={'Origin':'http://testserver','HX-Request':'true'})
|
|
assert result.status_code==200,result.text
|
|
with TestClient(create_preview_app()) as preview:
|
|
result=preview.get(result.json()['url'])
|
|
assert result.status_code==200 and 'sample-site' in result.text,result.text
|
|
assert '--color-primary: #a48bfa' in result.text
|
|
assert app.state.api_calls>0
|
|
print('installed wheel: all theme presets, build, widths, static, templates, Theme Manager, API, bridge, separate preview OK; design/ absent')
|
|
"""
|
|
subprocess.run([sys.executable, "-c", program], cwd=work, env=env, check=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|