chore: add exporter scripts for static clones
This commit is contained in:
1 parent
2771be2d67
commit
f4f0857870
7 files changed
+1114
No files matched your search
@@ -0,0 +1,41 @@
|
||||
"""Compare /api/hotel + /api/product of a static export (Apache on 127.0.0.1:8099) with live local TYPO3.
|
||||
|
||||
Usage: compare_api.py <export dir>. Case list: every hotel/product code, sampled pairs, random
|
||||
unlinked pairs, empty/missing params, missing/wrong/query-string key, direct snapshot access.
|
||||
"""
|
||||
import sys, os, random, importlib.util, urllib.request, urllib.error, concurrent.futures
|
||||
spec = importlib.util.spec_from_file_location('export', '/var/www/html/.ddev/static-export/export.py'); m = importlib.util.module_from_spec(spec); spec.loader.exec_module(m)
|
||||
sites = m.load_sites(); exp = m.Exporter('ep-reisen', sites['ep-reisen'], sites, '/nonexistent', follow=False, workers=1); key = m.cms_api_key()
|
||||
class N(urllib.request.HTTPRedirectHandler):
|
||||
def redirect_request(self, *a): return None
|
||||
op = urllib.request.build_opener(N)
|
||||
def call(url, headers):
|
||||
try:
|
||||
with op.open(urllib.request.Request(url, headers=headers), timeout=60) as r: return r.status, r.read().decode(), r.headers.get('Content-Type')
|
||||
except urllib.error.HTTPError as e: return e.code, e.read().decode(), e.headers.get('Content-Type')
|
||||
typo3 = lambda q, h: call('http://127.0.0.1/' + q, dict(h, **{'Host': 'ep-reisen.ddev.site', 'X-Forwarded-Proto': 'https'}))
|
||||
static = lambda q, h: call('http://127.0.0.1:8099/' + q, dict(h, **{'Host': 'www.ep-reisen.de'}))
|
||||
root = sys.argv[1]; K = {'X-Api-Key': key}
|
||||
hotels = sorted(f[:-5] for f in os.listdir(root + '/_api/hotel')); products = sorted(f[:-5] for f in os.listdir(root + '/_api/product') if f.endswith('.json'))
|
||||
pairs = sorted((p, f[:-5]) for p in products if os.path.isdir(root + '/_api/product/' + p) for f in os.listdir(root + '/_api/product/' + p) if not f.startswith('_'))
|
||||
random.seed(1)
|
||||
cases = [('api/hotel?hotel=' + c, K) for c in hotels] + [('api/product?product=' + c, K) for c in products]
|
||||
cases += [('api/product?product=%s&hotel=%s' % pc, K) for pc in random.sample(pairs, 150)]
|
||||
cases += [('api/product?hotel=%s&product=%s' % (h, p), K) for p, h in random.sample(pairs, 10)]
|
||||
cases += [('api/product?product=%s&hotel=%s' % (p, random.choice(hotels)), K) for p in random.sample(products, 60)]
|
||||
cases += [(q, K) for q in ['api/hotel?hotel=_empty', 'api/product?product=_empty', 'api/hotel?hotel=%40empty', 'api/product?product=3VIIN&hotel=@empty', 'api/product?product=3VIIN&hotel=PMVSW%26A', 'api/hotel?hotel=a%20b', 'api/product?product=%40empty&hotel=', 'api/hotel', 'api/product', 'api/hotel?hotel=', 'api/product?product=', 'api/product?product=&hotel=X',
|
||||
'api/hotel?hotel=NOPE', 'api/product?product=NOPE', 'api/product?product=NOPE&hotel=' + hotels[0],
|
||||
'api/product?product=%s&hotel=' % products[0], 'api/product?product=%s&hotel=NOPE' % products[0]]]
|
||||
cases += [('api/hotel?hotel=' + hotels[0], {}), ('api/hotel?hotel=' + hotels[0], {'X-Api-Key': 'wrong'}),
|
||||
('api/hotel?hotel=%s&key=%s' % (hotels[0], key), {}), ('api/product?key=%s&product=%s' % (key, products[0]), {}),
|
||||
('api/product?product=%s&key=wrong' % products[0], {})]
|
||||
def compare(c):
|
||||
q, h = c; a, b = typo3(q, h), static(q, h)
|
||||
return q, (a[0], exp.to_prod(a[1]), a[2]), b
|
||||
bad = []
|
||||
with concurrent.futures.ThreadPoolExecutor(8) as ex:
|
||||
for q, a, b in ex.map(compare, cases):
|
||||
if a != b: bad.append((q, a, b))
|
||||
print('cases: %d, identical: %d, different: %d' % (len(cases), len(cases) - len(bad), len(bad)))
|
||||
for q, a, b in bad[:6]: print(' DIFF', q, '| typo3', a[0], a[2], '| static', b[0], b[2], repr(b[1][:90]))
|
||||
for q in ['_api/hotel/%s.json' % hotels[0], '_api/pair.shtml', '_api/product-part/%s.part' % products[0]]: print(' direct', q, static(q, {})[0])
|
||||
Reference in new issue
Block a user