summaryrefslogtreecommitdiff
path: root/test/unit/test_indexeddb.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/test_indexeddb.py')
-rw-r--r--test/unit/test_indexeddb.py36
1 files changed, 7 insertions, 29 deletions
diff --git a/test/unit/test_indexeddb.py b/test/unit/test_indexeddb.py
index 447ee6e..9dfbe63 100644
--- a/test/unit/test_indexeddb.py
+++ b/test/unit/test_indexeddb.py
@@ -19,62 +19,41 @@ Haketilo unit tests - IndexedDB access
import pytest
import json
-from hashlib import sha256
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import WebDriverException
from ..script_loader import load_script
+from .utils import sample_files, sample_files_by_hash, sample_file_ref
indexeddb_js = lambda: load_script('common/indexeddb.js')
broker_js = lambda: load_script('background/broadcast_broker.js') + ';start();'
-def sample_file(contents):
- return {
- 'hash_key': f'sha256-{sha256(contents.encode()).digest().hex()}',
- 'contents': contents
- }
-
-sample_files = {
- 'report.spdx': sample_file('<!-- dummy report -->'),
- 'LICENSES/somelicense.txt': sample_file('Permission is granted...'),
- 'hello.js': sample_file('console.log("hello!");\n'),
- 'bye.js': sample_file('console.log("bye!");\n'),
- 'combined.js': sample_file('console.log("hello!\\nbye!");\n'),
- 'README.md': sample_file('# Python Frobnicator\n...')
-}
-
-sample_files_by_hash = dict([[file['hash_key'], file['contents']]
- for file in sample_files.values()])
-
# Sample resource definitions. They'd normally contain more fields but here we
# use simplified versions.
def make_sample_resource():
return {
'source_copyright': [
- file_ref('report.spdx'),
- file_ref('LICENSES/somelicense.txt')
+ sample_file_ref('report.spdx'),
+ sample_file_ref('LICENSES/somelicense.txt')
],
'type': 'resource',
'identifier': 'helloapple',
- 'scripts': [file_ref('hello.js'), file_ref('bye.js')]
+ 'scripts': [sample_file_ref('hello.js'), sample_file_ref('bye.js')]
}
def make_sample_mapping():
return {
'source_copyright': [
- file_ref('report.spdx'),
- file_ref('README.md')
+ sample_file_ref('report.spdx'),
+ sample_file_ref('README.md')
],
'type': 'mapping',
'identifier': 'helloapple'
}
-def file_ref(file_name):
- return {'file': file_name, 'hash_key': sample_files[file_name]['hash_key']}
-
def clear_indexeddb(execute_in_page):
execute_in_page(
'''{
@@ -168,7 +147,7 @@ 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(file_ref('combined.js'))
+ sample_item['scripts'].append(sample_file_ref('combined.js'))
incomplete_files = {**sample_files_by_hash}
incomplete_files.pop(sample_files['combined.js']['hash_key'])
exception = execute_in_page(
@@ -439,7 +418,6 @@ def test_haketilodb_track(driver, execute_in_page, wait_elem_text):
'''
function update_item(store_name, change)
{
- console.log('# update', ...arguments);
const elem_id = `${store_name}_${change.key}`;
let elem = document.getElementById(elem_id);
elem = elem || document.createElement("li");