78 lines
4.1 KiB
Python
78 lines
4.1 KiB
Python
|
|
"""Acceptance tests for V5 visual packages and honest commercial readiness."""
|
||
|
|
import json
|
||
|
|
from pathlib import Path
|
||
|
|
from bs4 import BeautifulSoup
|
||
|
|
from app import theme_store,db,builder,commercial_readiness
|
||
|
|
from test_factory_v2 import factory,site
|
||
|
|
|
||
|
|
def test_all_four_new_versions_have_complete_offline_artwork(factory):
|
||
|
|
for theme in ('automotive','industrial','corporate','minimal'):
|
||
|
|
versions=factory.get(f'/api/factory/themes/{theme}/versions').json()
|
||
|
|
names={row['version'] for row in versions}
|
||
|
|
assert {'1.1.0','1.0.0','0.3.0'} <= names
|
||
|
|
folder=theme_store.resolve(theme,'1.1.0')
|
||
|
|
assert (folder/'visual/hero.svg').read_text().startswith('<svg ')
|
||
|
|
assert (folder/'pages/product.html').is_file()
|
||
|
|
assert theme_store.compatibility(theme,'1.1.0')['valid']
|
||
|
|
|
||
|
|
def test_site_build_contains_commercial_css_artwork_and_report(factory):
|
||
|
|
sid=site(factory)
|
||
|
|
assert factory.post(f'/api/factory/sites/{sid}/bootstrap').status_code==200
|
||
|
|
assert factory.put(f'/api/factory/sites/{sid}/theme',json={'theme':'industrial','version':'1.1.0'}).status_code==200
|
||
|
|
result=factory.post(f'/api/sites/{sid}/builds',json={})
|
||
|
|
assert result.status_code==200,result.text
|
||
|
|
bid=result.json()['version']
|
||
|
|
url=f'/preview/{sid}/{bid}'
|
||
|
|
home=factory.get(url+'/').text
|
||
|
|
soup=BeautifulSoup(home,'html.parser')
|
||
|
|
assert soup.select_one('link[href="assets/commercial.css"]')
|
||
|
|
assert len(soup.select('h1'))==1
|
||
|
|
assert soup.select_one('meta[property="og:title"]')
|
||
|
|
assert factory.get(url+'/assets/commercial.css').status_code==200
|
||
|
|
svg=factory.get(url+'/assets/visual/hero.svg')
|
||
|
|
assert svg.status_code==200 and '<svg' in svg.text
|
||
|
|
report=factory.get(f'/api/sites/{sid}/builds/{bid}/report').json()
|
||
|
|
assert not report['errors']
|
||
|
|
assert report['commercial_readiness']['commercially_certified'] is False
|
||
|
|
handoff=factory.get(url+'/commercial-readiness.json')
|
||
|
|
assert handoff.status_code==200
|
||
|
|
obj=handoff.json();assert obj['commercially_certified'] is False
|
||
|
|
assert any(w['code']=='brand_logo' for w in obj['warnings'])
|
||
|
|
|
||
|
|
def test_theme_rollback_keeps_previous_version(factory):
|
||
|
|
sid=site(factory)
|
||
|
|
for version in ('1.0.0','1.1.0'):
|
||
|
|
selected=factory.put(f'/api/factory/sites/{sid}/theme',json={'theme':'automotive','version':version})
|
||
|
|
assert selected.status_code==200,selected.text
|
||
|
|
result=factory.post(f'/api/sites/{sid}/builds',json={})
|
||
|
|
assert result.status_code==200,result.text
|
||
|
|
html=factory.get(f'/preview/{sid}/{result.json()["version"]}/').text
|
||
|
|
assert ('assets/commercial.css' in html)==(version=='1.1.0')
|
||
|
|
|
||
|
|
def test_readiness_detects_missing_required_pages_and_contact(tmp_path):
|
||
|
|
root=tmp_path
|
||
|
|
(root/'index.html').write_text('<html><head><title>Test</title></head><body><h1>Test</h1></body></html>')
|
||
|
|
report=commercial_readiness.inspect(root)
|
||
|
|
assert not report['ready_for_review']
|
||
|
|
assert report['commercially_certified'] is False
|
||
|
|
assert any(x['code']=='page_missing' for x in report['blockers'])
|
||
|
|
|
||
|
|
def test_online_theme_preview_loads_same_css_and_hero(factory):
|
||
|
|
preview=factory.get('/api/factory/themes/automotive/preview',params={'version':'1.1.0','page_type':'home'})
|
||
|
|
assert preview.status_code==200
|
||
|
|
assert '/ui/commercial.css' in preview.text
|
||
|
|
sheet=factory.get('/ui/commercial.css')
|
||
|
|
assert sheet.status_code==200 and 'pro-filter-panel' in sheet.text
|
||
|
|
art=factory.get('/api/factory/themes/automotive/visual/hero.svg',params={'version':'1.1.0'})
|
||
|
|
assert art.status_code==200 and 'image/svg+xml' in art.headers['content-type']
|
||
|
|
assert factory.get('/api/factory/themes/automotive/visual/hero.svg',params={'version':'1.0.0'}).status_code==404
|
||
|
|
|
||
|
|
def test_custom_declarative_theme_inherits_trusted_visuals(factory):
|
||
|
|
import io,zipfile
|
||
|
|
from test_factory_v2 import zip_theme
|
||
|
|
blob=io.BytesIO(zip_theme('art-compatible','2.0.0'))
|
||
|
|
response=factory.post('/api/factory/themes/install',files={'file':('theme.zip',blob.getvalue(),'application/zip')})
|
||
|
|
assert response.status_code==200,response.text
|
||
|
|
folder=theme_store.resolve('art-compatible','2.0.0')
|
||
|
|
assert (folder/'visual/hero.svg').is_file()
|