Skip to content

Commit af20c16

Browse files
committed
Added test coverage for the stale remote config logic.
1 parent bff2f0d commit af20c16

File tree

1 file changed

+76
-10
lines changed

1 file changed

+76
-10
lines changed

test/unit_tests/test_profile.py

Lines changed: 76 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,104 @@
33
"""
44

55
import json
6+
import copy
67
from test.conftest import ApioRunner
78
from apio.profile import Profile
9+
from apio.utils import util
10+
811

912
TEST_DATA = {
1013
"installed-packages": {
11-
"examples": {"version": "0.1.4"},
12-
"verible": {"version": "0.0.1"},
14+
"drivers": {"version": "2025.06.13"},
15+
"examples": {"version": "2025.06.21"},
1316
},
1417
"preferences": {"theme": "light"},
1518
"remote-config": {
19+
"metadata": {
20+
"loaded-at": "2025-06-29-07-18",
21+
"loaded-by": util.get_apio_version(),
22+
"loaded-from": (
23+
"https://github.com/FPGAwars/apio/raw/develop/"
24+
"remote-config/apio-0.9.7.jsonc"
25+
),
26+
},
1627
"packages": {
17-
"drivers": {"version": "1.2.0"},
18-
"examples": {"version": "0.1.4"},
19-
}
28+
"drivers": {
29+
"release": {
30+
"package-file": "apio-drivers-${PLATFORM}-${YYYYMMDD}.tgz",
31+
"release-tag": "${YYYY-MM-DD}",
32+
"version": "2025.06.13",
33+
},
34+
"repository": {
35+
"name": "tools-drivers",
36+
"organization": "FPGAwars",
37+
},
38+
},
39+
"examples": {
40+
"release": {
41+
"package-file": "apio-examples-${YYYYMMDD}.tgz",
42+
"release-tag": "${YYYY-MM-DD}",
43+
"version": "2025.06.21",
44+
},
45+
"repository": {
46+
"name": "apio-examples",
47+
"organization": "FPGAwars",
48+
},
49+
},
50+
},
2051
},
2152
}
2253

2354

24-
def test_profile_loading(apio_runner: ApioRunner):
55+
def test_profile_loading_config_ok(apio_runner: ApioRunner):
2556
"""Tests the loading and validation of a profile file."""
2657

2758
with apio_runner.in_sandbox() as sb:
2859

2960
# -- Write a test profile.json file.
3061
path = sb.home_dir / "profile.json"
31-
sb.write_file(path, json.dumps(TEST_DATA, indent=2))
62+
test_data = copy.deepcopy(TEST_DATA)
63+
sb.write_file(
64+
path,
65+
json.dumps(
66+
test_data,
67+
indent=2,
68+
),
69+
)
70+
71+
# -- Read back the content.
72+
profile = Profile(sb.home_dir, "http://fake-domain.com/config")
73+
74+
# -- Verify
75+
assert profile.preferences == test_data["preferences"]
76+
assert profile.packages == test_data["installed-packages"]
77+
assert profile.remote_config == test_data["remote-config"]
78+
assert not profile.remote_config_fetched
79+
80+
81+
def test_profile_loading_config_stale(apio_runner: ApioRunner):
82+
"""Tests the loading and validation of a profile file."""
83+
84+
with apio_runner.in_sandbox() as sb:
85+
86+
# -- Write a test profile.json file. We set an old apio version
87+
# -- to cause the cached remote config to be classified as stale.
88+
path = sb.home_dir / "profile.json"
89+
test_data = copy.deepcopy(TEST_DATA)
90+
test_data["remote-config"]["metadata"]["loaded-by"] = "0.9.6"
91+
sb.write_file(
92+
path,
93+
json.dumps(
94+
test_data,
95+
indent=2,
96+
),
97+
)
3298

3399
# -- Read back the content.
34100
profile = Profile(sb.home_dir, "http://fake-domain.com/config")
35101

36102
# -- Verify
37-
assert profile.preferences == TEST_DATA["preferences"]
38-
assert profile.packages == TEST_DATA["installed-packages"]
39-
assert profile.remote_config == TEST_DATA["remote-config"]
103+
assert profile.preferences == test_data["preferences"]
104+
assert profile.packages == test_data["installed-packages"]
105+
assert profile.remote_config == {} # Config rejected
40106
assert not profile.remote_config_fetched

0 commit comments

Comments
 (0)