Revision 92fc67cf
Added by koszko over 1 year ago
test/unit/test_indexeddb.py | ||
---|---|---|
77 | 77 |
|
78 | 78 |
database_contents = get_db_contents(execute_in_page) |
79 | 79 |
|
80 |
assert len(database_contents['files']) == 4
|
|
80 |
assert len(database_contents['file']) == 4 |
|
81 | 81 |
assert all([sample_files_by_sha256[file['sha256']] == file['contents'] |
82 |
for file in database_contents['files']])
|
|
83 |
assert all([len(file) == 2 for file in database_contents['files']])
|
|
82 |
for file in database_contents['file']]) |
|
83 |
assert all([len(file) == 2 for file in database_contents['file']]) |
|
84 | 84 |
|
85 | 85 |
assert len(database_contents['file_uses']) == 4 |
86 | 86 |
assert all([uses['uses'] == 1 for uses in database_contents['file_uses']]) |
87 | 87 |
assert set([uses['sha256'] for uses in database_contents['file_uses']]) \ |
88 |
== set([file['sha256'] for file in database_contents['files']])
|
|
88 |
== set([file['sha256'] for file in database_contents['file']]) |
|
89 | 89 |
|
90 | 90 |
assert database_contents['mapping'] == [] |
91 | 91 |
assert database_contents['resource'] == [sample_item] |
... | ... | |
147 | 147 |
for file, nr in zip(sample_files_list, uses_list)]) |
148 | 148 |
|
149 | 149 |
files = dict([(file['sha256'], file['contents']) |
150 |
for file in database_contents['files']])
|
|
150 |
for file in database_contents['file']]) |
|
151 | 151 |
assert files == dict([(file['sha256'], file['contents']) |
152 | 152 |
for file in sample_files_list]) |
153 | 153 |
|
... | ... | |
179 | 179 |
assert uses == dict([(file['sha256'], 1) for file in sample_files_list]) |
180 | 180 |
|
181 | 181 |
files = dict([(file['sha256'], file['contents']) |
182 |
for file in results[0]['files']])
|
|
182 |
for file in results[0]['file']]) |
|
183 | 183 |
assert files == dict([(file['sha256'], file['contents']) |
184 | 184 |
for file in sample_files_list]) |
185 | 185 |
|
... | ... | |
192 | 192 |
sample_resource = make_sample_resource() |
193 | 193 |
sample_mapping = make_sample_mapping() |
194 | 194 |
initial_data = { |
195 |
'resources': {
|
|
195 |
'resource': { |
|
196 | 196 |
'helloapple': { |
197 | 197 |
'1.12': sample_resource, |
198 | 198 |
'0.9': 'something_that_should_get_ignored', |
... | ... | |
201 | 201 |
'1.11.1': 'something_that_should_get_ignored', |
202 | 202 |
} |
203 | 203 |
}, |
204 |
'mappings': {
|
|
204 |
'mapping': { |
|
205 | 205 |
'helloapple': { |
206 | 206 |
'0.1.1': sample_mapping |
207 | 207 |
} |
... | ... | |
222 | 222 |
def test_haketilodb_settings(driver, execute_in_page): |
223 | 223 |
""" |
224 | 224 |
indexeddb.js facilitates operating on Haketilo's internal database. |
225 |
Verify assigning/retrieving values of simple "settings" item works properly.
|
|
225 |
Verify assigning/retrieving values of simple "setting" item works properly. |
|
226 | 226 |
""" |
227 | 227 |
execute_in_page(load_script('common/indexeddb.js')) |
228 | 228 |
mock_broadcast(execute_in_page) |
... | ... | |
230 | 230 |
# Start with no database. |
231 | 231 |
clear_indexeddb(execute_in_page) |
232 | 232 |
|
233 |
assert get_db_contents(execute_in_page)['settings'] == []
|
|
233 |
assert get_db_contents(execute_in_page)['setting'] == [] |
|
234 | 234 |
|
235 | 235 |
assert execute_in_page('returnval(get_setting("option15"));') == None |
236 | 236 |
|
... | ... | |
280 | 280 |
# Start with no database. |
281 | 281 |
clear_indexeddb(execute_in_page) |
282 | 282 |
|
283 |
assert get_db_contents(execute_in_page)['repos'] == []
|
|
283 |
assert get_db_contents(execute_in_page)['repo'] == [] |
|
284 | 284 |
|
285 | 285 |
sample_urls = ['https://hdrlla.example.com/', 'https://hdrlla.example.org'] |
286 | 286 |
|
... | ... | |
342 | 342 |
sample_resource = make_sample_resource() |
343 | 343 |
sample_mapping = make_sample_mapping() |
344 | 344 |
initial_data = { |
345 |
'resources': {
|
|
345 |
'resource': { |
|
346 | 346 |
'helloapple': { |
347 | 347 |
'1.0': sample_resource |
348 | 348 |
} |
349 | 349 |
}, |
350 |
'mappings': {
|
|
350 |
'mapping': { |
|
351 | 351 |
'helloapple': { |
352 | 352 |
'0.1.1': sample_mapping |
353 | 353 |
} |
... | ... | |
404 | 404 |
for elem_id, json_value in [ |
405 | 405 |
('resource_helloapple', sample_resource), |
406 | 406 |
('mapping_helloapple', sample_mapping), |
407 |
('settings_option15', {'name': 'option15', 'value': '123'}),
|
|
408 |
('repos_https://hydril.la', {'url': 'https://hydril.la'}),
|
|
407 |
('setting_option15', {'name': 'option15', 'value': '123'}), |
|
408 |
('repo_https://hydril.la', {'url': 'https://hydril.la'}), |
|
409 | 409 |
('blocking_file:///*', {'pattern': 'file:///*', 'allow': False}) |
410 | 410 |
]: |
411 | 411 |
assert json.loads(driver.find_element_by_id(elem_id).text) == json_value |
... | ... | |
417 | 417 |
sample_mapping2 = make_sample_mapping() |
418 | 418 |
sample_mapping2['identifier'] = 'helloapple-copy' |
419 | 419 |
sample_data = { |
420 |
'resources': {
|
|
420 |
'resource': { |
|
421 | 421 |
'helloapple-copy': { |
422 | 422 |
'1.0': sample_resource2 |
423 | 423 |
} |
424 | 424 |
}, |
425 |
'mappings': {
|
|
425 |
'mapping': { |
|
426 | 426 |
'helloapple-copy': { |
427 | 427 |
'0.1.1': sample_mapping2 |
428 | 428 |
} |
... | ... | |
441 | 441 |
for elem_id, json_value in [ |
442 | 442 |
('resource_helloapple-copy', sample_resource2), |
443 | 443 |
('mapping_helloapple-copy', sample_mapping2), |
444 |
('settings_option22', {'name': 'option22', 'value': 'abc'}),
|
|
445 |
('repos_https://hydril2.la', {'url': 'https://hydril2.la'}),
|
|
444 |
('setting_option22', {'name': 'option22', 'value': 'abc'}), |
|
445 |
('repo_https://hydril2.la', {'url': 'https://hydril2.la'}), |
|
446 | 446 |
('blocking_ftp://a.bc/', {'pattern': 'ftp://a.bc/', 'allow': True}) |
447 | 447 |
]: |
448 | 448 |
assert json.loads(driver.find_element_by_id(elem_id).text) == json_value |
... | ... | |
468 | 468 |
}''') |
469 | 469 |
|
470 | 470 |
removed_ids = ['mapping_helloapple-copy', 'resource_helloapple', |
471 |
'repos_https://hydril.la', 'blocking_file:///*']
|
|
471 |
'repo_https://hydril.la', 'blocking_file:///*'] |
|
472 | 472 |
def condition_items_absent_and_changed(driver): |
473 | 473 |
for id in removed_ids: |
474 | 474 |
try: |
... | ... | |
477 | 477 |
except WebDriverException: |
478 | 478 |
pass |
479 | 479 |
|
480 |
option_text = driver.find_element_by_id('settings_option22').text
|
|
480 |
option_text = driver.find_element_by_id('setting_option22').text |
|
481 | 481 |
blocking_text = driver.find_element_by_id('blocking_ftp://a.bc/').text |
482 | 482 |
return (json.loads(option_text)['value'] == None and |
483 | 483 |
json.loads(blocking_text)['allow'] == False) |
Also available in: Unified diff
change store names and data keys to singular