20 lines
2.4 KiB
Python
20 lines
2.4 KiB
Python
from pathlib import Path
|
|
from datetime import datetime,timezone
|
|
from urllib.parse import urlencode
|
|
import importlib.util,json,csv,io,hashlib,sys
|
|
OUT=Path(__file__).resolve().parent;spec=importlib.util.spec_from_file_location('lot',OUT/'consumer-lot-lib.py');lib=importlib.util.module_from_spec(spec);spec.loader.exec_module(lib)
|
|
c=lib.Client();proof={'at':datetime.now(timezone.utc).isoformat(),'target':lib.TARGET,'active_writes':0,'browser_observed':False,'criteria':{}};stage='isolation'
|
|
def raw(path):
|
|
s,h,b=c.request('GET',path,accept='text/csv');lib.events.append({'method':'GET','route':path.split('?')[0],'status':s});assert s==200 and'text/csv'in h.get('Content-Type','');assert b.startswith(b'\xef\xbb\xbf');return h,b,list(csv.reader(io.StringIO(b.decode('utf-8-sig')),delimiter=';'))
|
|
try:
|
|
c.call('GET','/api/v1/investment/search');stage='opportunity_export';h,b,rows=raw('/api/v1/investment/export');assert len(rows[0])==8 and all(len(r)==8 for r in rows);assert h.get('X-Export-Limit')=='1000';proof['criteria']['opportunity_csv']={'columns':8,'data_rows':len(rows)-1,'UTF8_BOM':True,'limit':1000,'sha256':hashlib.sha256(b).hexdigest()}
|
|
if len(rows)>1:
|
|
ref=rows[1][0];_,filtered,rs=raw('/api/v1/investment/export?'+urlencode({'q':ref}));assert any(r[0]==ref for r in rs[1:]);_,again,_=raw('/api/v1/investment/export?'+urlencode({'q':ref}));assert filtered==again;proof['criteria']['positive_filter_and_replay']=True
|
|
_,b,private=raw('/api/v1/investment/export?opportunity_id=56');assert len(private)==1;proof['criteria']['internal_opportunity_56_excluded']=True
|
|
stage='zone_export';_,b,z=raw('/api/v2/investment/zones/export.csv');assert len(z[0])==11 and all(len(r)==11 for r in z);proof['criteria']['zone_csv']={'columns':11,'data_rows':len(z)-1,'UTF8_BOM':True,'sha256':hashlib.sha256(b).hexdigest()}
|
|
if len(z)>1:
|
|
title=z[1][1];_,b,filt=raw('/api/v2/investment/zones/export.csv?'+urlencode({'q':title}));assert any(r[1]==title for r in filt[1:]);_,again,_=raw('/api/v2/investment/zones/export.csv?'+urlencode({'q':title}));assert b==again;proof['criteria']['zone_positive_filter_replay']=True
|
|
proof['result']='passed'
|
|
except Exception as e:proof.update(result='stopped',stage=stage,error_type=type(e).__name__)
|
|
proof['routes']=lib.events;(OUT/'next-exports-HTTP.json').write_text(json.dumps(proof,indent=2),encoding='utf-8');print(json.dumps(proof));sys.exit(0 if proof['result']=='passed'else 1)
|