36
36
class TestCandidates(unittest.TestCase):
37
37
def test_no_images(self):
38
38
# If there are no images defined, there are no candidates.
39
index = get_index('index_01.json')
39
index = get_index('candidates.index_01.json')
40
40
candidates = get_candidates(index, 1400)
41
41
self.assertEqual(candidates, [])
43
43
def test_only_higher_fulls(self):
44
44
# All the full images have a minversion greater than our version, so
45
45
# we cannot upgrade to any of them.
46
index = get_index('index_02.json')
46
index = get_index('candidates.index_02.json')
47
47
candidates = get_candidates(index, 100)
48
48
self.assertEqual(candidates, [])
50
50
def test_one_higher_full(self):
51
51
# Our device is between the minversions of the two available fulls, so
52
52
# the older one can be upgraded too.
53
index = get_index('index_02.json')
53
index = get_index('candidates.index_02.json')
54
54
candidates = get_candidates(index, 800)
55
55
# There is exactly one upgrade path.
56
56
self.assertEqual(len(candidates), 1)
64
64
def test_fulls_with_no_minversion(self):
65
65
# Like the previous test, there are two full upgrades, but because
66
66
# neither of them have minversions, both are candidates.
67
index = get_index('index_05.json')
67
index = get_index('candidates.index_03.json')
68
68
candidates = get_candidates(index, 400)
69
69
self.assertEqual(len(candidates), 2)
70
70
# Both candidate paths have exactly one image in them. We can't sort
82
82
def test_no_deltas_based_on_us(self):
83
83
# There are deltas in the test data, but no fulls. None of the deltas
84
84
# have a base equal to our build number.
85
index = get_index('index_03.json')
85
index = get_index('candidates.index_04.json')
86
86
candidates = get_candidates(index, 100)
87
87
self.assertEqual(candidates, [])
89
89
def test_one_delta_based_on_us(self):
90
90
# There is one delta in the test data that is based on us.
91
index = get_index('index_03.json')
91
index = get_index('candidates.index_04.json')
92
92
candidates = get_candidates(index, 500)
93
93
self.assertEqual(len(candidates), 1)
94
94
path = candidates[0]
100
100
def test_two_deltas_based_on_us(self):
101
101
# There are two deltas that are based on us, so both are candidates.
102
102
# They get us to different final versions.
103
index = get_index('index_04.json')
103
index = get_index('candidates.index_05.json')
104
104
candidates = get_candidates(index, 1100)
105
105
self.assertEqual(len(candidates), 2)
106
106
# Both candidate paths have exactly one image in them. We can't sort
115
115
def test_one_path_with_full_and_deltas(self):
116
116
# There's one path to upgrade from our version to the final version.
117
117
# This one starts at a full and includes several deltas.
118
index = get_index('index_06.json')
118
index = get_index('candidates.index_06.json')
119
119
candidates = get_candidates(index, 1000)
120
120
self.assertEqual(len(candidates), 1)
121
121
path = candidates[0]
128
128
# Similar to above, except that because we're upgrading from the
129
129
# version of the full, the path is only two images long, i.e. the
131
index = get_index('index_06.json')
131
index = get_index('candidates.index_06.json')
132
132
candidates = get_candidates(index, 1300)
133
133
self.assertEqual(len(candidates), 1)
134
134
path = candidates[0]
140
140
# We have a fork in the road. There is a full update, but two deltas
141
141
# with different versions point to the same base. This will give us
142
142
# two upgrade paths, both of which include the full.
143
index = get_index('index_07.json')
143
index = get_index('candidates.index_07.json')
144
144
candidates = get_candidates(index, 1200)
145
145
self.assertEqual(len(candidates), 2)
146
146
# We can sort the paths by length.
171
171
def test_get_downloads(self):
172
172
# Path B will win; it has one full and two deltas, none of which have
173
173
# a bootme flag. Download all their files.
174
index = get_index('index_10.json')
174
index = get_index('candidates.index_08.json')
175
175
candidates = get_candidates(index, 600)
176
176
winner = WeightedScorer().choose(candidates, 'devel')
177
177
descriptions = []
209
209
def test_get_downloads_with_bootme(self):
210
210
# Path B will win; it has one full and two deltas. The first delta
211
211
# has a bootme flag so the second delta's files are not downloaded.
212
index = get_index('index_11.json')
212
index = get_index('candidates.index_09.json')
213
213
candidates = get_candidates(index, 600)
214
214
winner = WeightedScorer().choose(candidates, 'devel')
215
215
descriptions = []
234
234
# Run a filter over the candidates, such that the only ones left are
235
235
# those that contain only full upgrades. This can truncate any paths
236
236
# that start with some fulls and then contain some deltas.
237
index = get_index('index_10.json')
237
index = get_index('candidates.index_08.json')
238
238
candidates = get_candidates(index, 600)
239
239
filtered = full_filter(candidates)
240
240
# Since all images start with a full update, we're still left with
250
250
def test_filter_for_fulls_one_candidate(self):
251
251
# Filter for full updates, where the only candidate has one full image.
252
index = get_index('index_13.json')
252
index = get_index('candidates.index_10.json')
253
253
candidates = get_candidates(index, 600)
254
254
filtered = full_filter(candidates)
255
255
self.assertEqual(filtered, candidates)
257
257
def test_filter_for_fulls_with_just_delta_candidates(self):
258
258
# A candidate path that contains only deltas will have no filtered
259
259
# paths if all the images are delta updates.
260
index = get_index('index_15.json')
260
index = get_index('candidates.index_11.json')
261
261
candidates = get_candidates(index, 100)
262
262
self.assertEqual(len(candidates), 1)
263
263
filtered = full_filter(candidates)
266
266
def test_filter_for_deltas(self):
267
267
# Filter the candidates, where the only available path is a delta path.
268
index = get_index('index_15.json')
268
index = get_index('candidates.index_11.json')
269
269
candidates = get_candidates(index, 100)
270
270
self.assertEqual(len(candidates), 1)
271
271
filtered = delta_filter(candidates)
276
276
# Run a filter over the candidates, such that the only ones left are
277
277
# those that start with and contain only deltas. Since none of the
278
278
# paths do so, tere are no candidates left.
279
index = get_index('index_10.json')
279
index = get_index('candidates.index_08.json')
280
280
candidates = get_candidates(index, 600)
281
281
filtered = delta_filter(candidates)
282
282
self.assertEqual(len(filtered), 0)
284
284
def test_filter_for_deltas_one_candidate(self):
285
285
# Filter for delta updates, but the only candidate is a full.
286
index = get_index('index_13.json')
286
index = get_index('candidates.index_10.json')
287
287
candidates = get_candidates(index, 600)
288
288
filtered = delta_filter(candidates)
289
289
self.assertEqual(len(filtered), 0)
291
291
def test_filter_for_multiple_deltas(self):
292
292
# The candidate path has multiple deltas. All are preserved.
293
index = get_index('index_19.json')
293
index = get_index('candidates.index_12.json')
294
294
candidates = get_candidates(index, 100)
295
295
filtered = delta_filter(candidates)
296
296
self.assertEqual(len(filtered), 1)
306
306
def test_candidates(self):
307
307
# Path B will win; it has one full and two deltas.
308
index = get_index('index_20.json')
308
index = get_index('candidates.index_13.json')
309
309
candidates = get_candidates(index, 0)
310
310
self.assertEqual(len(candidates), 3)
311
311
path0 = candidates[0]