Revision 74bbdd9a
Added by koszko over 1 year ago
test/haketilo_test/unit/test_install.py | ||
---|---|---|
70 | 70 |
if complex_variant: |
71 | 71 |
# The resource/mapping others depend on. |
72 | 72 |
root_id = 'abcd-defg-ghij' |
73 |
root_resource_id = f'resource_{root_id}'
|
|
74 |
root_mapping_id = f'mapping_{root_id}'
|
|
73 |
root_resource_id = f'resource-{root_id}'
|
|
74 |
root_mapping_id = f'mapping-{root_id}'
|
|
75 | 75 |
# Those ids are used to check the alphabetical ordering. |
76 |
resource_ids = [f'resource_{letters}' for letters in (
|
|
76 |
resource_ids = [f'resource-{letters}' for letters in (
|
|
77 | 77 |
'a', 'abcd', root_id, 'b', 'c', |
78 | 78 |
'd', 'defg', 'e', 'f', |
79 | 79 |
'g', 'ghij', 'h', 'i', 'j' |
80 | 80 |
)] |
81 | 81 |
files_count = 9 |
82 | 82 |
else: |
83 |
root_resource_id = f'resource_a'
|
|
84 |
root_mapping_id = f'mapping_a'
|
|
83 |
root_resource_id = f'resource-a'
|
|
84 |
root_mapping_id = f'mapping-a'
|
|
85 | 85 |
resource_ids = [root_resource_id] |
86 | 86 |
files_count = 0 |
87 | 87 |
|
... | ... | |
102 | 102 |
|
103 | 103 |
assert not execute_in_page('returnval(ets()[0].old_ver);').is_displayed() |
104 | 104 |
execute_in_page('returnval(ets()[0].details_but);').click() |
105 |
assert 'resource_a' in containers['resource_preview_container'].text
|
|
105 |
assert 'resource-a' in containers['resource_preview_container'].text
|
|
106 | 106 |
assert_container_displayed('resource_preview_container') |
107 | 107 |
|
108 | 108 |
execute_in_page('returnval(install_view.resource_back_but);').click() |
... | ... | |
246 | 246 |
browser.tabs.sendMessage = () => new Promise(cb => {}); |
247 | 247 |
install_view.show(...arguments); |
248 | 248 |
''', |
249 |
'https://hydril.la/', 'mapping', 'mapping_a')
|
|
249 |
'https://hydril.la/', 'mapping', 'mapping-a')
|
|
250 | 250 |
|
251 | 251 |
assert dlg_buts() == [] |
252 | 252 |
assert dialog_txt() == 'Fetching data from repository...' |
... | ... | |
256 | 256 |
browser.tabs.sendMessage = () => Promise.resolve({error: "sth"}); |
257 | 257 |
install_view.show(...arguments); |
258 | 258 |
''', |
259 |
'https://hydril.la/', 'mapping', 'mapping_a')
|
|
259 |
'https://hydril.la/', 'mapping', 'mapping-a')
|
|
260 | 260 |
|
261 | 261 |
assert_dlg(['conf_buts'], 'Failure to communicate with repository :(') |
262 | 262 |
elif message == 'HTTP_code_item': |
... | ... | |
266 | 266 |
browser.tabs.sendMessage = () => Promise.resolve(response); |
267 | 267 |
install_view.show(...arguments); |
268 | 268 |
''', |
269 |
'https://hydril.la/', 'mapping', 'mapping_a')
|
|
269 |
'https://hydril.la/', 'mapping', 'mapping-a')
|
|
270 | 270 |
|
271 | 271 |
assert_dlg(['conf_buts'], 'Repository sent HTTP code 404 :(') |
272 | 272 |
elif message == 'invalid_JSON': |
... | ... | |
276 | 276 |
browser.tabs.sendMessage = () => Promise.resolve(response); |
277 | 277 |
install_view.show(...arguments); |
278 | 278 |
''', |
279 |
'https://hydril.la/', 'mapping', 'mapping_a')
|
|
279 |
'https://hydril.la/', 'mapping', 'mapping-a')
|
|
280 | 280 |
|
281 | 281 |
assert_dlg(['conf_buts'], "Repository's response is not valid JSON :(") |
282 | 282 |
elif message == 'newer_API_version': |
283 | 283 |
execute_in_page( |
284 | 284 |
''' |
285 |
const response = {
|
|
286 |
ok: true,
|
|
287 |
status: 200,
|
|
288 |
json: {$schema: "https://hydrilla.koszko.org/schemas/api_mapping_description-2.1.schema.json"}
|
|
289 |
};
|
|
290 |
browser.tabs.sendMessage = () => Promise.resolve(response);
|
|
285 |
const old_sendMessage = browser.tabs.sendMessage;
|
|
286 |
browser.tabs.sendMessage = async function(...args) {
|
|
287 |
const response = await old_sendMessage(...args);
|
|
288 |
response.json.$schema = "https://hydrilla.koszko.org/schemas/api_mapping_description-255.1.schema.json";
|
|
289 |
return response;
|
|
290 |
}
|
|
291 | 291 |
install_view.show(...arguments); |
292 | 292 |
''', |
293 |
'https://hydril.la/', 'mapping', 'somemapping', [2, 1])
|
|
293 |
'https://hydril.la/', 'mapping', 'mapping-a', [2022, 5, 10])
|
|
294 | 294 |
|
295 | 295 |
assert_dlg(['conf_buts'], |
296 |
'Mapping somemapping-2.1 was served using unsupported Hydrilla API version. You might need to update Haketilo.')
|
|
296 |
'Mapping mapping-a-2022.5.10 was served using unsupported Hydrilla API version. You might need to update Haketilo.')
|
|
297 | 297 |
elif message == 'invalid_response_format': |
298 | 298 |
execute_in_page( |
299 | 299 |
''' |
300 |
const response = {
|
|
301 |
ok: true,
|
|
302 |
status: 200,
|
|
303 |
/* $schema is not a string as it should be. */
|
|
304 |
json: {$schema: null}
|
|
305 |
};
|
|
306 |
browser.tabs.sendMessage = () => Promise.resolve(response);
|
|
300 |
const old_sendMessage = browser.tabs.sendMessage;
|
|
301 |
browser.tabs.sendMessage = async function(...args) {
|
|
302 |
const response = await old_sendMessage(...args);
|
|
303 |
/* identifier is not a string as it should be. */
|
|
304 |
response.json.identifier = 1234567;
|
|
305 |
return response;
|
|
306 |
}
|
|
307 | 307 |
install_view.show(...arguments); |
308 | 308 |
''', |
309 |
'https://hydril.la/', 'resource', 'someresource')
|
|
309 |
'https://hydril.la/', 'resource', 'resource-a')
|
|
310 | 310 |
|
311 | 311 |
assert_dlg(['conf_buts'], |
312 |
'Resource someresource was served using a nonconforming response format.')
|
|
312 |
'Resource resource-a was served using a nonconforming response format.')
|
|
313 | 313 |
elif message == 'indexeddb_error_item': |
314 | 314 |
execute_in_page( |
315 | 315 |
''' |
316 | 316 |
haketilodb.idb_get = () => {throw "some error";}; |
317 | 317 |
install_view.show(...arguments); |
318 | 318 |
''', |
319 |
'https://hydril.la/', 'mapping', 'mapping_a')
|
|
319 |
'https://hydril.la/', 'mapping', 'mapping-a')
|
|
320 | 320 |
|
321 | 321 |
assert_dlg(['conf_buts'], |
322 | 322 |
"Error accessing Haketilo's internal database :(") |
... | ... | |
326 | 326 |
haketilodb.save_items = () => new Promise(() => {}); |
327 | 327 |
returnval(install_view.show(...arguments)); |
328 | 328 |
''', |
329 |
'https://hydril.la/', 'mapping', 'mapping_b')
|
|
329 |
'https://hydril.la/', 'mapping', 'mapping-b')
|
|
330 | 330 |
|
331 | 331 |
execute_in_page('returnval(install_view.install_but);').click() |
332 | 332 |
|
... | ... | |
343 | 343 |
} |
344 | 344 |
returnval(install_view.show(...arguments)); |
345 | 345 |
''', |
346 |
'https://hydril.la/', 'mapping', 'mapping_b')
|
|
346 |
'https://hydril.la/', 'mapping', 'mapping-b')
|
|
347 | 347 |
|
348 | 348 |
execute_in_page('returnval(install_view.install_but);').click() |
349 | 349 |
|
... | ... | |
355 | 355 |
fetch = () => {throw "some error";}; |
356 | 356 |
returnval(install_view.show(...arguments)); |
357 | 357 |
''', |
358 |
'https://hydril.la/', 'mapping', 'mapping_b')
|
|
358 |
'https://hydril.la/', 'mapping', 'mapping-b')
|
|
359 | 359 |
|
360 | 360 |
execute_in_page('returnval(install_view.install_but);').click() |
361 | 361 |
|
... | ... | |
367 | 367 |
fetch = () => Promise.resolve({ok: false, status: 400}); |
368 | 368 |
returnval(install_view.show(...arguments)); |
369 | 369 |
''', |
370 |
'https://hydril.la/', 'mapping', 'mapping_b')
|
|
370 |
'https://hydril.la/', 'mapping', 'mapping-b')
|
|
371 | 371 |
|
372 | 372 |
execute_in_page('returnval(install_view.install_but);').click() |
373 | 373 |
|
... | ... | |
379 | 379 |
fetch = () => Promise.resolve({ok: true, status: 200, text: err}); |
380 | 380 |
returnval(install_view.show(...arguments)); |
381 | 381 |
''', |
382 |
'https://hydril.la/', 'mapping', 'mapping_b')
|
|
382 |
'https://hydril.la/', 'mapping', 'mapping-b')
|
|
383 | 383 |
|
384 | 384 |
execute_in_page('returnval(install_view.install_but);').click() |
385 | 385 |
|
... | ... | |
396 | 396 |
} |
397 | 397 |
returnval(install_view.show(...arguments)); |
398 | 398 |
''', |
399 |
'https://hydril.la/', 'mapping', 'mapping_b')
|
|
399 |
'https://hydril.la/', 'mapping', 'mapping-b')
|
|
400 | 400 |
|
401 | 401 |
execute_in_page('returnval(install_view.install_but);').click() |
402 | 402 |
|
... | ... | |
413 | 413 |
haketilodb.save_items = () => {throw "some error";}; |
414 | 414 |
returnval(install_view.show(...arguments)); |
415 | 415 |
''', |
416 |
'https://hydril.la/', 'mapping', 'mapping_b')
|
|
416 |
'https://hydril.la/', 'mapping', 'mapping-b')
|
|
417 | 417 |
|
418 | 418 |
execute_in_page('returnval(install_view.install_but);').click() |
419 | 419 |
|
Also available in: Unified diff
validate repository responses against JSON schemas