43 lines
2.6 KiB
Python
43 lines
2.6 KiB
Python
from pathlib import Path
|
|
from urllib.parse import urlencode
|
|
from datetime import datetime,timezone
|
|
import importlib.util,json
|
|
OUT=Path(__file__).resolve().parent
|
|
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)
|
|
state=json.loads((OUT/'option-B-land-progress.json').read_text(encoding='utf-8'))
|
|
correspondence=json.loads((OUT/'QA-credential-correspondence.json').read_text(encoding='utf-8'))
|
|
candidate=next(c for c in correspondence['candidates']if c['source_file']=='i0-qa-actor-private.json')
|
|
assert candidate['password_matches']and candidate['MFA_secret_matches']and candidate['can_manage_portal']
|
|
lib.actors['manager']=json.loads((lib.PRIVATE/'i0-qa-actor-private.json').read_text(encoding='utf-8'))
|
|
lib.actors['manager']['id']=candidate['user_id']
|
|
proof={'at':datetime.now(timezone.utc).isoformat(),'scope':'B','target':lib.TARGET,'active_writes':0,
|
|
'browser_observed':False,'criteria':{},'case_id':state['id']}
|
|
manager=lib.Client();owner=lib.Client();step='login';exit_code=1
|
|
try:
|
|
manager.login('manager')
|
|
route='/management/interests?'+urlencode({'country':'PT','origin':'BR','q':state['ticket_reference']})
|
|
before=manager.call('GET',route,json_response=False)
|
|
assert before['requests']['total']==1
|
|
row=before['requests']['data'][0]
|
|
assert row['reference']==state['ticket_reference']and row['country']=='Portugal'and row['declaredOrigin']['code']=='BR'
|
|
owner.login('promoter')
|
|
owner.call('POST','/investidor/terra-duat/'+state['id']+'/solicitar-apoio',state['submission'],expected=202)
|
|
after=manager.call('GET',route,json_response=False)
|
|
assert after['requests']['total']==1 and after['requests']['data'][0]['id']==row['id']
|
|
assert after['originStatistics']==before['originStatistics']
|
|
proof['criteria']={'ISO_country_filter_recovers_preserved_legacy_value':True,'origin_filter_distinct':'BR',
|
|
'matched_receipt_count':1,'same_receipt_after_repeat':True,'origin_statistics_unchanged_after_repeat':True,
|
|
'statistic_scope':'separate origin-selected collections; country/q filters apply to the request list'}
|
|
proof['result']='passed';exit_code=0
|
|
except Exception as error:
|
|
proof.update(result='stopped',step=step,error_type=type(error).__name__)
|
|
finally:
|
|
for client in [manager,owner]:
|
|
try:client.logout()
|
|
except Exception:pass
|
|
proof['routes']=lib.events
|
|
(OUT/'option-B-land-statistics-HTTP.json').write_text(json.dumps(proof,ensure_ascii=False,indent=2)+'\n',encoding='utf-8')
|
|
print(json.dumps({key:value for key,value in proof.items()if key!='routes'}))
|
|
raise SystemExit(exit_code)
|