"""Read-only page/asset checks for a running packaged app; never writes order data.""" import argparse import getpass import http.cookiejar import re import urllib.parse import urllib.request def main(): parser=argparse.ArgumentParser(description=__doc__) parser.add_argument('--url',default='http://127.0.0.1:8080') parser.add_argument('--username',required=True,help='Use an initialized admin account') args=parser.parse_args() base=args.url.rstrip('/') opener=urllib.request.build_opener(urllib.request.HTTPCookieProcessor(http.cookiejar.CookieJar())) def get(path): with opener.open(base+path,timeout=30) as response: return response.geturl(),response.read() _,body=get('/login') match=re.search(r'name="csrf_token" value="([^"]+)"',body.decode('utf-8')) if not match: raise SystemExit('Complete first-time setup before running this check.') fields={'username':args.username,'password':getpass.getpass('Password: '),'csrf_token':match[1]} with opener.open(urllib.request.Request(base+'/login',data=urllib.parse.urlencode(fields).encode()),timeout=30) as response: if response.geturl().rstrip('/') != base: raise SystemExit('Login failed or password change is required.') response.read() for path,marker in [('/orders/new',b'request_key'),('/users',b'username'),('/materials',b'matImpModal'), ('/suppliers',b'supImpModal'),('/static/money.js',b'lineCents'),('/static/style.css',b'modal-mask')]: url,body=get(path) if url != base+path or marker not in body: raise SystemExit('Failed page/asset check: '+path) print('PASS',path) for path in ['/materials/import_template.xlsx','/suppliers/import_template.xlsx','/import_template.xlsx']: url,body=get(path) if url != base+path or not body.startswith(b'PK'): raise SystemExit('Failed workbook check: '+path) print('PASS',path) print('Packaged page/asset checks passed; order data was not modified.') if __name__=='__main__': main()