Archived
87 lines
4.0 KiB
Python
87 lines
4.0 KiB
Python
"""Regression tests for the v0.40.4 native candidate, no privileged side effects."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import re
|
|
import runpy
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
LANGS = ('en', 'ru', 'de', 'fr', 'it', 'es', 'pl')
|
|
|
|
|
|
class CandidateTests(unittest.TestCase):
|
|
def test_versions_and_locale_fallback_contract(self):
|
|
self.assertEqual((ROOT / 'VERSION').read_text().strip(), '1.0.1')
|
|
en = json.loads((ROOT/'app/locales/en.json').read_text())
|
|
self.assertGreaterEqual(len(en), 1098)
|
|
for lang in LANGS:
|
|
content=(ROOT/'app/locales'/f'{lang}.json').read_bytes()
|
|
self.assertEqual(content,(ROOT/'app/static'/f'{lang}.json').read_bytes())
|
|
self.assertEqual(content,(ROOT/'app/static/locales'/f'{lang}.json').read_bytes())
|
|
data=json.loads(content)
|
|
self.assertEqual(set(data),set(en),lang)
|
|
# Every supported language resolves every possible UI key through English.
|
|
merged={**en,**data}
|
|
self.assertEqual(set(merged),set(en))
|
|
for key,value in data.items():
|
|
self.assertEqual(set(re.findall(r'\{\w+\}',value)),
|
|
set(re.findall(r'\{\w+\}',en[key])),(lang,key))
|
|
|
|
def test_delete_returns_exact_client_name_for_audit(self):
|
|
helper=runpy.run_path(str(ROOT/'scripts/wgtools-helper'))
|
|
fun=helper['delete_client']
|
|
g=fun.__globals__
|
|
g.update({
|
|
'read_config_text':lambda iface:'[Interface]\n',
|
|
'parse_config':lambda text,iface:{'peers':[{'public_key':'PUBLICKEY','name':'Work laptop','remote_networks':[]}], 'detected':{}},
|
|
'replace_peer_block':lambda text,key,value:text,
|
|
'update_route_hooks':lambda text,*args:text,
|
|
'load_client_meta':lambda key:None,
|
|
'delete_client_meta':lambda key:None,
|
|
'sync_managed_client_policies':lambda text,iface:text,
|
|
'write_config_transaction':lambda *args:'/tmp/test-backup',
|
|
})
|
|
response=fun('wg0',{'public_key':'PUBLICKEY'})
|
|
self.assertEqual(response['name'],'Work laptop')
|
|
self.assertTrue(response['ok'])
|
|
|
|
def test_short_cache_and_no_runtime_tests(self):
|
|
helper=runpy.run_path(str(ROOT/'scripts/wgtools-helper'))
|
|
self.assertEqual(helper['UPDATE_NOTICE_MAX_AGE'],15*60)
|
|
installer=(ROOT/'scripts/install.sh').read_text()
|
|
self.assertIn('"$APP_DIR/tests"',installer)
|
|
self.assertIn('Preserving existing /etc/wgtools/wgtools.env',installer)
|
|
js=(ROOT/'app/static/js/app.js').read_text()
|
|
self.assertIn('topbar-theme-toggle',js)
|
|
self.assertIn('renderPeerTable(body,visiblePeers.map',js)
|
|
self.assertIn('topbar-update-notice',js)
|
|
|
|
def test_online_breathes_without_reset_and_icon_is_svg(self):
|
|
css=(ROOT/'app/static/css/app.css').read_text()
|
|
js=(ROOT/'app/static/js/app.js').read_text()
|
|
template=(ROOT/'app/templates/base.html').read_text()
|
|
self.assertIn('.status-dot.peer-status-dot.offline{\n animation:none!important;',css)
|
|
self.assertNotIn('animation:wgtools-peer-breathe',css)
|
|
self.assertIn('animation:wgtools-peer-online-breathe 2.4s ease-in-out infinite',css)
|
|
self.assertIn('inset:-2px;',css)
|
|
self.assertIn('50%{transform:scale(1.10);opacity:.88}',css)
|
|
self.assertNotIn('0 0 9px rgba(105,193,125,.42)',css)
|
|
self.assertIn('prefers-reduced-motion:reduce',css)
|
|
self.assertIn('renderPeerTable(body,rowsHtml,5)',js)
|
|
self.assertIn('theme-icon-sun',template)
|
|
self.assertIn('theme-icon-moon',template)
|
|
self.assertNotIn('id="topbar-theme-icon"',template)
|
|
self.assertIn('old.innerHTML!==next.innerHTML',js)
|
|
self.assertIn('a.className===b.className&&a.textContent===b.textContent',js)
|
|
self.assertNotIn('pulse-phase',js)
|
|
self.assertNotIn('wgtools-peer-online-ripple',css)
|
|
self.assertIn('animation:none!important',css)
|
|
|
|
|
|
if __name__=='__main__':
|
|
unittest.main()
|