Files
LihonT/tests/test_streak_patch.py
cheb0chik 5df4cddf7d LihonT 3 Luna pre-alpha: the streak pet becomes an animal
A pair of people can have a kitten, a puppy or a lion cub in place of TikTok's streak creature: it grows with the days of the
streak (cub, teen, adult, elder), goes grey while the streak is about to burn out, can be dragged in the chat and is also shown
on the big streak screen. An animal is given by a link (lihont.space/pet) that the friend accepts. The drawings are made by
scripts/make_pet_designs.py and served as strips of frames. Also here: the promo video scripts (make_pet_video.py on top of
make_store_video.py), a retry pause for strips that failed to load, stricter checks in the answer to a gift.

Work in progress: the gift service is not switched on for everyone yet and there is no public build with the animals.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-10 15:14:48 +03:00

68 lines
2.9 KiB
Python

import unittest
import zipfile
from pathlib import Path
from lihont import streak_patch, widget_patch
from lihont.axml import Axml, RES_XML_END_ELEMENT
ROOT = Path(__file__).resolve().parents[1]
APKS = sorted((ROOT / "OriginalAPKtiktok").glob("*.apk")) if (ROOT / "OriginalAPKtiktok").is_dir() else []
class FakeApk:
"""Just enough of lihont.apkzip.Apk: reads from the original apk, remembers what is replaced."""
def __init__(self, path):
self.zip = zipfile.ZipFile(path)
self.replaced = {}
def read(self, name):
return self.replaced.get(name) or self.zip.read(name)
def replace(self, name, data):
self.replaced[name] = data
def add(self, name, data, method=None):
self.replaced[name] = data
@unittest.skipUnless(APKS, "the original TikTok apk is not in OriginalAPKtiktok/")
class StreakPatchTest(unittest.TestCase):
def setUp(self):
self.apk = FakeApk(APKS[0])
self.xml = Axml.parse(self.apk.read("AndroidManifest.xml"))
def test_the_alarm_receiver_is_declared_and_private(self):
report = streak_patch.apply(self.apk, self.xml)
rebuilt = Axml.parse(self.apk.replaced["AndroidManifest.xml"])
nodes = [n for n in rebuilt.elements("receiver") if rebuilt.attr_string(n, "name") == streak_patch.RECEIVER]
self.assertEqual(1, len(nodes))
self.assertEqual(0, rebuilt.attr(nodes[0], "exported").data, "no other app can reach it")
self.assertEqual({"receiver": streak_patch.RECEIVER, "exported": False}, report)
ids = [rebuilt.resource_map[a.name] for a in nodes[0].attributes]
self.assertEqual(sorted(ids), ids, "the attributes stay in ascending id order")
def test_it_has_no_intent_filter(self):
streak_patch.apply(self.apk, self.xml)
rebuilt = Axml.parse(self.apk.replaced["AndroidManifest.xml"])
node = next(n for n in rebuilt.elements("receiver") if rebuilt.attr_string(n, "name") == streak_patch.RECEIVER)
following = rebuilt.nodes[rebuilt.nodes.index(node) + 1]
self.assertEqual(RES_XML_END_ELEMENT, following.kind, "the receiver closes right away: no intent filter")
def test_a_second_pass_is_refused(self):
streak_patch.apply(self.apk, self.xml)
with self.assertRaises(streak_patch.StreakError):
streak_patch.apply(self.apk, self.xml)
def test_it_sits_next_to_the_widget_changes(self):
widget_patch.apply(self.apk, self.xml, 0x7F120364)
streak_patch.apply(self.apk, self.xml)
rebuilt = Axml.parse(self.apk.replaced["AndroidManifest.xml"])
names = {rebuilt.attr_string(n, "name") for n in rebuilt.elements("receiver")}
self.assertIn(streak_patch.RECEIVER, names)
self.assertIn("lihont.two.widget.StreakWidget1", names)
if __name__ == "__main__":
unittest.main()