-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathtest_apps_manifest.py
More file actions
132 lines (118 loc) · 4.96 KB
/
test_apps_manifest.py
File metadata and controls
132 lines (118 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import json
import os
import unittest
from pathlib import Path
try:
APPS_BASE_PATH = Path(__file__).parent.parent / "internal_filesystem" / "apps"
except NameError:
APPS_BASE_PATH = Path("apps")
def iter_app_path():
try:
entries = os.listdir(str(APPS_BASE_PATH))
except OSError:
entries = []
for app_name in entries:
app = APPS_BASE_PATH / app_name
if app.is_dir():
yield app
class TestAppsManifest(unittest.TestCase):
def test_all_apps_manifest(self):
for app_path in iter_app_path():
with self.subTest(app=app_path.name):
manifest = app_path / "META-INF" / "MANIFEST.JSON"
self.assertTrue(manifest.is_file(), f"Missing {manifest=}")
try:
with manifest.open("r", encoding="utf-8") as f:
data = json.load(f)
except Exception as e:
self.fail(f"Invalid JSON in {manifest=}: {e}")
fullname = app_path.name
self.assertEqual(data.get("fullname"), fullname)
# Check name:
name = data.get("name")
self.assertTrue(name, f"Missing name in {manifest=}")
# Check version is a valid Version
version = data.get("version")
self.assertTrue(version, f"Missing version in {manifest=}")
try:
# Until we can use packaging.version.Version check canonical version manually:
version_tuple = tuple(int(x) for x in version.split("."))
version_str = ".".join(str(x) for x in version_tuple)
except Exception as e:
self.fail(f"Invalid version {version=} in {manifest=}: {e}")
self.assertEqual(
version_str,
version,
f"{version=} in {manifest=} is not in canonical form",
)
# Test download_url:
download_url = data.get("download_url")
self.assertTrue(download_url, f"Missing download_url in {manifest=}")
self.assertTrue(
download_url.startswith("https://"),
f"Invalid download_url in {manifest=}: {download_url}",
)
self.assertIn(
"/apps/",
download_url,
f"Invalid download_url in {manifest=}: {download_url}",
)
self.assertIn(
fullname,
download_url,
f"Missing fullname in download_url: {download_url}",
)
self.assertIn(
version,
download_url,
f"Missing version in download_url: {download_url}",
)
# Test icon_url:
icon_url = data.get("icon_url")
self.assertTrue(icon_url, f"Missing icon_url in {manifest=}")
self.assertTrue(
icon_url.startswith("https://"),
f"Invalid icon_url in {manifest=}: {icon_url}",
)
self.assertIn(
"/apps/", icon_url,
f"Invalid icon_url in {manifest=}: {icon_url}",
)
self.assertIn(
fullname,
icon_url,
f"Missing fullname in icon_url: {icon_url}",
)
self.assertIn(
version,
icon_url,
f"Missing version in icon_url: {icon_url}",
)
# Test activities.entrypoint
activities = data.get("activities", [])
for act in activities:
entrypoint = act.get("entrypoint")
self.assertTrue(
entrypoint, f"Missing entrypoint in activity of {manifest=}"
)
self.assertTrue(
entrypoint.endswith(".py"),
f"Invalid entrypoint in activity of {manifest=}: {entrypoint}",
)
entrypoint_path = app_path / entrypoint
self.assertTrue(
entrypoint_path.is_file(),
f"{entrypoint=} in {manifest=} does not exist as file",
)
classname = act.get("classname")
self.assertTrue(
classname, f"Missing classname in activity of {manifest=}"
)
entrypoint_code = entrypoint_path.read_text()
self.assertIn(
classname,
entrypoint_code,
f"{classname=} not found in {entrypoint=} of {manifest=}",
)
if __name__ == "__main__":
unittest.main()