diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-02-09 17:09:13 +0100 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-02-09 18:00:16 +0100 |
commit | 1c65dd5ca24052ccf9a92939eecd0966c9635c50 (patch) | |
tree | 7575157ccd729b4ad79f6c04501023ccb0532a63 /test/unit/test_indexeddb.py | |
parent | 830d22d8931a4e5f0606d401f24d7cd937f8697e (diff) | |
download | browser-extension-1c65dd5ca24052ccf9a92939eecd0966c9635c50.tar.gz browser-extension-1c65dd5ca24052ccf9a92939eecd0966c9635c50.zip |
adapt to changes in file path format
From now on we assume Hydrilla serves file contents at 'file/sha256/<hash>' instead of 'file/sha256-<hash>'.
With this commit we also stop using the "hash_key" property internally.
Diffstat (limited to 'test/unit/test_indexeddb.py')
-rw-r--r-- | test/unit/test_indexeddb.py | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/test/unit/test_indexeddb.py b/test/unit/test_indexeddb.py index 7ce4781..9041116 100644 --- a/test/unit/test_indexeddb.py +++ b/test/unit/test_indexeddb.py @@ -6,7 +6,7 @@ Haketilo unit tests - IndexedDB access # This file is part of Haketilo # -# Copyright (C) 2021,2022 Wojtek Kosior <koszko@koszko.org> +# Copyright (C) 2021, 2022 Wojtek Kosior <koszko@koszko.org> # # This program is free software: you can redistribute it and/or modify # it under the terms of the CC0 1.0 Universal License as published by @@ -73,19 +73,19 @@ def test_haketilodb_item_modifications(driver, execute_in_page): .then(finalize_transaction); returnval(promise); }''', - sample_item, sample_files_by_hash) + sample_item, {'sha256': sample_files_by_sha256}) database_contents = get_db_contents(execute_in_page) assert len(database_contents['files']) == 4 - assert all([sample_files_by_hash[file['hash_key']] == file['contents'] + assert all([sample_files_by_sha256[file['sha256']] == file['contents'] for file in database_contents['files']]) assert all([len(file) == 2 for file in database_contents['files']]) assert len(database_contents['file_uses']) == 4 assert all([uses['uses'] == 1 for uses in database_contents['file_uses']]) - assert set([uses['hash_key'] for uses in database_contents['file_uses']]) \ - == set([file['hash_key'] for file in database_contents['files']]) + assert set([uses['sha256'] for uses in database_contents['file_uses']]) \ + == set([file['sha256'] for file in database_contents['files']]) assert database_contents['mapping'] == [] assert database_contents['resource'] == [sample_item] @@ -93,8 +93,8 @@ def test_haketilodb_item_modifications(driver, execute_in_page): # See if trying to add an item without providing all its files ends in an # exception and aborts the transaction as it should. sample_item['scripts'].append(sample_file_ref('combined.js')) - incomplete_files = {**sample_files_by_hash} - incomplete_files.pop(sample_files['combined.js']['hash_key']) + incomplete_files = {**sample_files_by_sha256} + incomplete_files.pop(sample_files['combined.js']['sha256']) exception = execute_in_page( '''{ const args = arguments; @@ -112,14 +112,14 @@ def test_haketilodb_item_modifications(driver, execute_in_page): } returnval(try_add_item()); }''', - sample_item, incomplete_files) + sample_item, {'sha256': incomplete_files}) previous_database_contents = database_contents database_contents = get_db_contents(execute_in_page) assert 'file not present' in exception for key, val in database_contents.items(): - keyfun = lambda item: item.get('hash_key') or item['identifier'] + keyfun = lambda item: item.get('sha256') or item['identifier'] assert sorted(previous_database_contents[key], key=keyfun) \ == sorted(val, key=keyfun) @@ -132,7 +132,7 @@ def test_haketilodb_item_modifications(driver, execute_in_page): .then(finalize_transaction); returnval(promise); }''', - sample_item, sample_files_by_hash) + sample_item, {'sha256': sample_files_by_sha256}) database_contents = get_db_contents(execute_in_page) @@ -141,14 +141,14 @@ def test_haketilodb_item_modifications(driver, execute_in_page): sample_files_list = [sample_files[name] for name in names] uses_list = [1, 2, 1, 1, 1] - uses = dict([(uses['hash_key'], uses['uses']) + uses = dict([(uses['sha256'], uses['uses']) for uses in database_contents['file_uses']]) - assert uses == dict([(file['hash_key'], nr) + assert uses == dict([(file['sha256'], nr) for file, nr in zip(sample_files_list, uses_list)]) - files = dict([(file['hash_key'], file['contents']) + files = dict([(file['sha256'], file['contents']) for file in database_contents['files']]) - assert files == dict([(file['hash_key'], file['contents']) + assert files == dict([(file['sha256'], file['contents']) for file in sample_files_list]) del database_contents['resource'][0]['source_copyright'][0]['extra_prop'] @@ -174,13 +174,13 @@ def test_haketilodb_item_modifications(driver, execute_in_page): sample_files_list = [sample_files[name] for name in names] uses_list = [1, 1] - uses = dict([(uses['hash_key'], uses['uses']) + uses = dict([(uses['sha256'], uses['uses']) for uses in results[0]['file_uses']]) - assert uses == dict([(file['hash_key'], 1) for file in sample_files_list]) + assert uses == dict([(file['sha256'], 1) for file in sample_files_list]) - files = dict([(file['hash_key'], file['contents']) + files = dict([(file['sha256'], file['contents']) for file in results[0]['files']]) - assert files == dict([(file['hash_key'], file['contents']) + assert files == dict([(file['sha256'], file['contents']) for file in sample_files_list]) assert results[0]['resource'] == [] @@ -206,7 +206,9 @@ def test_haketilodb_item_modifications(driver, execute_in_page): '0.1.1': sample_mapping } }, - 'files': sample_files_by_hash + 'file': { + 'sha256': sample_files_by_sha256 + } } clear_indexeddb(execute_in_page) @@ -350,7 +352,9 @@ def test_haketilodb_track(driver, execute_in_page, wait_elem_text): '0.1.1': sample_mapping } }, - 'files': sample_files_by_hash + 'file': { + 'sha256': sample_files_by_sha256 + } } driver.switch_to.window(windows[1]) execute_in_page('initial_data = arguments[0];', initial_data) @@ -423,7 +427,9 @@ def test_haketilodb_track(driver, execute_in_page, wait_elem_text): '0.1.1': sample_mapping2 } }, - 'files': sample_files_by_hash + 'file': { + 'sha256': sample_files_by_sha256 + } } execute_in_page('returnval(save_items(arguments[0]));', sample_data) execute_in_page('returnval(set_setting("option22", "abc"));') |