"""V8.33.1: industrial/hesupipe advantage and dynamic-card regression.""" import json from pathlib import Path from bs4 import BeautifulSoup from app import blueprints, theme_store from test_factory_v2 import factory, site def _blocks(): return [ {'id':'benefits-1234','type':'features','title':'我们的核心优势','items':[ {'title':'专业管道解决方案','text':'支持项目选型、施工方案和规格咨询。'}, {'title':'严格质量控制','text':'规格清晰,支持检验与资料交付。'}, {'title':'丰富的项目经验','text':'多种应用场景和工程项目。'}, {'title':'国际供应能力','text':'支持国际物流和技术服务。'}]}, {'id':'productss-1234','type':'collection','title':'热销管道产品','subtitle':'PRODUCT SOLUTIONS', 'source':'product','limit':6,'columns':3,'button':'浏览所有产品','href':'/products/'}, ] def test_features_four_cards_form_balanced_rows(): markup=blueprints.render_blocks(_blocks()[:1],{}, {'route':'/','type':'page'}, []) assert 'style="--sf-feature-cols:4"' in markup soup=BeautifulSoup(markup,'html.parser') assert len(soup.select('.sf-features .sf-feature'))==4 assert all(x.select_one('h3') for x in soup.select('.sf-feature')) def test_home_dynamic_list_no_filters_and_listing_filter_present(): rows=[{'route':'/products/p'+str(i)+'/','title':'测试管件 '+str(i),'type':'product','cover':'', 'summary':'HDPE 工程管材','meta_json':'{}'} for i in range(12)] home=blueprints.render_blocks(_blocks()[1:],{}, {'route':'/','type':'page'},rows) assert 'data-sf-filterable="false"' in home assert home.count('class="sf-item"')==6 listing=blueprints.render_blocks([dict(_blocks()[1],limit=12)],{}, {'route':'/products/','type':'page'},rows) assert 'data-sf-filterable="true"' in listing assert listing.count('class="sf-item"')==12 def test_industrial_new_css_and_version_archive(): theme=theme_store.resolve('industrial') assert theme_store.latest('industrial')=='1.3.1' assert theme_store.resolve('industrial','1.3.0')!=theme css=(theme/'blocks.css').read_text() assert '.sf-theme-industrial .pro-custom-content .sf-section.sf-features > .sf-container > .sf-features' in css assert 'object-fit:contain' in css assert '.sf-section.sf-collection,.sf-section.sf-stats' in (Path(__file__).parents[1]/'app/static/blocks.css').read_text() assert not (theme_store.resolve('industrial','1.3.0')/'blocks.css').exists() def test_hesupipe_real_builder_preview_and_archive(factory): sid=site(factory) assert factory.put(f'/api/factory/sites/{sid}/theme',json={'theme':'industrial','version':'1.3.1'}).status_code==200 home=next(x for x in factory.get(f'/api/sites/{sid}/entries').json() if x['route']=='/') for i in range(1,7): item=factory.post(f'/api/sites/{sid}/entries',json={ 'type':'product','title':f'HDPE 管道产品 {i}','route':f'/products/hdpe-{i}/', 'summary':'适用于市政供水和工业管线的专业产品'}) assert item.status_code==201,item.text saved=factory.put(f'/api/sites/{sid}/pages/{home["id"]}/blueprint',json={'blocks':_blocks(),'page_template':'home'}) assert saved.status_code==200,saved.text built=factory.post(f'/api/sites/{sid}/builds',json={}) assert built.status_code==200,built.text version=built.json()['version'] html=factory.get(f'/preview/{sid}/{version}/').text soup=BeautifulSoup(html,'html.parser') assert soup.select_one('.sf-theme-industrial .pro-custom-content .sf-features[style*="--sf-feature-cols:4"]') assert len(soup.select('.pro-custom-content .sf-collection .sf-item'))==6 assert soup.select_one('.pro-custom-content .sf-collection[data-sf-filterable]').get('data-sf-filterable')=='false' styles=factory.get(f'/preview/{sid}/{version}/assets/blocks.css').text assert '.sf-theme-industrial .pro-custom-content .sf-item-img' in styles js=factory.get(f'/preview/{sid}/{version}/assets/site-runtime.js').text assert 'data-sf-filterable' in js report=factory.get(f'/api/sites/{sid}/builds/{version}/report').json() assert not report['errors'] assert factory.put(f'/api/factory/sites/{sid}/theme',json={'theme':'industrial','version':'1.3.0'}).status_code==200 older=factory.post(f'/api/sites/{sid}/builds',json={}) assert older.status_code==200,older.text oldcss=factory.get(f'/preview/{sid}/{older.json()["version"]}/assets/blocks.css').text assert '.sf-theme-industrial .pro-custom-content .sf-item-img' not in oldcss