30 lines
2.1 KiB
Python
30 lines
2.1 KiB
Python
"""Only bootstrap's exact pinned additions may differ from frozen code18 avatar bytes."""
|
|
import hashlib,importlib.util,tempfile,unittest,zipfile
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
ROOT=Path(__file__).resolve().parents[2]
|
|
spec=importlib.util.spec_from_file_location('startup_package',ROOT/'scripts/package-avatar-emotion.py')
|
|
pack=importlib.util.module_from_spec(spec);spec.loader.exec_module(pack)
|
|
|
|
class StartupPackageTests(unittest.TestCase):
|
|
def test_bootstrap_additions_and_no_old_asset_drift(self):
|
|
with tempfile.TemporaryDirectory() as folder:
|
|
old=Path(folder)/'old.apk';new=Path(folder)/'new.apk'
|
|
files={'assets/'+pack.ASSET_ROOT+'manifest.json':(ROOT/'app/src/main/assets'/pack.ASSET_ROOT/'manifest.json').read_bytes(),
|
|
'assets/'+pack.ASSET_ROOT+'fixture.png':b'old-immutable-patch'}
|
|
additions={'assets/avatar/startup-white-01/'+name:(ROOT/'app/src/main/assets/avatar/startup-white-01'/name).read_bytes() for name in ('manifest.json','poster.png')}
|
|
def write(path,rows):
|
|
with zipfile.ZipFile(path,'w') as z:
|
|
for name,data in rows.items():z.writestr(name,data)
|
|
write(old,files)
|
|
with patch.object(pack,'CODE18',old),patch.object(pack,'CODE18_SHA',hashlib.sha256(old.read_bytes()).hexdigest()):
|
|
write(new,{**files,**additions});self.assertEqual(pack.verify_runtime_fix_assets(new,pack.RUNTIME_FIX_PIN,True),2)
|
|
for change in ({'assets/avatar/unapproved.png':b'newportrait'},
|
|
{next(n for n in files if n.endswith('.png')):b'changed-mouth'},
|
|
{'assets/avatar/startup-white-01/poster.png':b'changed-poster'}):
|
|
with self.subTest(change=list(change)):
|
|
write(new,{**files,**additions,**change})
|
|
with self.assertRaises(ValueError):pack.verify_runtime_fix_assets(new,pack.RUNTIME_FIX_PIN,True)
|
|
write(new,{**files,**additions})
|
|
with self.assertRaises(ValueError):pack.verify_runtime_fix_assets(new,pack.RUNTIME_FIX_PIN,False)
|