aboutsummaryrefslogtreecommitdiff
path: root/test/unit/test_item_preview.py
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-02-16 22:01:38 +0100
committerWojtek Kosior <koszko@koszko.org>2022-02-16 22:01:38 +0100
commitfd9f2fc4783cc606734e61116185c032a63d54a0 (patch)
treeddc162b1df608c3ae51d74f19fbffc92e5cfc3e3 /test/unit/test_item_preview.py
parent7965f1b455144220c137bcb25c4967283a6b7ff3 (diff)
downloadbrowser-extension-fd9f2fc4783cc606734e61116185c032a63d54a0.tar.gz
browser-extension-fd9f2fc4783cc606734e61116185c032a63d54a0.zip
fix out-of-source builds
Diffstat (limited to 'test/unit/test_item_preview.py')
-rw-r--r--test/unit/test_item_preview.py208
1 files changed, 0 insertions, 208 deletions
diff --git a/test/unit/test_item_preview.py b/test/unit/test_item_preview.py
deleted file mode 100644
index fe9a98e..0000000
--- a/test/unit/test_item_preview.py
+++ /dev/null
@@ -1,208 +0,0 @@
-# SPDX-License-Identifier: CC0-1.0
-
-"""
-Haketilo unit tests - displaying resources and mappings details
-"""
-
-# This file is part of Haketilo
-#
-# Copyright (C) 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
-# the Creative Commons Corporation.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# CC0 1.0 Universal License for more details.
-
-import pytest
-from selenium.webdriver.support.ui import WebDriverWait
-from selenium.common.exceptions import NoSuchWindowException
-
-from ..extension_crafting import ExtraHTML
-from ..script_loader import load_script
-from .utils import *
-
-@pytest.mark.ext_data({
- 'extra_html': ExtraHTML('html/item_preview.html', {}),
- 'navigate_to': 'html/item_preview.html'
-})
-@pytest.mark.usefixtures('webextension')
-def test_resource_preview(driver, execute_in_page):
- """
- A test case of the resource preview display function.
- """
- execute_in_page(load_script('html/item_preview.js'))
-
- sample_resource = make_sample_resource()
-
- preview_div = execute_in_page(
- '''
- let preview_object = resource_preview(arguments[0]);
- document.body.append(preview_object.main_div);
- returnval(preview_object.main_div);
- ''',
- sample_resource)
- text = preview_div.text
-
- assert '...' not in text
-
- for string in [
- *filter(lambda v: type(v) is str, sample_resource.values()),
- *[rr['identifier'] for rr in sample_resource['dependencies']],
- *[c['file'] for k in ('source_copyright', 'scripts')
- for c in sample_resource[k]],
- item_version_string(sample_resource, True)
- ]:
- assert string in text
-
- sample_resource['identifier'] = 'hellopear'
- sample_resource['long_name'] = 'Hello Pear'
- sample_resource['description'] = 'greets a pear'
- sample_resource['dependencies'] = [{'identifier': 'hello-msg'}]
- for key in ('scripts', 'source_copyright'):
- for file_ref in sample_resource[key]:
- file_ref['file'] = file_ref['file'].replace('.', '_')
-
- preview_div = execute_in_page(
- '''
- returnval(resource_preview(arguments[0], preview_object).main_div);
- ''',
- sample_resource)
- text = preview_div.text
-
- for string in ['...', 'pple', 'hello-message', 'report.spdx',
- 'LICENSES/CC0-1.0.txt', 'hello.js', 'bye.js']:
- assert string not in text
-
- for string in ['hellopear', 'Hello Pear', 'hello-msg', 'greets a pear',
- 'report_spdx', 'LICENSES/CC0-1_0_txt', 'hello_js', 'bye_js']:
- assert string in text
-
-@pytest.mark.ext_data({
- 'extra_html': ExtraHTML('html/item_preview.html', {}),
- 'navigate_to': 'html/item_preview.html'
-})
-@pytest.mark.usefixtures('webextension')
-def test_mapping_preview(driver, execute_in_page):
- """
- A test case of the mapping preview display function.
- """
- execute_in_page(load_script('html/item_preview.js'))
-
- sample_mapping = make_sample_mapping()
-
- preview_div = execute_in_page(
- '''
- let preview_object = mapping_preview(arguments[0]);
- document.body.append(preview_object.main_div);
- returnval(preview_object.main_div);
- ''',
- sample_mapping)
- text = preview_div.text
-
- assert '...' not in text
-
- for string in [
- *filter(lambda v: type(v) is str, sample_mapping.values()),
- *[p['identifier'] for p in sample_mapping['payloads'].values()],
- *[c['file'] for c in sample_mapping['source_copyright']],
- item_version_string(sample_mapping)
- ]:
- assert string in text
-
- sample_mapping['identifier'] = 'example-org-bloated'
- sample_mapping['long_name'] = 'Example.org Bloated',
- sample_mapping['payloads'] = dict(
- [(pat.replace('.org', '.com'), res_id)
- for pat, res_id in sample_mapping['payloads'].items()]
- )
- for file_ref in sample_mapping['source_copyright']:
- file_ref['file'] = file_ref['file'].replace('.', '_')
-
- preview_div = execute_in_page(
- '''
- returnval(mapping_preview(arguments[0], preview_object).main_div);
- ''',
- sample_mapping)
- text = preview_div.text
-
- for string in ['...', 'inimal', 'example.org', 'report.spdx',
- 'LICENSES/CC0-1.0.txt']:
- assert string not in text
-
- for string in ['example-org-bloated', 'Example.org Bloated', 'example.com',
- 'report_spdx', 'LICENSES/CC0-1_0_txt']:
- assert string in text
-
-@pytest.mark.ext_data({
- 'background_script': broker_js,
- 'extra_html': [
- ExtraHTML('html/item_preview.html', {}),
- ExtraHTML('html/file_preview.html', {}, wrap_into_htmldoc=False)
- ],
- 'navigate_to': 'html/item_preview.html'
-})
-@pytest.mark.usefixtures('webextension')
-def test_file_preview_link(driver, execute_in_page):
- """
- A test case of <a> links created by preview functions that allow a
- referenced file to be previewed.
- """
- execute_in_page(load_script('html/item_preview.js'))
-
- sample_data = make_complete_sample_data()
- sample_data['mapping'] = {}
- execute_in_page('returnval(haketilodb.save_items(arguments[0]));',
- sample_data)
-
- # Cause the "link" to `bye.js` to be invalid.
- sample_resource = make_sample_resource()
- sample_resource['scripts'][1]['sha256'] = 'dummy nonexistent hash'
-
- execute_in_page(
- '''
- let resource_preview_object = resource_preview(arguments[0], undefined);
- document.body.append(resource_preview_object.main_div);
- ''',
- sample_resource)
-
- window0 = driver.window_handles[0]
- driver.find_element_by_link_text('hello.js').click()
-
- def blob_url_navigated(driver):
- if len(driver.window_handles) < 2:
- return
- window1 = [wh for wh in driver.window_handles if wh != window0][0]
- driver.switch_to.window(window1)
- try:
- return driver.current_url.startswith('blob')
- except NoSuchWindowException:
- pass
-
- WebDriverWait(driver, 10).until(blob_url_navigated)
-
- assert sample_files['hello.js']['contents'].strip() \
- in driver.find_element_by_tag_name("pre").text
-
- driver.close()
- driver.switch_to.window(window0)
-
- driver.find_element_by_link_text('bye.js').click()
-
- def get_error_span(driver):
- if len(driver.window_handles) < 2:
- return
- window1 = [wh for wh in driver.window_handles if wh != window0][0]
- driver.switch_to.window(window1)
- try:
- return driver.find_element_by_id('error_msg')
- except NoSuchWindowException:
- pass
-
- error_span = WebDriverWait(driver, 10).until(get_error_span)
- assert error_span.is_displayed()
- assert "Couldn't find file in Haketilo's internal database :(" \
- in error_span.text