first commit
This commit is contained in:
commit
58cfd95600
35 files changed
+5357
No files matched your search
@@ -0,0 +1,54 @@
|
||||
"""Browser test: pasted magnet cleanup, live diagnostics and .torrent upload."""
|
||||
from pathlib import Path
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
root = Path(__file__).resolve().parents[1] / 'app' / 'static'
|
||||
html = (root / 'index.html').read_text().replace('<link rel="stylesheet" href="/static/style.css">', '').replace('<script src="/static/app.js" defer></script>', '')
|
||||
css = (root / 'style.css').read_text()
|
||||
js = (root / 'app.js').read_text()
|
||||
|
||||
with sync_playwright() as playwright:
|
||||
browser = playwright.chromium.launch(executable_path='/usr/bin/chromium', args=['--no-sandbox', '--disable-dev-shm-usage'])
|
||||
page = browser.new_page(viewport={'width': 1280, 'height': 900})
|
||||
errors = []
|
||||
page.on('pageerror', lambda err: errors.append(str(err)))
|
||||
page.set_content(html)
|
||||
page.add_style_tag(content=css)
|
||||
page.evaluate('''() => {
|
||||
window.__seenMagnet = null;
|
||||
window.fetch = async (url, options = {}) => {
|
||||
const u = String(url), m = options.method || 'GET';
|
||||
let reply = {};
|
||||
if (u === '/api/system') reply = {free:1000000000,total:2000000000};
|
||||
else if (u === '/api/jobs' && m === 'GET') reply = [];
|
||||
else if (u === '/api/archive/session') reply = {authenticated:false};
|
||||
else if (u === '/api/magnet/inspect' && m === 'POST') {
|
||||
window.__seenMagnet = JSON.parse(options.body).magnet;
|
||||
reply = {status:'loading',preview_id:'a'.repeat(32)};
|
||||
}
|
||||
else if (u === '/api/magnet/upload') reply = {status:'ready',preview_id:'b'.repeat(32)};
|
||||
else if (u.includes('/magnet/inspect/' + 'a'.repeat(32)) && m === 'GET')
|
||||
reply = {status:'loading',elapsed:35,connections:0,aria_status:'active'};
|
||||
else if (u.includes('/magnet/inspect/' + 'b'.repeat(32)) && m === 'GET')
|
||||
reply = {status:'ready',name:'Demo',suggested:[],files:[{index:1,name:'Demo/Game.iso',size:1024,padding:false}]};
|
||||
else if (u.startsWith('/api/magnet/inspect/') && m === 'POST') reply = {ok:true};
|
||||
return new Response(JSON.stringify(reply), {status:200,headers:{'Content-Type':'application/json'}});
|
||||
};
|
||||
}''')
|
||||
page.add_script_tag(content=js)
|
||||
raw = "'**magnet**:?xt=urn:btih:c98fbaa2a36ee48e3d9423be02cdbefd9281bc7d&so=15\\\n&tr=udp%3A%2F%2Fexample.com%2Fannounce'"
|
||||
page.locator('#urls').fill(raw)
|
||||
page.locator('#linksForm button[type=submit]').click()
|
||||
page.locator('#magnetDialog').wait_for(state='visible')
|
||||
page.locator('#magnetStatus').get_by_text('Brak połączeń', exact=False).wait_for()
|
||||
parsed = page.evaluate('window.__seenMagnet')
|
||||
assert parsed.startswith('magnet:?xt=urn:btih:c98fbaa2a36ee48e3d9423be02cdbefd9281bc7d&so=15&tr='), parsed
|
||||
assert '\n' not in parsed and '&' not in parsed
|
||||
page.screenshot(path='/mnt/data/x360-magnet-diagnostics-preview.png', full_page=True)
|
||||
page.locator('#torrentFileDialog').set_input_files({'name':'demo.torrent','mimeType':'application/x-bittorrent','buffer':b'd4:infod4:name4:Demoe e'})
|
||||
page.locator('#magnetResults').wait_for(state='visible')
|
||||
assert page.locator('#magnetFiles input[type=checkbox]').count() == 1
|
||||
page.screenshot(path='/mnt/data/x360-magnet-upload-preview.png', full_page=True)
|
||||
assert not errors, errors
|
||||
browser.close()
|
||||
print('UI magnet fallback PASS')
|
||||
Reference in new issue
Block a user