summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/example_content/hello/index.json21
-rw-r--r--src/test/test_pydrilla.py17
2 files changed, 29 insertions, 9 deletions
diff --git a/src/test/example_content/hello/index.json b/src/test/example_content/hello/index.json
index 12105c2..16843cb 100644
--- a/src/test/example_content/hello/index.json
+++ b/src/test/example_content/hello/index.json
@@ -150,8 +150,9 @@
// Array of javascript files that belong to this resource.
"scripts": [
{
- // Script name. It should also be a valid file path.
- "name": "hello.js",
+ // Script name. It should also be a valid file path relative
+ // to index.json's containing directory.
+ "file": "hello.js",
// Copyright and license info of a script file can be
// specified using the same format as in the case of the
// index.json file itself. If "copyright" or "license" is
@@ -160,7 +161,7 @@
"copyright": "auto",
"licenses": "auto"
}, {
- "name": "bye.js"
+ "file": "bye.js"
}
]
}, {
@@ -175,7 +176,7 @@
"licenses": "CC0-1.0",
// If "dependencies" is empty, it can also be omitted.
// "dependencies": [],
- "scripts": [{"name": "message.js"}]
+ "scripts": [{"file": "message.js"}]
}, {
"type": "mapping",
@@ -262,14 +263,16 @@
//
// "comment": "Expat license is the most common form of the license often called \"MIT\". Many other forms of \"MIT\" license exist. Here the name \"Expat\" is used to avoid ambiguity."
- // If applicable, a "notice" can be included. It shall then be a
- // path (relative to index.json) to a plain text file with that
- // notice.
+ // If applicable, a "notice" can be included. It shall then be an
+ // object with "file" field containing a path (relative to
+ // index.json's directory) to a plain text file with that notice.
//
- // "notice": "license-notice.txt"
+ // "notice": {
+ // "file": "license-notice.txt"
+ // }
//
// This is needed for example in case of GNU licenses (both with and
- // without exceptions). For example,
+ // without exceptions). For instance,
// "GPL-3.0-or-later-with-html-exception" could have the following
// in its notice file:
//
diff --git a/src/test/test_pydrilla.py b/src/test/test_pydrilla.py
index 22022ae..50757a7 100644
--- a/src/test/test_pydrilla.py
+++ b/src/test/test_pydrilla.py
@@ -28,6 +28,7 @@ import pytest
import sys
import shutil
from pathlib import Path
+from hashlib import sha256
from os import mkdir, unlink, environ
import json
from markupsafe import escape
@@ -37,6 +38,7 @@ from pydrilla import pydrilla, create_app
test_dir = Path(__file__).resolve().parent
packages_dir = test_dir.parent
development_config_path = test_dir / 'development_config.json'
+example_content_dir = test_dir / 'example_content'
@pytest.fixture
def client():
@@ -51,6 +53,11 @@ def development_config():
yield json.loads(pydrilla.strip_json_comments(config_file.read()))
def test_api_basic(client, development_config):
+ def verify_sha256sum(source_name, file_object):
+ with open(example_content_dir / source_name / file_object['file'],
+ mode='rb') as file:
+ assert sha256(file.read()).digest().hex() == file_object['sha256']
+
response = client.get('/')
assert b'html' in response.data
sources_uri = development_config['hydrilla_sources_uri']
@@ -63,6 +70,11 @@ def test_api_basic(client, development_config):
assert definition['type'] == item_type
assert definition['source_name'] == 'hello'
assert definition['version'] == [2021, 11, 10]
+ if item_type == 'resource':
+ assert type(definition['scripts']) is list
+ assert len(definition['scripts']) > 0
+ for script_file in definition['scripts']:
+ verify_sha256sum(definition['source_name'], script_file)
response = client.get(f'/{item_type}s/helloapple?ver=2021.11.10.0')
assert response.status_code == 200
@@ -91,6 +103,11 @@ def test_api_basic(client, development_config):
assert definition['long_name'] == 'Creative Commons Zero v1.0 Universal'
assert definition['source_name'] == 'hello'
+ assert type(definition['legal_text']) is list
+ assert len(definition['legal_text']) > 0
+ for license_file in definition['legal_text']:
+ verify_sha256sum(definition['source_name'], license_file)
+
response = client.get('/licenses/random-bad-identifier')
assert response.status_code == 404