61 lines
4.6 KiB
Python
61 lines
4.6 KiB
Python
from pathlib import Path
|
|
from datetime import datetime,timezone
|
|
import importlib.util,json,uuid,sys
|
|
OUT=Path(__file__).resolve().parent;dest=OUT/'option-B5-coeditor-revoke-HTTP.json';progress=OUT/'option-B5-coeditor-revoke-progress.json'
|
|
if dest.exists():
|
|
prior=json.loads(dest.read_text(encoding='utf-8'))
|
|
assert prior['result']=='stopped' and prior['step']=='normal_login' and not progress.exists()
|
|
archived=OUT/'option-B5-coeditor-revoke-HTTP.pre-mutation-harness.json'
|
|
assert not archived.exists();archived.write_bytes(dest.read_bytes())
|
|
spec=importlib.util.spec_from_file_location('transport',OUT/'consumer-lot-lib.py');lib=importlib.util.module_from_spec(spec);spec.loader.exec_module(lib)
|
|
pre=json.loads((OUT/'option-B5-revocation-preflight.json').read_text(encoding='utf-8'))
|
|
assert pre['superuser_id']==27 and pre['superuser_is_existing'] and pre['user_id']==22
|
|
assert any(c['id']==15 and c['state']=='draft' for c in pre['editable_existing_cases'])
|
|
proof={'at':datetime.now(timezone.utc).isoformat(),'target':lib.TARGET,'scope':'B / L1.1 existing QA22 investment-project coedition','active_writes':0,'browser_observed':False,'criteria':{}}
|
|
state={};clients=[];step='normal_login';code=1
|
|
def checkpoint():progress.write_text(json.dumps(state,ensure_ascii=False,indent=2)+'\n',encoding='utf-8')
|
|
try:
|
|
colleague=lib.Client().login('colleague');clients.append(colleague)
|
|
original=colleague.call('GET','/minhas-oportunidades/15/edit',json_response=False)
|
|
assert original['workflowState']=='draft' and original['canEditDraft'];saved_values=original['values']
|
|
admin=lib.Client().login('super_first');clients.append(admin)
|
|
step='revoke_existing_coeditor_assignment'
|
|
reason='SIMULAÇÃO QA B: revogar apenas coedição de projeto, preservar papéis independentes e histórico'
|
|
path='/perfis/atribuicoes/'+pre['grant_id']+'/revogar'
|
|
admin.call('POST',path,{'reason':reason});state['revoked_grant_id']=pre['grant_id'];checkpoint()
|
|
step='old_session_denied';colleague.call('GET','/dashboard',expected=401)
|
|
proof['criteria']['old_session_invalidated']=401
|
|
step='fresh_session_without_coedition'
|
|
fresh=lib.Client().login('colleague');clients.append(fresh)
|
|
fresh.call('GET','/minhas-oportunidades/15/edit',expected=403)
|
|
fresh.call('POST','/minhas-oportunidades/15/resources/locations',{},expected=403)
|
|
readable=fresh.call('GET','/minhas-oportunidades/30/view',json_response=False)
|
|
assert readable['profileActions']==[]
|
|
proof['criteria']['coedition_revoked']={'fresh_session_edit':403,'fresh_session_write':403,'other_validator_role_read_retained':200,'operational_actions':[]}
|
|
admin.call('POST',path,{'reason':reason})
|
|
state['revocation_repeated']=True;checkpoint()
|
|
step='prepare_scoped_fixture_again_by_existing_request'
|
|
creation_key=str(uuid.uuid4())
|
|
request={'creation_key':creation_key,'representation_type':pre['representation_type'],'organization_id':pre['organization_id'],
|
|
'opportunity_types':pre['requested_types'],'document_ids':pre['support_document_ids'],
|
|
'reason':'SIMULAÇÃO QA B: reabilitar fixture de coedição no mesmo âmbito comprovado, mantendo a revogação anterior auditada'}
|
|
created=fresh.call('POST','/perfil/promotor',request,expected=201);state['new_request_id']=created['id'];checkpoint()
|
|
repeated=fresh.call('POST','/perfil/promotor',request,expected=201);assert repeated['id']==created['id']
|
|
admin.call('POST','/perfis/pedidos/'+created['id']+'/decisao',{
|
|
'version':1,'decision':'approved','reason':'SIMULAÇÃO QA B: revisão independente da representação e comprovativo próprios já existentes; apenas projeto de investimento',
|
|
'verified_identity':True,'verified_representation':True,'verified_documents':True,'approved_types':pre['requested_types']})
|
|
state['new_request_approved']=True;checkpoint()
|
|
recovered=fresh.call('GET','/minhas-oportunidades/15/edit',json_response=False)
|
|
assert recovered['canEditDraft'] and recovered['values']==saved_values
|
|
proof['criteria']['fixture_rehabilitated_through_existing_flow']={'request_replay_same_id':True,'reviewer_id':27,'subject_id':22,'types':pre['requested_types'],
|
|
'organization_unchanged':True,'existing_support_document_reused':True,'edit_recovers_unchanged_draft':True,'revoked_assignment_not_reactivated':True}
|
|
proof['result']='passed';code=0
|
|
except Exception as e:proof.update(result='stopped',step=step,error_type=type(e).__name__)
|
|
finally:
|
|
for c in clients:
|
|
try:c.logout()
|
|
except Exception:pass
|
|
proof['requests']=lib.events;dest.write_text(json.dumps(proof,ensure_ascii=False,indent=2)+'\n',encoding='utf-8')
|
|
print(json.dumps({k:v for k,v in proof.items()if k!='requests'},ensure_ascii=False))
|
|
raise SystemExit(code)
|