58 lines
3.6 KiB
Python
58 lines
3.6 KiB
Python
from pathlib import Path
|
|
import datetime,hashlib,json,ssl,sys,urllib.request,urllib.parse
|
|
from html.parser import HTMLParser
|
|
out=Path(__file__).resolve().parent;root=out.parents[1]
|
|
phase=sys.argv[1];assert phase in ['before','after','installed']
|
|
ctx=ssl.create_default_context(cafile='C:/Users/macbook/.config/investmoz/tls/portal-investidor.test-fullchain.pem')
|
|
base='https://portal-investidor.test';checks=[]
|
|
def get(path,j=False):
|
|
with urllib.request.urlopen(urllib.request.Request(base+path,headers={'Accept':'application/json' if j else 'text/html'}),context=ctx,timeout=45)as r:
|
|
data=r.read();assert r.status==200
|
|
checks.append({'method':'GET','path':path,'status':r.status,'bytes':len(data),'sha256':hashlib.sha256(data).hexdigest()})
|
|
return json.loads(data)if j else data
|
|
class Parser(HTMLParser):
|
|
def __init__(self):super().__init__();self.on=False;self.json=[];self.assets=[]
|
|
def handle_starttag(self,t,a):
|
|
a=dict(a)
|
|
if t=='script' and a.get('type')=='application/json':self.on=True
|
|
if t=='script' and a.get('type')=='module' and a.get('src'):self.assets.append(a['src'])
|
|
if t=='link' and a.get('rel')=='stylesheet' and '/build/'in a.get('href',''):self.assets.append(a['href'])
|
|
def handle_endtag(self,t):
|
|
if t=='script':self.on=False
|
|
def handle_data(self,d):
|
|
if self.on:self.json.append(d)
|
|
get('/up')
|
|
api=get('/api/v2/investment/zones',True)
|
|
rows=api['records']['data']
|
|
assert rows
|
|
park=next((x for x in rows if x['category']=='industrial_park'),None)
|
|
assert park,'Existing public park required for bounded observation'
|
|
if phase!='before':
|
|
before=json.loads((out/'HTTP-BEFORE.json').read_text('utf-8'));park=before['park']
|
|
detail=get('/api/v2/investment/zones/'+park['id'],True)
|
|
assets={};components={}
|
|
for path in ['/zonas','/zonas/'+park['id']]:
|
|
parser=Parser();parser.feed(get(path).decode('utf-8'))
|
|
props=json.loads(''.join(parser.json));assert props['props']['auth']['user']is None
|
|
components[path]=props['component']
|
|
for url in parser.assets:
|
|
p=urllib.parse.urlsplit(url).path;assert p.startswith('/build/')
|
|
if p in assets:continue
|
|
h=hashlib.sha256(get(p)).hexdigest()
|
|
assert h==hashlib.sha256((root/'public'/p.lstrip('/')).read_bytes()).hexdigest()
|
|
assets[p]=h
|
|
if phase!='before':
|
|
# New response keys are expected; previously published factual values must survive.
|
|
old=before['public_detail']['record'];new=detail['record']
|
|
assert all(new[k]==v for k,v in old.items()),'Published factual field changed'
|
|
assert [x['id']for x in rows]==before['public_list_ids']
|
|
assert detail['attachments']==before['public_detail']['attachments']
|
|
assert 'editorial_draft'not in new and detail['relations']==[]and detail['geometries']==[]
|
|
result={'at':datetime.datetime.now(datetime.timezone.utc).isoformat(),'candidate':'parques-operacionais-QA-6aacf653a98e','phase':phase,
|
|
'TLS_certificate_and_hostname_verified':True,'checks':checks,'park':{'id':park['id'],'name':park['name']},
|
|
'public_list_ids':[x['id']for x in rows],'public_detail':detail,'components':components,'entry_assets_verified':assets,
|
|
'previous_published_fields_preserved':True if phase!='before'else None,'business_writes':0,'accepted_QA_tests_repeated':False}
|
|
path=out/f'HTTP-{phase.upper()}.json';assert not path.exists();path.write_text(json.dumps(result,ensure_ascii=False,indent=2)+'\n','utf-8')
|
|
print(json.dumps({'phase':phase,'GETs':len(checks),'entry_assets_verified':len(assets),'public_records':len(rows),
|
|
'public_park':result['park'],'previous_public_fields_preserved':result['previous_published_fields_preserved']}))
|