aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-05-31 18:25:18 +0200
committerWojtek Kosior <koszko@koszko.org>2022-05-31 18:25:18 +0200
commit9dcbfdfe8620cc417438d1727aa1e0c89846e9bf (patch)
tree9d93c401bff22799aff9b02afab89715fe55f74a /tests
parent2290975f9e867938116bf1e4d21f83eb073eb906 (diff)
downloadhaketilo-hydrilla-9dcbfdfe8620cc417438d1727aa1e0c89846e9bf.tar.gz
haketilo-hydrilla-9dcbfdfe8620cc417438d1727aa1e0c89846e9bf.zip
update to schema version 2 and hydrilla builder version 1.1-beta1
Diffstat (limited to 'tests')
m---------tests/source-package-example0
-rw-r--r--tests/test_server.py47
2 files changed, 36 insertions, 11 deletions
diff --git a/tests/source-package-example b/tests/source-package-example
-Subproject 92a4d31c659b2336e5e188877d1ce6bfad2fa31
+Subproject 48a440fd1e13814f2adaa8a115baaf47e4c38c3
diff --git a/tests/test_server.py b/tests/test_server.py
index 0820d5c..02b9742 100644
--- a/tests/test_server.py
+++ b/tests/test_server.py
@@ -31,6 +31,7 @@ import pytest
import sys
import shutil
import json
+import functools as ft
from pathlib import Path
from hashlib import sha256
@@ -119,22 +120,46 @@ class Setup:
return self._client
-def remove_all_uuids(setup: Setup) -> None:
- """Modify sample packages before build to contain no (optional) UUIDs"""
- index_json = (setup.source_dir / 'index.json').read_text()
- index_json = json.loads(hydrilla_util.strip_json_comments(index_json))
+def index_json_modification(modify_index_json):
+ """Decorator for function that modifies index.json before build."""
+ def handle_index_json(setup):
+ """Modify index.json before build."""
+ index_path = setup.source_dir / 'index.json'
+ index_json, _ = hydrilla_util.load_instance_from_file(index_path)
+ index_json = modify_index_json(index_json) or index_json
+
+ index_json = f'''
+ // SPDX-License-Identifier: CC0-1.0
+ // Copyright (C) 2021, 2022 Wojtek Kosior
+ {json.dumps(index_json)}
+ '''
+
+ index_path.write_text(index_json)
+
+ return handle_index_json
+
+@index_json_modification
+def remove_all_uuids(index_json):
+ """Modify sample packages to contain no (optional) UUIDs"""
for definition in index_json['definitions']:
del definition['uuid']
- index_json = ("// SPDX-License-Identifier: CC0-1.0\n" +
- "// Copyright (C) 2021, 2022 Wojtek Kosior\n" +
- json.dumps(index_json))
+@index_json_modification
+def bump_schema_v2(index_json) -> None:
+ """Modify sample packages to use version 2 of Hydrilla JSON schemas."""
+ for definition in index_json['definitions']:
+ definition['min_haketilo_version'] = [1, 1]
- (setup.source_dir / 'index.json').write_text(index_json)
+ if definition['identifier'] == 'helloapple' and \
+ definition['type'] == 'resource':
+ definition['required_mappings'] = {'identifier': 'helloapple'}
default_setup = Setup()
uuidless_setup = Setup(modify_before_build=remove_all_uuids)
+schema_v2_setup = Setup(modify_before_build=bump_schema_v2)
+
+setups = [default_setup, uuidless_setup, schema_v2_setup]
def def_get(url: str) -> Response:
"""Convenience wrapper for def_get()"""
@@ -147,7 +172,7 @@ def test_project_url() -> None:
project_url = default_setup.config()['hydrilla_project_url']
assert escape(project_url).encode() in response.data
-@pytest.mark.parametrize('setup', [default_setup, uuidless_setup])
+@pytest.mark.parametrize('setup', setups)
@pytest.mark.parametrize('item_type', ['resource', 'mapping'])
def test_get_newest(setup: Setup, item_type: str) -> None:
"""
@@ -239,7 +264,7 @@ def test_query() -> None:
'generated_by': expected_generated_by
}
- hydrilla_util.validator_for('api_query_result-1.0.1.schema.json')\
+ hydrilla_util.validator_for('api_query_result-1.schema.json')\
.validate(response_object)
def test_source() -> None:
@@ -257,7 +282,7 @@ def test_source() -> None:
response = def_get(f'/source/hello.zip')
assert sha256(response.data).digest().hex() == zipfile_hash
- hydrilla_util.validator_for('api_source_description-1.0.1.schema.json')\
+ hydrilla_util.validator_for('api_source_description-1.schema.json')\
.validate(description)
def test_missing_source() -> None: