38 lines
4.7 KiB
Python
38 lines
4.7 KiB
Python
from http_common import *
|
|
manager=login('manager');installer=login('installer');outsider=login('outsider');auditor=login('auditor');anon=session()
|
|
top='0ae14c9a-1adb-4ee7-8094-d5d54d4e75f1';bel='1b57649a-f522-4cd5-8e97-32e82b6e1b37'
|
|
admin='/api/v2/investment/admin/zones/';public='/api/v2/investment/zones/'
|
|
install='/management/investment/zones/profile-install'
|
|
p0=call(anon,public+top);(out/'PUBLIC-P0.json').write_text(json.dumps(p0,ensure_ascii=False,indent=2),'utf-8')
|
|
def fields(record):
|
|
keys=['version_no','code','category','name','name_en','description','description_en','province','district','operator_id','legal_source_id','physical_category','legal_regime','operational_status','development_status','availability_status','area_components','source_evidence','area_value','area_unit','aliases','activities','resources','data_as_of','sources_consulted_at','parent_zone_id','historical_territory']
|
|
return {k:(v[:10] if k in ['data_as_of','sources_consulted_at'] and v else v) for k,v in record.items() if k in keys}
|
|
record=call(manager,admin+top)['record'];assert record['version_no']==3
|
|
data=fields(record);data['description']='SIMULAÇÃO QA — alteração privada, não é informação operacional real.'
|
|
call(manager,admin+top,data,method='PUT',expected=503);check('intermediate_no_column_public_served_prepare_visibly_refused',call(anon,public+top)==p0)
|
|
call(outsider,install,expected=403)
|
|
plan=call(installer,install)['plan'];check('preview_no_schema_consistent',not plan['installed'] and plan['consistent'])
|
|
payload={'hash':plan['hash'],'idempotency_key':str(uuid.uuid4()),'confirm':True}
|
|
call(manager,install,payload,expected=403);call(auditor,install,payload,expected=403)
|
|
call(installer,install,{**payload,'actor_id':2},expected=422)
|
|
call(installer,install,{**payload,'hash':'0'*64},expected=409)
|
|
receipt=call(installer,install,payload)['receipt'];check('authenticated_nominal_install_zero_business_records',receipt['changed'] and receipt['business_records_changed']==0)
|
|
check('same_installation_key_replays',call(installer,install,payload)['receipt']['replayed'])
|
|
plan=call(installer,install)['plan'];receipt=call(installer,install,{'hash':plan['hash'],'idempotency_key':str(uuid.uuid4()),'confirm':True})['receipt'];check('new_key_installed_no_op',not receipt['changed'])
|
|
data['resources']=[{'name':'SIMULAÇÃO QA — energia de ensaio','status':'unconfirmed','source_reference':'Suporte sintético QA autorizado; sem validade operacional','kind':'infrastructure','scope':'inside','source_date':'2026-10-16','capacity_type':'Potência de ensaio','capacity_value':12.5,'capacity_unit':'kW','private_note':'QA-NOTA-PRIVADA-NAO-DIVULGAR'}]
|
|
data['activities']=[{'name':'SIMULAÇÃO QA — foco de ensaio','status':'potential','source_reference':'Modelo sintético autorizado em QA','focus':'potential','source_date':'2026-10-16'}]
|
|
saved=call(manager,admin+top,data,method='PUT');check('private_working_v4_public_v3',saved['version_no']==4 and saved['public_version_no']==3 and saved['has_private_draft'])
|
|
check('public_all_props_unchanged_during_private_preparation',call(anon,public+top)==p0)
|
|
call(manager,admin+top,data,method='PUT',expected=409);check('stale_save_visible_409',True)
|
|
new=login('manager');recovered=call(new,admin+top)['record'];check('new_session_recovers_private_details',recovered['resources'][0]['capacity_value']==12.5 and recovered['resources'][0]['private_note']=='QA-NOTA-PRIVADA-NAO-DIVULGAR')
|
|
call(outsider,admin+top,expected=403);check('private_preparation_unauthorized_denied',True)
|
|
published=call(new,admin+top+'/publish',{'version_no':4});check('explicit_publication_allocates_v5',published['version_no']==5 and not published['has_private_draft'])
|
|
p1=call(anon,public+top);check('public_promotes_only_explicitly',p1['record']['description']==data['description'] and p1['record']['version_no']==5)
|
|
check('public_private_metadata_excluded','QA-NOTA-PRIVADA-NAO-DIVULGAR' not in json.dumps(p1) and 'editorial_draft' not in json.dumps(p1))
|
|
(out/'PUBLIC-P1.json').write_text(json.dumps(p1,ensure_ascii=False,indent=2),'utf-8')
|
|
# Existing unpublished park: only new optional fields are prepared, no publication.
|
|
b=fields(call(manager,admin+bel)['record']);b['resources']=[{'name':'SIMULAÇÃO QA — acesso regional','status':'unconfirmed','source_reference':'Ensaios QA, não constitui acesso confirmado','kind':'access','scope':'regional','capacity_value':None,'capacity_unit':None,'source_date':None}]
|
|
bs=call(manager,admin+bel,b,method='PUT');check('existing_draft_UUID_preserved_optional_unknowns',bs['id']==bel and bs['version_no']==2 and bs['resources'][0]['capacity_value'] is None and bs['publication_status']=='draft')
|
|
call(anon,public+bel,expected=404);check('private_draft_not_public',True)
|
|
print(json.dumps({'checks':len(proof['checks']),'events':len(proof['events']),'phase':'new core only'}))
|