From 92fc67cfa135526cef75311c3ee1a14e248c3060 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Tue, 15 Feb 2022 13:18:59 +0100 Subject: change store names and data keys to singular --- background/indexeddb_files_server.js | 4 +-- background/patterns_query_manager.js | 2 +- common/indexeddb.js | 60 ++++++++++++++++++-------------- default_settings.json | 9 ++--- html/default_blocking_policy.js | 2 +- html/file_preview.js | 4 +-- html/install.js | 5 ++- html/text_entry_list.js | 2 +- test/unit/test_indexeddb.py | 42 +++++++++++----------- test/unit/test_indexeddb_files_server.py | 8 ++--- test/unit/test_install.py | 2 +- test/unit/test_item_list.py | 14 ++++---- test/unit/test_item_preview.py | 2 +- test/unit/test_patterns_query_manager.py | 10 +++--- test/unit/utils.py | 4 +-- 15 files changed, 88 insertions(+), 82 deletions(-) diff --git a/background/indexeddb_files_server.js b/background/indexeddb_files_server.js index 24fa700..c548b74 100644 --- a/background/indexeddb_files_server.js +++ b/background/indexeddb_files_server.js @@ -59,7 +59,7 @@ async function get_resource_files(getting, id) { getting.defs_by_res_id.set(id, definition); const file_proms = (definition.scripts || []) - .map(s => haketilodb.idb_get(getting.tx, "files", s.sha256)); + .map(s => haketilodb.idb_get(getting.tx, "file", s.sha256)); const deps_proms = (definition.dependencies || []) .map(res_ref => get_resource_files(getting, res_ref.identifier)); @@ -104,7 +104,7 @@ async function send_resource_files(root_resource_id, send_cb) { const getting = { defs_by_res_id: new Map(), files_by_res_id: new Map(), - tx: db.transaction(["files", "resource"]) + tx: db.transaction(["file", "resource"]) }; let prom_cbs, prom = new Promise((...cbs) => prom_cbs = cbs); diff --git a/background/patterns_query_manager.js b/background/patterns_query_manager.js index d3c659a..863fbe9 100644 --- a/background/patterns_query_manager.js +++ b/background/patterns_query_manager.js @@ -160,7 +160,7 @@ async function start(secret_) { initial_blocking.forEach(b => register("blocking", b)); const [setting_tracking, initial_settings] = - await haketilodb.track.settings(setting_changed); + await haketilodb.track.setting(setting_changed); for (const setting of initial_settings) { if (setting.name === "default_allow") diff --git a/common/indexeddb.js b/common/indexeddb.js index 371d491..cf38d23 100644 --- a/common/indexeddb.js +++ b/common/indexeddb.js @@ -59,13 +59,13 @@ const nr_reductor = ([i, s], num) => [i - 1, s + num * 1024 ** i]; const version_nr = ver => ver.slice(0, 3).reduce(nr_reductor, [2, 0])[1]; const stores = [ - ["files", {keyPath: "sha256"}], + ["file", {keyPath: "sha256"}], ["file_uses", {keyPath: "sha256"}], ["resource", {keyPath: "identifier"}], ["mapping", {keyPath: "identifier"}], - ["settings", {keyPath: "name"}], + ["setting", {keyPath: "name"}], ["blocking", {keyPath: "pattern"}], - ["repos", {keyPath: "url"}] + ["repo", {keyPath: "url"}] ]; let db = null; @@ -111,7 +111,7 @@ async function perform_upgrade(event) { store = opened_db.createObjectStore(store_name, key_mode); const ctx = make_context(store.transaction, initial_data.file); - await _save_items(initial_data.resources, initial_data.mappings, ctx); + await _save_items(initial_data.resource, initial_data.mapping, [], ctx); return opened_db; } @@ -186,7 +186,7 @@ function make_context(transaction, files) async function start_items_transaction(item_store_names, files) { const db = await get_db(); - const scope = [...item_store_names, "files", "file_uses"]; + const scope = [...item_store_names, "file", "file_uses"]; return make_context(db.transaction(scope, "readwrite"), files); } #EXPORT start_items_transaction @@ -226,7 +226,7 @@ async function finalize_transaction(context) if (uses.uses < 1) { if (!is_new) { idb_del(context.transaction, "file_uses", sha256); - idb_del(context.transaction, "files", sha256); + idb_del(context.transaction, "file", sha256); } continue; @@ -246,7 +246,7 @@ async function finalize_transaction(context) throw "file not present: " + sha256; } - idb_put(context.transaction, "files", {sha256, contents: file}); + idb_put(context.transaction, "file", {sha256, contents: file}); } return context.result; @@ -257,7 +257,7 @@ async function finalize_transaction(context) * How a sample data argument to the function below might look like: * * data = { - * resources: { + * resource: { * "resource1": { * "1": { * // some stuff @@ -272,7 +272,7 @@ async function finalize_transaction(context) * } * }, * }, - * mappings: { + * mapping: { * "mapping1": { * "2": { * // some stuff @@ -295,13 +295,16 @@ async function finalize_transaction(context) async function save_items(data) { const item_store_names = ["resource", "mapping"]; + if ("repo" in data) + item_store_names.push("repo"); + const context = await start_items_transaction(item_store_names, data.file); - return _save_items(data.resources, data.mappings, context); + return _save_items(data.resource, data.mapping, data.repo || [], context); } #EXPORT save_items -async function _save_items(resources, mappings, context) +async function _save_items(resources, mappings, repos, context) { resources = Object.values(resources || {}).map(entities.get_newest); mappings = Object.values(mappings || {}).map(entities.get_newest); @@ -309,6 +312,9 @@ async function _save_items(resources, mappings, context) for (const item of resources.concat(mappings)) await save_item(item, context); + for (const repo_url of repos) + await idb_put(context.transaction, "repo", {url: repo_url}); + await finalize_transaction(context); } @@ -378,7 +384,7 @@ async function get_all(store_name) /* * A simplified kind of transaction for modifying stores without special - * inter-store integrity constraints ("settings", "blocking", "repos"). + * inter-store integrity constraints ("setting", "blocking", "repo"). */ async function start_simple_transaction(store_name) { @@ -386,20 +392,20 @@ async function start_simple_transaction(store_name) return make_context(db.transaction(store_name, "readwrite"), {}); } -/* Functions to access the "settings" store. */ +/* Functions to access the "setting" store. */ async function set_setting(name, value) { - const context = await start_simple_transaction("settings"); - broadcast.prepare(context.sender, "idb_changes_settings", name); - await idb_put(context.transaction, "settings", {name, value}); + const context = await start_simple_transaction("setting"); + broadcast.prepare(context.sender, "idb_changes_setting", name); + await idb_put(context.transaction, "setting", {name, value}); return finalize_transaction(context); } #EXPORT set_setting async function get_setting(name) { - const transaction = (await get_db()).transaction("settings"); - return ((await idb_get(transaction, "settings", name)) || {}).value; + const transaction = (await get_db()).transaction("setting"); + return ((await idb_get(transaction, "setting", name)) || {}).value; } #EXPORT get_setting @@ -429,15 +435,15 @@ async function get_allowing(pattern) } #EXPORT get_allowing -/* Functions to access the "repos" store. */ +/* Functions to access the "repo" store. */ async function set_repo(url, remove=false) { - const context = await start_simple_transaction("repos"); - broadcast.prepare(context.sender, "idb_changes_repos", url); + const context = await start_simple_transaction("repo"); + broadcast.prepare(context.sender, "idb_changes_repo", url); if (remove) - await idb_del(context.transaction, "repos", url); + await idb_del(context.transaction, "repo", url); else - await idb_put(context.transaction, "repos", {url}); + await idb_put(context.transaction, "repo", {url}); return finalize_transaction(context); } #EXPORT set_repo @@ -445,7 +451,7 @@ async function set_repo(url, remove=false) const del_repo = url => set_repo(url, true); #EXPORT del_repo -const get_repos = () => get_all("repos").then(list => list.map(obj => obj.url)); +const get_repos = () => get_all("repo").then(list => list.map(obj => obj.url)); #EXPORT get_repos /* Callback used when listening to broadcasts while tracking db changes. */ @@ -460,8 +466,8 @@ async function track_change(tracking, key) /* * Monitor changes to `store_name` IndexedDB object store. * - * `store_name` should be either "resource", "mapping", "settings", "blocking" - * or "repos". + * `store_name` should be either "resource", "mapping", "setting", "blocking" + * or "repo". * * `onchange` should be a callback that will be called when an item is added, * modified or removed from the store. The callback will be passed an object @@ -492,7 +498,7 @@ async function start_tracking(store_name, onchange) } const track = {}; -const trackable = ["resource", "mapping", "settings", "blocking", "repos"]; +const trackable = ["resource", "mapping", "setting", "blocking", "repo"]; for (const store_name of trackable) track[store_name] = onchange => start_tracking(store_name, onchange); #EXPORT track diff --git a/default_settings.json b/default_settings.json index 3ce6856..6b6ca86 100644 --- a/default_settings.json +++ b/default_settings.json @@ -21,7 +21,7 @@ // the notice above. #ENDIF { - "resources": { + "resource": { "haketilo-demo-script": { "2022.1.28": { "source_name": "haketilo-default-settings", @@ -44,7 +44,7 @@ } } }, - "mappings": { + "mapping": { "haketilo-demo-message": { "2022.1.28": { "source_name": "haketilo-default-settings", @@ -66,10 +66,11 @@ } } }, - "files": { + "file": { "sha256": { "a2010f343487d3f7618affe54f789f5487602331c0a8d03f49e9a7c547cf0499": "Creative Commons Legal Code\n\nCC0 1.0 Universal\n\n CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE\n LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN\n ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS\n INFORMATION ON AN \"AS-IS\" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES\n REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS\n PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM\n THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED\n HEREUNDER.\n\nStatement of Purpose\n\nThe laws of most jurisdictions throughout the world automatically confer\nexclusive Copyright and Related Rights (defined below) upon the creator\nand subsequent owner(s) (each and all, an \"owner\") of an original work of\nauthorship and/or a database (each, a \"Work\").\n\nCertain owners wish to permanently relinquish those rights to a Work for\nthe purpose of contributing to a commons of creative, cultural and\nscientific works (\"Commons\") that the public can reliably and without fear\nof later claims of infringement build upon, modify, incorporate in other\nworks, reuse and redistribute as freely as possible in any form whatsoever\nand for any purposes, including without limitation commercial purposes.\nThese owners may contribute to the Commons to promote the ideal of a free\nculture and the further production of creative, cultural and scientific\nworks, or to gain reputation or greater distribution for their Work in\npart through the use and efforts of others.\n\nFor these and/or other purposes and motivations, and without any\nexpectation of additional consideration or compensation, the person\nassociating CC0 with a Work (the \"Affirmer\"), to the extent that he or she\nis an owner of Copyright and Related Rights in the Work, voluntarily\nelects to apply CC0 to the Work and publicly distribute the Work under its\nterms, with knowledge of his or her Copyright and Related Rights in the\nWork and the meaning and intended legal effect of CC0 on those rights.\n\n1. Copyright and Related Rights. A Work made available under CC0 may be\nprotected by copyright and related or neighboring rights (\"Copyright and\nRelated Rights\"). Copyright and Related Rights include, but are not\nlimited to, the following:\n\n i. the right to reproduce, adapt, distribute, perform, display,\n communicate, and translate a Work;\n ii. moral rights retained by the original author(s) and/or performer(s);\niii. publicity and privacy rights pertaining to a person's image or\n likeness depicted in a Work;\n iv. rights protecting against unfair competition in regards to a Work,\n subject to the limitations in paragraph 4(a), below;\n v. rights protecting the extraction, dissemination, use and reuse of data\n in a Work;\n vi. database rights (such as those arising under Directive 96/9/EC of the\n European Parliament and of the Council of 11 March 1996 on the legal\n protection of databases, and under any national implementation\n thereof, including any amended or successor version of such\n directive); and\nvii. other similar, equivalent or corresponding rights throughout the\n world based on applicable law or treaty, and any national\n implementations thereof.\n\n2. Waiver. To the greatest extent permitted by, but not in contravention\nof, applicable law, Affirmer hereby overtly, fully, permanently,\nirrevocably and unconditionally waives, abandons, and surrenders all of\nAffirmer's Copyright and Related Rights and associated claims and causes\nof action, whether now known or unknown (including existing as well as\nfuture claims and causes of action), in the Work (i) in all territories\nworldwide, (ii) for the maximum duration provided by applicable law or\ntreaty (including future time extensions), (iii) in any current or future\nmedium and for any number of copies, and (iv) for any purpose whatsoever,\nincluding without limitation commercial, advertising or promotional\npurposes (the \"Waiver\"). Affirmer makes the Waiver for the benefit of each\nmember of the public at large and to the detriment of Affirmer's heirs and\nsuccessors, fully intending that such Waiver shall not be subject to\nrevocation, rescission, cancellation, termination, or any other legal or\nequitable action to disrupt the quiet enjoyment of the Work by the public\nas contemplated by Affirmer's express Statement of Purpose.\n\n3. Public License Fallback. Should any part of the Waiver for any reason\nbe judged legally invalid or ineffective under applicable law, then the\nWaiver shall be preserved to the maximum extent permitted taking into\naccount Affirmer's express Statement of Purpose. In addition, to the\nextent the Waiver is so judged Affirmer hereby grants to each affected\nperson a royalty-free, non transferable, non sublicensable, non exclusive,\nirrevocable and unconditional license to exercise Affirmer's Copyright and\nRelated Rights in the Work (i) in all territories worldwide, (ii) for the\nmaximum duration provided by applicable law or treaty (including future\ntime extensions), (iii) in any current or future medium and for any number\nof copies, and (iv) for any purpose whatsoever, including without\nlimitation commercial, advertising or promotional purposes (the\n\"License\"). The License shall be deemed effective as of the date CC0 was\napplied by Affirmer to the Work. Should any part of the License for any\nreason be judged legally invalid or ineffective under applicable law, such\npartial invalidity or ineffectiveness shall not invalidate the remainder\nof the License, and in such case Affirmer hereby affirms that he or she\nwill not (i) exercise any of his or her remaining Copyright and Related\nRights in the Work or (ii) assert any associated claims and causes of\naction with respect to the Work, in either case contrary to Affirmer's\nexpress Statement of Purpose.\n\n4. Limitations and Disclaimers.\n\n a. No trademark or patent rights held by Affirmer are waived, abandoned,\n surrendered, licensed or otherwise affected by this document.\n b. Affirmer offers the Work as-is and makes no representations or\n warranties of any kind concerning the Work, express, implied,\n statutory or otherwise, including without limitation warranties of\n title, merchantability, fitness for a particular purpose, non\n infringement, or the absence of latent or other defects, accuracy, or\n the present or absence of errors, whether or not discoverable, all to\n the greatest extent permissible under applicable law.\n c. Affirmer disclaims responsibility for clearing rights of other persons\n that may apply to the Work or any use thereof, including without\n limitation any person's Copyright and Related Rights in the Work.\n Further, Affirmer disclaims responsibility for obtaining any necessary\n consents, permissions or other rights required for any use of the\n Work.\n d. Affirmer understands and acknowledges that Creative Commons is not a\n party to this document and has no duty or obligation with respect to\n this CC0 or use of the Work.\n", "sha256-f1d9dc9f2f4edaaebd9167eb8b79a6da6434313df47921aa4ea8ae278f7739e3": "/**\n * Haketilo demo script.\n *\n * Copyright (C) 2021 Wojtek Kosior\n * Available under the terms of Creative Commons Zero\n * \n */\n\n{\n const banner = document.createElement(\"h2\");\n \n banner.textContent = \"Hoooray! Haketilo works :D\";\n \n banner.setAttribute(\"style\", `\\\n margin: 1em; \\\n border-radius: 1em 0px; \\\n background-color: #474; \\\n padding: 10px 20px; \\\n color: #eee; \\\n box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19); \\\n display: inline-block;\\\n `);\n \n document.body.prepend(banner);\n}\n" } - } + }, + "repo": ["https://hydrilla.koszko.org/api_v1"] } diff --git a/html/default_blocking_policy.js b/html/default_blocking_policy.js index b0577f7..edac02d 100644 --- a/html/default_blocking_policy.js +++ b/html/default_blocking_policy.js @@ -66,7 +66,7 @@ function update_policy(change) async function track_default_allow() { const set_val = ch => default_allow = (ch.new_val || {}).value; - const [tracking, settings] = await haketilodb.track.settings(update_policy); + const [tracking, settings] = await haketilodb.track.setting(update_policy); for (const setting of settings) { if (setting.name === "default_allow") default_allow = setting.value; diff --git a/html/file_preview.js b/html/file_preview.js index 3e22225..be54201 100644 --- a/html/file_preview.js +++ b/html/file_preview.js @@ -55,8 +55,8 @@ function error(msg) { async function show_preview(hash_key) { const db = await haketilodb.get(); - const file = await haketilodb.idb_get(db.transaction("files"), - "files", hash_key); + const file = await haketilodb.idb_get(db.transaction("file"), + "file", hash_key); if (file === undefined) { error("Couldn't find file in Haketilo's internal database :("); } else { diff --git a/html/install.js b/html/install.js index df63626..2a72662 100644 --- a/html/install.js +++ b/html/install.js @@ -382,15 +382,14 @@ function InstallView(tab_id, on_view_show, on_view_hide) { if (files !== undefined) { const data = {file: {sha256: files}}; - const names = [["mappings", "mapping"], ["resources", "resource"]]; - for (const [set_name, type] of names) { + for (const type of ["resource", "mapping"]) { const set = {}; for (const def of item_defs.filter(def => def.type === type)) set[def.identifier] = {[version_string(def.version)]: def}; - data[set_name] = set; + data[type] = set; } try { diff --git a/html/text_entry_list.js b/html/text_entry_list.js index 0ea2862..80895c9 100644 --- a/html/text_entry_list.js +++ b/html/text_entry_list.js @@ -311,7 +311,7 @@ async function repo_list(dialog_ctx) { } dialog.loader(dialog_ctx, "Loading repositories..."); - const [tracking, items] = await haketilodb.track.repos(onchange); + const [tracking, items] = await haketilodb.track.repo(onchange); dialog.close(dialog_ctx); list = new TextEntryList(dialog_ctx, () => haketilodb.untrack(tracking), diff --git a/test/unit/test_indexeddb.py b/test/unit/test_indexeddb.py index 9041116..9f31480 100644 --- a/test/unit/test_indexeddb.py +++ b/test/unit/test_indexeddb.py @@ -77,15 +77,15 @@ def test_haketilodb_item_modifications(driver, execute_in_page): database_contents = get_db_contents(execute_in_page) - assert len(database_contents['files']) == 4 + assert len(database_contents['file']) == 4 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']]) + for file in database_contents['file']]) + assert all([len(file) == 2 for file in database_contents['file']]) assert len(database_contents['file_uses']) == 4 assert all([uses['uses'] == 1 for uses in database_contents['file_uses']]) assert set([uses['sha256'] for uses in database_contents['file_uses']]) \ - == set([file['sha256'] for file in database_contents['files']]) + == set([file['sha256'] for file in database_contents['file']]) assert database_contents['mapping'] == [] assert database_contents['resource'] == [sample_item] @@ -147,7 +147,7 @@ def test_haketilodb_item_modifications(driver, execute_in_page): for file, nr in zip(sample_files_list, uses_list)]) files = dict([(file['sha256'], file['contents']) - for file in database_contents['files']]) + for file in database_contents['file']]) assert files == dict([(file['sha256'], file['contents']) for file in sample_files_list]) @@ -179,7 +179,7 @@ def test_haketilodb_item_modifications(driver, execute_in_page): assert uses == dict([(file['sha256'], 1) for file in sample_files_list]) files = dict([(file['sha256'], file['contents']) - for file in results[0]['files']]) + for file in results[0]['file']]) assert files == dict([(file['sha256'], file['contents']) for file in sample_files_list]) @@ -192,7 +192,7 @@ def test_haketilodb_item_modifications(driver, execute_in_page): sample_resource = make_sample_resource() sample_mapping = make_sample_mapping() initial_data = { - 'resources': { + 'resource': { 'helloapple': { '1.12': sample_resource, '0.9': 'something_that_should_get_ignored', @@ -201,7 +201,7 @@ def test_haketilodb_item_modifications(driver, execute_in_page): '1.11.1': 'something_that_should_get_ignored', } }, - 'mappings': { + 'mapping': { 'helloapple': { '0.1.1': sample_mapping } @@ -222,7 +222,7 @@ def test_haketilodb_item_modifications(driver, execute_in_page): def test_haketilodb_settings(driver, execute_in_page): """ indexeddb.js facilitates operating on Haketilo's internal database. - Verify assigning/retrieving values of simple "settings" item works properly. + Verify assigning/retrieving values of simple "setting" item works properly. """ execute_in_page(load_script('common/indexeddb.js')) mock_broadcast(execute_in_page) @@ -230,7 +230,7 @@ def test_haketilodb_settings(driver, execute_in_page): # Start with no database. clear_indexeddb(execute_in_page) - assert get_db_contents(execute_in_page)['settings'] == [] + assert get_db_contents(execute_in_page)['setting'] == [] assert execute_in_page('returnval(get_setting("option15"));') == None @@ -280,7 +280,7 @@ def test_haketilodb_repos(driver, execute_in_page): # Start with no database. clear_indexeddb(execute_in_page) - assert get_db_contents(execute_in_page)['repos'] == [] + assert get_db_contents(execute_in_page)['repo'] == [] sample_urls = ['https://hdrlla.example.com/', 'https://hdrlla.example.org'] @@ -342,12 +342,12 @@ def test_haketilodb_track(driver, execute_in_page, wait_elem_text): sample_resource = make_sample_resource() sample_mapping = make_sample_mapping() initial_data = { - 'resources': { + 'resource': { 'helloapple': { '1.0': sample_resource } }, - 'mappings': { + 'mapping': { 'helloapple': { '0.1.1': sample_mapping } @@ -404,8 +404,8 @@ def test_haketilodb_track(driver, execute_in_page, wait_elem_text): for elem_id, json_value in [ ('resource_helloapple', sample_resource), ('mapping_helloapple', sample_mapping), - ('settings_option15', {'name': 'option15', 'value': '123'}), - ('repos_https://hydril.la', {'url': 'https://hydril.la'}), + ('setting_option15', {'name': 'option15', 'value': '123'}), + ('repo_https://hydril.la', {'url': 'https://hydril.la'}), ('blocking_file:///*', {'pattern': 'file:///*', 'allow': False}) ]: assert json.loads(driver.find_element_by_id(elem_id).text) == json_value @@ -417,12 +417,12 @@ def test_haketilodb_track(driver, execute_in_page, wait_elem_text): sample_mapping2 = make_sample_mapping() sample_mapping2['identifier'] = 'helloapple-copy' sample_data = { - 'resources': { + 'resource': { 'helloapple-copy': { '1.0': sample_resource2 } }, - 'mappings': { + 'mapping': { 'helloapple-copy': { '0.1.1': sample_mapping2 } @@ -441,8 +441,8 @@ def test_haketilodb_track(driver, execute_in_page, wait_elem_text): for elem_id, json_value in [ ('resource_helloapple-copy', sample_resource2), ('mapping_helloapple-copy', sample_mapping2), - ('settings_option22', {'name': 'option22', 'value': 'abc'}), - ('repos_https://hydril2.la', {'url': 'https://hydril2.la'}), + ('setting_option22', {'name': 'option22', 'value': 'abc'}), + ('repo_https://hydril2.la', {'url': 'https://hydril2.la'}), ('blocking_ftp://a.bc/', {'pattern': 'ftp://a.bc/', 'allow': True}) ]: assert json.loads(driver.find_element_by_id(elem_id).text) == json_value @@ -468,7 +468,7 @@ def test_haketilodb_track(driver, execute_in_page, wait_elem_text): }''') removed_ids = ['mapping_helloapple-copy', 'resource_helloapple', - 'repos_https://hydril.la', 'blocking_file:///*'] + 'repo_https://hydril.la', 'blocking_file:///*'] def condition_items_absent_and_changed(driver): for id in removed_ids: try: @@ -477,7 +477,7 @@ def test_haketilodb_track(driver, execute_in_page, wait_elem_text): except WebDriverException: pass - option_text = driver.find_element_by_id('settings_option22').text + option_text = driver.find_element_by_id('setting_option22').text blocking_text = driver.find_element_by_id('blocking_ftp://a.bc/').text return (json.loads(option_text)['value'] == None and json.loads(blocking_text)['allow'] == False) diff --git a/test/unit/test_indexeddb_files_server.py b/test/unit/test_indexeddb_files_server.py index d320eba..6ddfba8 100644 --- a/test/unit/test_indexeddb_files_server.py +++ b/test/unit/test_indexeddb_files_server.py @@ -51,7 +51,7 @@ def make_sample_resource_with_deps(n): resources = [make_sample_resource_with_deps(n) for n in range(count)] sample_data = { - 'resources': sample_data_dict(resources), + 'resource': sample_data_dict(resources), 'mapping': {}, 'file': { 'sha256': sample_files_by_sha256 @@ -91,7 +91,7 @@ def test_indexeddb_files_server_normal_usage(driver, execute_in_page): function_returned_value = execute_in_page( ''' returnval(registered_listener(["???"], {}, - () => location.reload())); + () => location.reload())); ''') assert function_returned_value == None @@ -138,9 +138,9 @@ def test_indexeddb_files_server_errors(driver, execute_in_page, error): sample_data_copy = copy.deepcopy(sample_data) if error == 'missing': - del sample_data_copy['resources']['res-3'] + del sample_data_copy['resource']['res-3'] elif error == 'circular': - res3_defs = sample_data_copy['resources']['res-3'].values() + res3_defs = sample_data_copy['resource']['res-3'].values() next(iter(res3_defs))['dependencies'].append({'identifier': 'res-8'}) prepare_test_page(sample_data_copy, execute_in_page) diff --git a/test/unit/test_install.py b/test/unit/test_install.py index 303d31a..cef2aa6 100644 --- a/test/unit/test_install.py +++ b/test/unit/test_install.py @@ -150,7 +150,7 @@ def test_install_normal_usage(driver, execute_in_page, complex_variant): assert set([it['identifier'] for it in db_contents[item_type]]) == ids assert all([len(db_contents[store]) == files_count - for store in ('files', 'file_uses')]) + for store in ('file', 'file_uses')]) # Update the installed mapping to a newer version. execute_in_page('returnval(install_view.show(...arguments));', diff --git a/test/unit/test_item_list.py b/test/unit/test_item_list.py index 189646e..35ed1d5 100644 --- a/test/unit/test_item_list.py +++ b/test/unit/test_item_list.py @@ -104,8 +104,8 @@ def test_item_list_ordering(driver, execute_in_page, item_type): items.reverse() sample_data = { - 'resources': {}, - 'mappings': {}, + 'resource': {}, + 'mapping': {}, 'file': { 'sha256': sample_files_by_sha256 } @@ -127,12 +127,12 @@ def test_item_list_ordering(driver, execute_in_page, item_type): it['long_name'] = f'somewhat renamed {it["long_name"]}' items_to_inclue = [items[i] for i in sorted(to_include)] - sample_data[item_type + 's'] = sample_data_dict(items_to_inclue) + sample_data[item_type] = sample_data_dict(items_to_inclue) execute_in_page('returnval(haketilodb.save_items(arguments[0]));', sample_data) extra_item['long_name'] = f'{iteration} {extra_item["long_name"]}' - sample_data[item_type + 's'] = sample_data_dict([extra_item]) + sample_data[item_type] = sample_data_dict([extra_item]) execute_in_page('returnval(haketilodb.save_items(arguments[0]));', sample_data) @@ -189,13 +189,13 @@ def test_item_list_displaying(driver, execute_in_page, item_type): items = [make_item(item_type, f'item{i}', f'Item {i}') for i in range(3)] sample_data = { - 'resources': {}, - 'mappings': {}, + 'resource': {}, + 'mapping': {}, 'file': { 'sha256': sample_files_by_sha256 } } - sample_data[item_type + 's'] = sample_data_dict(items) + sample_data[item_type] = sample_data_dict(items) preview_container, dialog_container, ul = execute_in_page( f''' diff --git a/test/unit/test_item_preview.py b/test/unit/test_item_preview.py index c715d75..fe9a98e 100644 --- a/test/unit/test_item_preview.py +++ b/test/unit/test_item_preview.py @@ -154,7 +154,7 @@ def test_file_preview_link(driver, execute_in_page): execute_in_page(load_script('html/item_preview.js')) sample_data = make_complete_sample_data() - sample_data['mappings'] = {} + sample_data['mapping'] = {} execute_in_page('returnval(haketilodb.save_items(arguments[0]));', sample_data) diff --git a/test/unit/test_patterns_query_manager.py b/test/unit/test_patterns_query_manager.py index 13d0add..9fbc438 100644 --- a/test/unit/test_patterns_query_manager.py +++ b/test/unit/test_patterns_query_manager.py @@ -105,7 +105,7 @@ def test_pqm_tree_building(driver, execute_in_page): return [{}, initial_blocking]; } - haketilodb.track.settings = function (cb) { + haketilodb.track.setting = function (cb) { settingchange = cb; return [{}, [{name: "default_allow", value: true}]]; @@ -271,10 +271,10 @@ def test_pqm_script_injection(driver, execute_in_page): execute_in_page(load_script('common/indexeddb.js')) sample_data = { - 'mappings': dict([(sm['identifier'], {'1.0': sm}) - for sm in sample_mappings]), - 'resources': {}, - 'files': {} + 'mapping': dict([(sm['identifier'], {'1.0': sm}) + for sm in sample_mappings]), + 'resource': {}, + 'file': {} } execute_in_page('returnval(save_items(arguments[0]));', sample_data) diff --git a/test/unit/utils.py b/test/unit/utils.py index 04a4d97..6ff04ed 100644 --- a/test/unit/utils.py +++ b/test/unit/utils.py @@ -149,8 +149,8 @@ def make_complete_sample_data(): be used to populate IndexedDB. """ return { - 'resources': sample_data_dict([make_sample_resource()]), - 'mappings': sample_data_dict([make_sample_mapping()]), + 'resource': sample_data_dict([make_sample_resource()]), + 'mapping': sample_data_dict([make_sample_mapping()]), 'file': { 'sha256': sample_files_by_sha256 } -- cgit v1.2.3