Files
Investidor-V2/outputs/investmoz-parques-L1-QA-20261016/prove-L1.py
T
nala cef6e201c7
tests / ci (push) Canceled after 0s
versao nrgocios 2
2026-10-16 20:11:05 +02:00

48 lines
6.0 KiB
Python

from http_common import *
from copy import deepcopy
manager=login('manager');installer=login('installer');outsider=login('outsider');anon=session()
top='0ae14c9a-1adb-4ee7-8094-d5d54d4e75f1';admin='/api/v2/investment/admin/zones/';public='/api/v2/investment/zones/';install='/management/investment/zones/operational-install'
fixture=json.loads((out/'FIXTURE-L1.json').read_text('utf-8'))
def minimal(record):return {k:record[k]for k in ['version_no','code','category','name']}
p0=call(anon,public+top);record=call(manager,admin+top)['record'];(out/'PUBLIC-P0.json').write_text(json.dumps(p0,ensure_ascii=False),'utf-8')
check('base130000_present_L1_not_installed',not record['details_available'])
call(manager,admin+top,{**minimal(record),'operational_details':{}},method='PUT',expected=503)
check('intermediate_public_unchanged_and_new_action_visible_failure',call(anon,public+top)==p0)
call(outsider,install,expected=403)
plan=call(installer,install)['plan'];check('preview_absent_L1_consistent',plan['consistent']and not plan['installed'])
payload={'hash':plan['hash'],'idempotency_key':str(uuid.uuid4()),'confirm':True}
call(manager,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_140000_only_zero_business_writes',receipt['changed']and receipt['business_records_changed']==0)
check('same_key_replay',call(installer,install,payload)['receipt']['replayed'])
plan=call(installer,install)['plan'];r=call(installer,install,{'hash':plan['hash'],'idempotency_key':str(uuid.uuid4()),'confirm':True})['receipt'];check('fresh_key_installed_noop',not r['changed'])
record=call(manager,admin+top)['record'];common={'label':'SIMULAÇÃO QA — função documentada','knowledge':'documented','disclosure':True,'source_reference':'Suporte sintético autorizado QA, convenções DOC01 L1','source_date':'2026-10-16','scope':'Exclusivamente ensaio QA, sem validade operacional','private_note':'L1-NOTA-PRIVADA'}
roles=[{**common,'id':str(uuid.uuid4()),'role':role,'organization_id':fixture['organization_id'],'private_contact':'L1-CONTACTO-PESSOAL-PRIVADO','public_contact':'Canal institucional sintético QA'}for role in ['owner','promoter','operator','manager']]
if fixture['support_document_id']:roles[0]['support_document_ids']=[fixture['support_document_id']]
conditions=[{**common,'id':str(uuid.uuid4()),'label':'SIMULAÇÃO QA — tarifa documentada','value':'125.50','currency':'MZN','unit':'m2','period':'mês','valid_from':'2026-10-01','valid_until':'2026-12-31'},
{'id':str(uuid.uuid4()),'label':'SIMULAÇÃO QA — preço desconhecido','knowledge':'unknown','disclosure':True,'source_reference':None,'source_date':None,'scope':None,'value':None,'currency':None,'unit':None}]
details={'schema_version':1,'responsibilities':roles,'conditions':conditions,'risks':[{**common,'id':str(uuid.uuid4()),'label':'SIMULAÇÃO QA — canal de esclarecimento','disclosure':False}],
'review':{'source_reference':'Suporte editorial QA autorizado','source_date':'2026-10-16','scope':'Ensaio delimitado','confidence':'reported','last_reviewed_at':'2026-10-16','next_review_at':None,'private_note':'L1-REVISAO-PRIVADA'}}
data={**minimal(record),'operator_id':fixture['organization_id'],'operational_details':details}
bad=deepcopy(data);bad['operational_details']['conditions'][1]['value']=0
call(manager,admin+top,bad,method='PUT',expected=422)
bad=deepcopy(data);bad['operational_details']['conditions'][0]['unit']=None
call(manager,admin+top,bad,method='PUT',expected=422)
bad=deepcopy(data);bad['operational_details']['responsibilities'].append(deepcopy(roles[0]));bad['operational_details']['responsibilities'][-1]['id']=str(uuid.uuid4())
call(manager,admin+top,bad,method='PUT',expected=422)
bad=deepcopy(data);bad['operational_details']['responsibilities'][0]['organization_id']=str(uuid.uuid4())
call(manager,admin+top,bad,method='PUT',expected=422)
check('unknown_zero_unit_missing_duplicate_role_and_unknown_org_refused',True)
saved=call(manager,admin+top,data,method='PUT');check('same_entity_four_functions_prepared',len(saved['operational_details']['responsibilities'])==4 and len({x['organization_id']for x in saved['operational_details']['responsibilities']})==1)
check('private_prepare_entire_public_response_unchanged',call(anon,public+top)==p0)
call(manager,admin+top,data,method='PUT',expected=409);call(outsider,admin+top,expected=403)
new=login('manager');recovered=call(new,admin+top)['record'];check('private_recovery_new_session',recovered['operational_details']['responsibilities'][0]['private_contact']=='L1-CONTACTO-PESSOAL-PRIVADO')
published=call(new,admin+top+'/publish',{'version_no':recovered['version_no']});p1=call(anon,public+top)
check('only_express_publish_discloses_four_roles',len(p1['record']['operational_details_public']['responsibilities'])==4)
text=json.dumps(p1,ensure_ascii=False);check('public_whitelist_excludes_all_private_markers_ciphertext_support_and_org_ids',all(x not in text for x in ['L1-CONTACTO-PESSOAL-PRIVADO','L1-NOTA-PRIVADA','L1-REVISAO-PRIVADA','private_ciphertext','support_document_ids',fixture['organization_id']]))
c=p1['record']['operational_details_public']['conditions'];check('tariff_context_and_unknown_null_preserved',str(c[0]['value'])=='125.50'and c[0]['currency']=='MZN'and c[0]['unit']=='m2'and c[0]['source_date']=='2026-10-16'and c[1]['value']is None)
post=call(new,admin+top)['record'];check('private_durable_recovery_after_publish_clears_draft',not post['has_private_draft']and post['operational_details']['review']['private_note']=='L1-REVISAO-PRIVADA')
check('public_list_excludes_hidden_raw_details','private_ciphertext'not in json.dumps(call(anon,'/api/v2/investment/zones')))
(out/'PUBLIC-P1.json').write_text(json.dumps(p1,ensure_ascii=False),'utf-8')
(out/'L1-STATE.json').write_text(json.dumps({'zone':top,'public_version':post['public_version_no'],'private':post['operational_details'],'public':p1},ensure_ascii=False),'utf-8')
print(json.dumps({'checks':len(proof['checks']),'events':len(proof['events']),'QA_only':True}))