aboutsummaryrefslogtreecommitdiff
path: root/test/unit/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/utils.py')
-rw-r--r--test/unit/utils.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/test/unit/utils.py b/test/unit/utils.py
index 6abb879..96ebf60 100644
--- a/test/unit/utils.py
+++ b/test/unit/utils.py
@@ -27,6 +27,8 @@ Various functions and objects that can be reused between unit tests
from hashlib import sha256
+from ..script_loader import load_script
+
patterns_doc_url = \
'https://hydrillabugs.koszko.org/projects/haketilo/wiki/URL_patterns'
@@ -55,6 +57,50 @@ sample_files_by_hash = dict([[file['hash_key'], file['contents']]
def sample_file_ref(file_name):
return {'file': file_name, 'hash_key': sample_files[file_name]['hash_key']}
+def make_sample_mapping():
+ return {
+ 'source_name': 'example-org-fixes-new',
+ 'source_copyright': [
+ sample_file_ref('report.spdx'),
+ sample_file_ref('LICENSES/CC0-1.0.txt')
+ ],
+ 'type': 'mapping',
+ 'identifier': 'example-org-minimal',
+ 'long_name': 'Example.org Minimal',
+ 'uuid': '54d23bba-472e-42f5-9194-eaa24c0e3ee7',
+ 'version': [2022, 5, 10],
+ 'description': 'suckless something something',
+ 'payloads': {
+ 'https://example.org/a/*': {
+ 'identifier': 'some-KISS-resource'
+ },
+ 'https://example.org/t/*': {
+ 'identifier': 'another-KISS-resource'
+ }
+ }
+ }
+
+def make_sample_resource():
+ return {
+ 'source_name': 'hello',
+ 'source_copyright': [
+ sample_file_ref('report.spdx'),
+ sample_file_ref('LICENSES/CC0-1.0.txt')
+ ],
+ 'type': 'resource',
+ 'identifier': 'helloapple',
+ 'long_name': 'Hello Apple',
+ 'uuid': 'a6754dcb-58d8-4b7a-a245-24fd7ad4cd68',
+ 'version': [2021, 11, 10],
+ 'revision': 1,
+ 'description': 'greets an apple',
+ 'dependencies': ['hello-message'],
+ 'scripts': [
+ sample_file_ref('hello.js'),
+ sample_file_ref('bye.js')
+ ]
+ }
+
def item_version_string(definition, include_revision=False):
"""
Given a resource or mapping definition, read its "version" property (and
@@ -73,6 +119,17 @@ def sample_data_dict(items):
return dict([(it['identifier'], {item_version_string(it): it})
for it in items])
+def make_complete_sample_data():
+ """
+ Craft a JSON data item with 1 sample resource and 1 sample mapping that can
+ be used to populate IndexedDB.
+ """
+ return {
+ 'resources': sample_data_dict([make_sample_resource()]),
+ 'mappings': sample_data_dict([make_sample_mapping()]),
+ 'files': sample_files_by_hash
+ }
+
def clear_indexeddb(execute_in_page):
"""
Remove Haketilo data from IndexedDB. If variables from common/indexeddb.js
@@ -128,3 +185,5 @@ def get_db_contents(execute_in_page):
def is_prime(n):
return n > 1 and all([n % i != 0 for i in range(2, n)])
+
+broker_js = lambda: load_script('background/broadcast_broker.js') + ';start();'