summaryrefslogtreecommitdiff
path: root/src/test/test_pydrilla.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/test_pydrilla.py')
-rw-r--r--src/test/test_pydrilla.py17
1 files changed, 17 insertions, 0 deletions
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