aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_build.py25
-rw-r--r--tests/test_item_infos.py317
-rw-r--r--tests/test_json_instances.py8
-rw-r--r--tests/test_pattern_tree.py10
-rw-r--r--tests/test_server.py2
-rw-r--r--tests/test_url_patterns.py62
-rw-r--r--tests/test_versions.py20
-rw-r--r--tests/url_patterns_common.py1
8 files changed, 232 insertions, 213 deletions
diff --git a/tests/test_build.py b/tests/test_build.py
index 868594e..a4dd684 100644
--- a/tests/test_build.py
+++ b/tests/test_build.py
@@ -20,8 +20,8 @@ from contextlib import contextmanager
from jsonschema import ValidationError
-from hydrilla import _version, json_instances, versions
-from hydrilla.json_instances import _schema_name_re
+from hydrilla import _version, json_instances, versions, exceptions
+from hydrilla.json_instances import _schema_name_re, UnknownSchemaError
from hydrilla.builder import build, local_apt
from hydrilla.builder.common_errors import *
@@ -696,7 +696,7 @@ def sample_source_error_missing_file(monkeypatch, sample_source):
Modify index.json to expect missing report.spdx file and cause an error.
"""
monkeypatch.delitem(index_obj, 'reuse_generate_spdx_report')
- return FileReferenceError, '^referenced_file_report.spdx_missing$'
+ return FileReferenceError, r'^referenced_file_report\.spdx_missing$'
@collect(error_makers)
def sample_source_error_index_schema(monkeypatch, sample_source):
@@ -710,25 +710,28 @@ def sample_source_error_unknown_index_schema(monkeypatch, sample_source):
schema_id = \
'https://hydrilla.koszko.org/schemas/package_source-65536.schema.json'
monkeypatch.setitem(index_obj, "$schema", schema_id)
- return hydrilla_util.UnknownSchemaError, \
- r'^unknown_schema_package_source_.*/hello/index\.json$'
+ return UnknownSchemaError, \
+ r'^unknown_schema_package_source-65536\.schema\.json$'
@collect(error_makers)
def sample_source_error_bad_comment(monkeypatch, sample_source):
"""Modify index.json to have an invalid '/' in it."""
- return json.JSONDecodeError, '^bad_comment: .*', \
+ return exceptions.HaketiloException, \
+ r'^err.util.text_in_.*/hello/index\.json_not_valid_json$', \
json.dumps(index_obj) + '/something\n'
@collect(error_makers)
def sample_source_error_bad_json(monkeypatch, sample_source):
"""Modify index.json to not be valid json even after comment stripping."""
- return json.JSONDecodeError, '', json.dumps(index_obj) + '???\n'
+ return exceptions.HaketiloException, \
+ r'^err.util.text_in_.*/hello/index\.json_not_valid_json$', \
+ json.dumps(index_obj) + '???\n'
@collect(error_makers)
def sample_source_error_missing_reuse(monkeypatch, sample_source):
"""Cause mocked reuse process invocation to fail with FileNotFoundError."""
(sample_source / 'mock_reuse_missing').touch()
- return build.ReuseError, '^couldnt_execute_reuse_is_it_installed$'
+ return build.ReuseError, r'^couldnt_execute_reuse_is_it_installed$'
@collect(error_makers)
def sample_source_error_missing_license(monkeypatch, sample_source):
@@ -755,14 +758,14 @@ def sample_source_error_file_outside(monkeypatch, sample_source):
"""Make index.json illegally reference a file outside srcdir."""
new_list = [*index_obj['copyright'], {'file': '../abc'}]
monkeypatch.setitem(index_obj, 'copyright', new_list)
- return FileReferenceError, '^path_contains_double_dot_\\.\\./abc$'
+ return FileReferenceError, r'^path_contains_double_dot_\.\./abc$'
@collect(error_makers)
def sample_source_error_reference_itself(monkeypatch, sample_source):
"""Make index.json illegally reference index.json."""
new_list = [*index_obj['copyright'], {'file': 'index.json'}]
monkeypatch.setitem(index_obj, 'copyright', new_list)
- return FileReferenceError, '^loading_reserved_index_json$'
+ return FileReferenceError, r'^loading_reserved_index_json$'
@collect(error_makers)
def sample_source_error_report_excluded(monkeypatch, sample_source):
@@ -773,7 +776,7 @@ def sample_source_error_report_excluded(monkeypatch, sample_source):
new_list = [file_ref for file_ref in index_obj['copyright']
if file_ref['file'] != 'report.spdx']
monkeypatch.setitem(index_obj, 'copyright', new_list)
- return FileReferenceError, '^report_spdx_not_in_copyright_list$'
+ return FileReferenceError, r'^report_spdx_not_in_copyright_list$'
@collect(error_makers)
def sample_source_error_combined_unsupported(monkeypatch, sample_source):
diff --git a/tests/test_item_infos.py b/tests/test_item_infos.py
index 9de3c96..85809d6 100644
--- a/tests/test_item_infos.py
+++ b/tests/test_item_infos.py
@@ -14,59 +14,62 @@ from immutables import Map
from hydrilla import item_infos, versions, json_instances
from hydrilla.exceptions import HaketiloException
-def test_make_item_refs_seq_empty():
+def test_make_item_specifiers_seq_empty():
"""...."""
- assert item_infos.make_item_refs_seq([]) == ()
+ assert item_infos.make_item_specifiers_seq([]) == ()
-def test_get_item_refs_seq_nonempty():
+def test_get_item_specifiers_seq_nonempty():
"""...."""
ref_objs = [{'identifier': 'abc'}, {'identifier': 'def'}]
- result = item_infos.make_item_refs_seq(ref_objs)
+ result = item_infos.make_item_specifiers_seq(ref_objs)
assert type(result) is tuple
assert [ref.identifier for ref in result] == ['abc', 'def']
@pytest.fixture
-def mock_make_item_refs_seq(monkeypatch):
+def mock_make_item_specifiers_seq(monkeypatch):
"""...."""
- def mocked_make_item_refs_seq(ref_objs):
+ def mocked_make_item_specifiers_seq(ref_objs):
"""...."""
assert ref_objs == getattr(
- mocked_make_item_refs_seq,
+ mocked_make_item_specifiers_seq,
'expected',
[{'identifier': 'abc'}, {'identifier': 'def'}]
)
- return (item_infos.ItemRef('abc'), item_infos.ItemRef('def'))
+ return (
+ item_infos.ItemSpecifier('abc'),
+ item_infos.ItemSpecifier('def')
+ )
- monkeypatch.setattr(item_infos, 'make_item_refs_seq',
- mocked_make_item_refs_seq)
+ monkeypatch.setattr(item_infos, 'make_item_specifiers_seq',
+ mocked_make_item_specifiers_seq)
- return mocked_make_item_refs_seq
+ return mocked_make_item_specifiers_seq
def test_make_required_mappings_compat_too_low():
"""...."""
assert item_infos.make_required_mappings('whatever', 1) == ()
-@pytest.mark.usefixtures('mock_make_item_refs_seq')
+@pytest.mark.usefixtures('mock_make_item_specifiers_seq')
def test_make_required_mappings_compat_ok():
"""...."""
ref_objs = [{'identifier': 'abc'}, {'identifier': 'def'}]
assert item_infos.make_required_mappings(ref_objs, 2) == \
- (item_infos.ItemRef('abc'), item_infos.ItemRef('def'))
+ (item_infos.ItemSpecifier('abc'), item_infos.ItemSpecifier('def'))
-def test_make_file_refs_seq_empty():
+def test_make_file_specifiers_seq_empty():
"""...."""
- assert item_infos.make_file_refs_seq([]) == ()
+ assert item_infos.make_file_specifiers_seq([]) == ()
-def test_make_file_refs_seq_nonempty():
+def test_make_file_specifiers_seq_nonempty():
"""...."""
ref_objs = [{'file': 'abc', 'sha256': 'dummy_hash1'},
{'file': 'def', 'sha256': 'dummy_hash2'}]
- result = item_infos.make_file_refs_seq(ref_objs)
+ result = item_infos.make_file_specifiers_seq(ref_objs)
assert type(result) is tuple
assert [ref.name for ref in result] == ['abc', 'def']
@@ -99,7 +102,7 @@ def test_load_item_info(monkeypatch):
def mocked_validate_instance(instance, schema_fmt):
"""...."""
assert instance == 'dummy_instance'
- assert schema_fmt == 'api_exotictype_description-{}.schema.json'
+ assert schema_fmt == 'api_resource_description-{}.schema.json'
return 7
monkeypatch.setattr(json_instances, 'validate_instance',
@@ -107,19 +110,21 @@ def test_load_item_info(monkeypatch):
class MockedLoadedType:
"""...."""
- def make(instance, schema_compat, repository):
+ def make(instance, schema_compat, repo, repo_iteration):
"""...."""
- assert instance == 'dummy_instance'
- assert schema_compat == 7
- assert repository == 'somerepo'
+ assert instance == 'dummy_instance'
+ assert schema_compat == 7
+ assert repo == 'somerepo'
+ assert repo_iteration == 1
return 'dummy_item_info'
- type_name = 'exotictype'
+ type = item_infos.ItemType.RESOURCE
assert item_infos._load_item_info(
MockedLoadedType,
'dummy_path',
- 'somerepo'
+ 'somerepo',
+ 1
) == 'dummy_item_info'
def test_make_payloads(monkeypatch):
@@ -136,8 +141,8 @@ def test_make_payloads(monkeypatch):
monkeypatch.setattr(item_infos, 'parse_pattern', mocked_parse_pattern)
assert item_infos.make_payloads(payloads_obj) == Map({
- 'dummy_parsed_pattern_1': item_infos.ItemRef('someresource'),
- 'dummy_parsed_pattern_2': item_infos.ItemRef('someresource')
+ 'dummy_parsed_pattern_1': item_infos.ItemSpecifier('someresource'),
+ 'dummy_parsed_pattern_2': item_infos.ItemSpecifier('someresource')
})
@pytest.mark.parametrize('info_mod, in_mod', [
@@ -146,7 +151,7 @@ def test_make_payloads(monkeypatch):
({}, {'uuid': 'dummy_uuid'}),
({'uuid': 'dummy_uuid'}, {'uuid': 'dummy_uuid'}),
({}, {'identifier': 'abc', '_initialized': True}),
- ({}, {'_by_version': Map({(1, 2): 'dummy_old_info'})})
+ ({}, {'items': Map({(1, 2): 'dummy_old_info'})})
])
def test_versioned_item_info_register(info_mod, in_mod):
"""...."""
@@ -162,14 +167,14 @@ def test_versioned_item_info_register(info_mod, in_mod):
in_fields = {
'uuid': None,
'identifier': '<dummy>',
- '_by_version': Map(),
+ 'items': Map(),
'_initialized': False,
**in_mod
}
out_fields = {
'uuid': DummyInfo.uuid or in_mod.get('uuid'),
'identifier': DummyInfo.identifier,
- '_by_version': Map({(1, 2): DummyInfo}),
+ 'items': Map({(1, 2): DummyInfo}),
'_initialized': True
}
@@ -195,20 +200,6 @@ def test_versioned_item_info_register_bad_uuid():
with pytest.raises(HaketiloException, match='^uuid_mismatch_abc$'):
versioned.register(DummyInfo)
-@pytest.mark.parametrize('previous_registrations', [
- Map(),
- Map({(1, 2): 'dummy_info'})
-])
-def test_versioned_item_info_unregister(previous_registrations):
- """...."""
- versioned = item_infos.VersionedItemInfo(
- identifier = 'abc',
- _by_version = previous_registrations
- )
-
- assert versioned.unregister((1, 2)) == \
- dc.replace(versioned, _by_version=Map())
-
@pytest.mark.parametrize('registrations, out', [
(Map(), True),
(Map({(1, 2): 'dummy_info'}), False)
@@ -217,7 +208,7 @@ def test_versioned_item_info_is_empty(registrations, out):
"""...."""
versioned = item_infos.VersionedItemInfo(
identifier = 'abc',
- _by_version = registrations
+ items = registrations
)
assert versioned.is_empty() == out
@@ -229,29 +220,32 @@ def test_versioned_item_info_is_empty(registrations, out):
def test_versioned_item_info_newest_version(versions, out):
"""...."""
versioned = item_infos.VersionedItemInfo(
- identifier = 'abc',
- _by_version = Map((ver, 'dummy_info') for ver in versions)
+ identifier = 'abc',
+ items = Map((ver, 'dummy_info') for ver in versions)
)
- assert versioned.newest_version() == out
+ assert versioned.newest_version == out
def test_versioned_item_info_newest_version_bad(monkeypatch):
"""...."""
- monkeypatch.setattr(item_infos.VersionedItemInfo, 'newest_version',
- lambda self: 'dummy_ver1')
+ monkeypatch.setattr(
+ item_infos.VersionedItemInfo,
+ 'newest_version',
+ 'dummy_ver1'
+ )
versioned = item_infos.VersionedItemInfo(
- identifier = 'abc',
- _by_version = Map(dummy_ver1='dummy_info1', dummy_ver2='dummy_info2')
+ identifier = 'abc',
+ items = Map(dummy_ver1='dummy_info1', dummy_ver2='dummy_info2')
)
- assert versioned.get_newest() == 'dummy_info1'
+ assert versioned.newest_info == 'dummy_info1'
def test_versioned_item_info_get_by_ver():
"""...."""
versioned = item_infos.VersionedItemInfo(
- identifier = 'abc',
- _by_version = Map({(1, 2): 'dummy_info1', (3, 4, 5): 'dummy_info2'})
+ identifier = 'abc',
+ items = Map({(1, 2): 'dummy_info1', (3, 4, 5): 'dummy_info2'})
)
assert versioned.get_by_ver(range(1, 3)) == 'dummy_info1'
@@ -263,24 +257,27 @@ def test_versioned_item_info_get_by_ver():
def test_versioned_item_get_all(versions, out):
"""...."""
versioned = item_infos.VersionedItemInfo(
- identifier = 'abc',
- _by_version = Map((ver, str(ver)) for ver in versions)
+ identifier = 'abc',
+ items = Map((ver, str(ver)) for ver in versions)
)
assert [*versioned.get_all()] == out
sample_resource_obj = {
- 'source_name': 'somesource',
- 'source_copyright': [{'file': 'ABC', 'sha256': 'dummy_sha256'}],
- 'version': [1, 2, 3, 0],
- 'identifier': 'someid',
- 'uuid': None,
- 'long_name': 'Some Thing',
- 'required_mappings': [{'identifier': 'required1'}],
- 'generated_by': {'name': 'sometool', 'version': '1.1.1'},
- 'revision': 4,
- 'dependencies': [{'identifier': 'abc'}, {'identifier': 'def'}],
- 'scripts': [{'file': 'ABC', 'sha256': 'dummy_sha256'}]
+ 'source_name': 'somesource',
+ 'source_copyright': [{'file': 'ABC', 'sha256': 'dummy_sha256'}],
+ 'version': [1, 2, 3, 0],
+ 'identifier': 'someid',
+ 'uuid': None,
+ 'long_name': 'Some Thing',
+ 'description': 'Do something somewhere',
+ 'permissions': {'eval': True, 'cors_bypass': False},
+ 'max_haketilo_version': [10],
+ 'required_mappings': [{'identifier': 'required1'}],
+ 'generated_by': {'name': 'sometool', 'version': '1.1.1'},
+ 'revision': 4,
+ 'dependencies': [{'identifier': 'abc'}, {'identifier': 'def'}],
+ 'scripts': [{'file': 'ABC', 'sha256': 'dummy_sha256'}]
}
sample_mapping_obj = {
@@ -297,118 +294,113 @@ del sample_mapping_obj['scripts']
def sample_resource_info():
"""...."""
return item_infos.ResourceInfo(
- repository = 'somerepo',
- source_name = 'somesource',
- source_copyright = (item_infos.FileRef('ABC', 'dummy_sha256'),),
- version = (1, 2, 3),
- identifier = 'someid',
- uuid = None,
- long_name = 'Some Thing',
- required_mappings = (item_infos.ItemRef('required1'),),
- generated_by = item_infos.GeneratedBy('sometool', '1.1.1'),
- revision = 4,
- dependencies = (item_infos.ItemRef('abc'),
- item_infos.ItemRef('def')),
- scripts = (item_infos.FileRef('ABC', 'dummy_sha256'),)
+ repo = 'somerepo',
+ repo_iteration = 2,
+ source_name = 'somesource',
+ source_copyright = (item_infos.FileSpecifier('ABC', 'dummy_sha256'),),
+ version = (1, 2, 3),
+ identifier = 'someid',
+ uuid = None,
+ long_name = 'Some Thing',
+ description = 'Do something somewhere',
+ allows_eval = True,
+ allows_cors_bypass = False,
+ min_haketilo_ver = versions.normalize([1]),
+ max_haketilo_ver = versions.normalize([10]),
+ required_mappings = (item_infos.ItemSpecifier('required1'),),
+ generated_by = item_infos.GeneratedBy('sometool', '1.1.1'),
+ revision = 4,
+ dependencies = (item_infos.ItemSpecifier('abc'),
+ item_infos.ItemSpecifier('def')),
+ scripts = (item_infos.FileSpecifier('ABC', 'dummy_sha256'),)
)
@pytest.fixture(scope='session')
def sample_mapping_info():
"""...."""
- payloads = Map({'https://example.com/': item_infos.ItemRef('someresource')})
+ payloads = Map({
+ 'https://example.com/': item_infos.ItemSpecifier('someresource')
+ })
return item_infos.MappingInfo(
- repository = 'somerepo',
- source_name = 'somesource',
- source_copyright = (item_infos.FileRef('ABC', 'dummy_sha256'),),
- version = (1, 2, 3),
- identifier = 'someid',
- uuid = None,
- long_name = 'Some Thing',
- required_mappings = (item_infos.ItemRef('required1'),),
- generated_by = item_infos.GeneratedBy('sometool', '1.1.1'),
- payloads = payloads
+ repo = 'somerepo',
+ repo_iteration = 2,
+ source_name = 'somesource',
+ source_copyright = (item_infos.FileSpecifier('ABC', 'dummy_sha256'),),
+ version = (1, 2, 3),
+ identifier = 'someid',
+ uuid = None,
+ long_name = 'Some Thing',
+ description = 'Do something somewhere',
+ allows_eval = True,
+ allows_cors_bypass = False,
+ min_haketilo_ver = versions.normalize([2]),
+ max_haketilo_ver = versions.normalize([10]),
+ required_mappings = (item_infos.ItemSpecifier('required1'),),
+ generated_by = item_infos.GeneratedBy('sometool', '1.1.1'),
+ payloads = payloads
)
@pytest.fixture(scope='session')
def sample_info_base_init_kwargs(sample_resource_info):
kwargs = {}
- for field_name in item_infos.ItemInfoBase.__annotations__.keys():
- kwargs[field_name] = getattr(sample_resource_info, field_name)
+ for datclass_type in (item_infos.ItemInfoBase, item_infos.ItemIdentity):
+ for field_name in datclass_type.__annotations__.keys():
+ kwargs[field_name] = getattr(sample_resource_info, field_name)
return Map(kwargs)
-@pytest.fixture
-def mock_version_string(monkeypatch):
- """...."""
- def mocked_version_string(version, revision=None):
- """...."""
- assert version == (1, 2, 3)
- assert revision in (None, 4)
- return '1.2.3' if revision is None else '1.2.3-4'
-
- monkeypatch.setattr(versions, 'version_string', mocked_version_string)
-
-@pytest.mark.usefixtures('mock_version_string')
-def test_item_info_path(sample_resource_info):
- """...."""
- assert sample_resource_info.path_relative_to_type() == 'someid/1.2.3'
- assert sample_resource_info.path() == 'resource/someid/1.2.3'
-
-@pytest.mark.usefixtures('mock_version_string')
-def test_resource_info_versioned_identifier(sample_resource_info, monkeypatch):
+def test_resource_info_versioned_identifier(sample_resource_info):
"""...."""
- monkeypatch.setattr(item_infos.ItemInfoBase, 'versioned_identifier',
- lambda self: '<dummy>')
+ assert sample_resource_info.versioned_identifier == 'someid-1.2.3-4'
- assert sample_resource_info.versioned_identifier == '<dummy>-4'
-
-@pytest.mark.usefixtures('mock_version_string')
def test_mapping_info_versioned_identifier(sample_mapping_info):
- """...."""
assert sample_mapping_info.versioned_identifier == 'someid-1.2.3'
@pytest.fixture
-def mock_make_file_refs_seq(monkeypatch):
+def mock_make_file_specifiers_seq(monkeypatch):
"""...."""
- def mocked_make_file_refs_seq(ref_objs):
+ def mocked_make_file_specifiers_seq(ref_objs):
"""...."""
assert ref_objs == getattr(
- mocked_make_file_refs_seq,
+ mocked_make_file_specifiers_seq,
'expected',
[{'file': 'ABC', 'sha256': 'dummy_sha256'}]
)
- return (item_infos.FileRef(name='ABC', sha256='dummy_sha256'),)
+ return (item_infos.FileSpecifier(name='ABC', sha256='dummy_sha256'),)
- monkeypatch.setattr(item_infos, 'make_file_refs_seq',
- mocked_make_file_refs_seq)
+ monkeypatch.setattr(item_infos, 'make_file_specifiers_seq',
+ mocked_make_file_specifiers_seq)
- return mocked_make_file_refs_seq
+ return mocked_make_file_specifiers_seq
@pytest.mark.parametrize('missing_prop', [
'required_mappings',
'generated_by',
'uuid'
])
-@pytest.mark.usefixtures('mock_make_item_refs_seq', 'mock_make_file_refs_seq')
+@pytest.mark.usefixtures(
+ 'mock_make_item_specifiers_seq',
+ 'mock_make_file_specifiers_seq'
+)
def test_item_info_get_base_init_kwargs(
missing_prop,
monkeypatch,
sample_resource_info,
sample_info_base_init_kwargs,
- mock_make_file_refs_seq
+ mock_make_file_specifiers_seq
):
"""...."""
monkeypatch.delitem(sample_resource_obj, missing_prop)
def mocked_normalize_version(version):
- """...."""
- assert version == [1, 2, 3, 0]
-
- return (1, 2, 3)
+ return {
+ (1, 2, 3, 0): (1, 2, 3),
+ (10,): (10,)
+ }[tuple(version)]
- monkeypatch.setattr(versions, 'normalize_version', mocked_normalize_version)
+ monkeypatch.setattr(versions, 'normalize', mocked_normalize_version)
def mocked_make_required_mappings(ref_objs, schema_compat):
"""...."""
@@ -419,7 +411,7 @@ def test_item_info_get_base_init_kwargs(
assert schema_compat == 2
- return (item_infos.ItemRef('required1'),)
+ return (item_infos.ItemSpecifier('required1'),)
monkeypatch.setattr(item_infos, 'make_required_mappings',
mocked_make_required_mappings)
@@ -441,17 +433,23 @@ def test_item_info_get_base_init_kwargs(
expected = expected.set('uuid', None)
Base = item_infos.ItemInfoBase
- assert Base._get_base_init_kwargs(sample_resource_obj, 2, 'somerepo') == \
- expected
+ assert Base._get_base_init_kwargs(sample_resource_obj, 2, 'somerepo', 2) \
+ == expected
@pytest.fixture
def mock_get_base_init_kwargs(monkeypatch, sample_info_base_init_kwargs):
"""...."""
- def mocked_get_base_init_kwargs(item_obj, schema_compat, repository):
+ def mocked_get_base_init_kwargs(
+ item_obj,
+ schema_compat,
+ repo,
+ repo_iteration
+ ):
"""...."""
assert schema_compat == 2
assert item_obj['identifier'] == 'someid'
- assert repository == 'somerepo'
+ assert repo == 'somerepo'
+ assert repo_iteration == 2
return sample_info_base_init_kwargs
@@ -464,23 +462,26 @@ def test_resource_info_make(
missing_prop,
monkeypatch,
sample_resource_info,
- mock_make_item_refs_seq,
- mock_make_file_refs_seq
+ mock_make_item_specifiers_seq,
+ mock_make_file_specifiers_seq
):
"""...."""
_in = sample_resource_obj
monkeypatch.delitem(_in, missing_prop)
if missing_prop == 'dependencies':
- mock_make_item_refs_seq.expected = []
+ mock_make_item_specifiers_seq.expected = []
elif missing_prop == 'scripts':
- mock_make_file_refs_seq.expected = []
+ mock_make_file_specifiers_seq.expected = []
- assert item_infos.ResourceInfo.make(_in, 2, 'somerepo') == \
+ assert item_infos.ResourceInfo.make(_in, 2, 'somerepo', 2) == \
sample_resource_info
@pytest.mark.parametrize('missing_payloads', [True, False])
-@pytest.mark.usefixtures('mock_get_base_init_kwargs', 'mock_make_item_refs_seq')
+@pytest.mark.usefixtures(
+ 'mock_get_base_init_kwargs',
+ 'mock_make_item_specifiers_seq'
+)
def test_mapping_info_make(missing_payloads, monkeypatch, sample_mapping_info):
"""...."""
_in = sample_mapping_obj
@@ -495,28 +496,46 @@ def test_mapping_info_make(missing_payloads, monkeypatch, sample_mapping_info):
assert payloads_obj == \
{'https://example.com/': {'identifier': 'someresource'}}
- return Map({'https://example.com/': item_infos.ItemRef('someresource')})
+ return Map({
+ 'https://example.com/': item_infos.ItemSpecifier('someresource')
+ })
monkeypatch.setattr(item_infos, 'make_payloads', mocked_make_payloads)
- assert item_infos.MappingInfo.make(_in, 2, 'somerepo') == \
+ assert item_infos.MappingInfo.make(_in, 2, 'somerepo', 2) == \
sample_mapping_info
@pytest.mark.parametrize('type_name', ['ResourceInfo', 'MappingInfo'])
-def test_make_item_info(type_name, monkeypatch):
+@pytest.mark.parametrize('repo_iter_arg', [10, 'default'])
+def test_make_item_info(type_name, repo_iter_arg, monkeypatch):
"""...."""
info_type = getattr(item_infos, type_name)
- def mocked_load_item_info(_info_type, instance_or_path, repository):
+ def mocked_load_item_info(
+ _info_type,
+ instance_or_path,
+ repo,
+ repo_iteration
+ ):
"""...."""
assert _info_type == info_type
assert instance_or_path == 'dummy_path'
- assert repository == 'somerepo'
+ assert repo == 'somerepo'
+ if repo_iter_arg == 'default':
+ assert repo_iteration == -1
+ else:
+ assert repo_iteration == 10
+
return 'dummy_info'
monkeypatch.setattr(item_infos, '_load_item_info', mocked_load_item_info)
- assert info_type.load('dummy_path', 'somerepo') == 'dummy_info'
+ extra_args = {}
+ if repo_iter_arg != 'default':
+ extra_args['repo_iteration'] = repo_iter_arg
+
+ assert info_type.load('dummy_path', 'somerepo', **extra_args) \
+ == 'dummy_info'
def test_resource_info_hash(sample_resource_info):
"""...."""
diff --git a/tests/test_json_instances.py b/tests/test_json_instances.py
index f5bd270..fd09ce1 100644
--- a/tests/test_json_instances.py
+++ b/tests/test_json_instances.py
@@ -7,7 +7,7 @@
import pytest
import re
-from hydrilla import json_instances
+from hydrilla import json_instances, versions
from hydrilla.exceptions import HaketiloException
sample_json_no_comments = '{\n"so/me":\n"//json//"\n}\n'
@@ -113,7 +113,7 @@ def test_read_instance_bad(monkeypatch, tmpdir):
somepath = tmpdir / 'somefile'
somepath.write_text('dummy_JSON_text')
- error_regex = f'^text_in_{re.escape(str(somepath))}_not_valid_json$'
+ error_regex = f'^err.util.text_in_{re.escape(str(somepath))}_not_valid_json$'
with pytest.raises(HaketiloException, match=error_regex):
json_instances.read_instance(somepath)
@@ -124,12 +124,12 @@ def test_read_instance_bad(monkeypatch, tmpdir):
])
def test_get_schema_version(instance, ver_str, monkeypatch):
"""...."""
- def mocked_parse_version(_ver_str):
+ def mocked_parse_normalize(_ver_str):
"""...."""
assert _ver_str == ver_str
return 'dummy_version'
- monkeypatch.setattr(json_instances, 'parse_version', mocked_parse_version)
+ monkeypatch.setattr(versions, 'parse_normalize', mocked_parse_normalize)
assert json_instances.get_schema_version(instance) == 'dummy_version'
diff --git a/tests/test_pattern_tree.py b/tests/test_pattern_tree.py
index 4238d66..df2ba15 100644
--- a/tests/test_pattern_tree.py
+++ b/tests/test_pattern_tree.py
@@ -203,8 +203,8 @@ def test_pattern_tree_branch_search_wildcards(_in, out, branch_with_wildcards):
def test_filter_by_trailing_slash(sample_url_parsed):
"""...."""
sample_url_parsed2 = dc.replace(sample_url_parsed, has_trailing_slash=True)
- item1 = pattern_tree.StoredTreeItem(sample_url_parsed, 'dummy_it1')
- item2 = pattern_tree.StoredTreeItem(sample_url_parsed2, 'dummy_it2')
+ item1 = pattern_tree.StoredTreeItem('dummy_it1', sample_url_parsed)
+ item2 = pattern_tree.StoredTreeItem('dummy_it2', sample_url_parsed2)
assert pattern_tree.filter_by_trailing_slash((item1, item2), False) == \
frozenset({item1})
@@ -223,10 +223,10 @@ def test_pattern_tree_privatemethod_register(
sample_url_parsed
):
"""...."""
- dummy_it = pattern_tree.StoredTreeItem(sample_url_parsed, 'dummy_it')
+ dummy_it = pattern_tree.StoredTreeItem('dummy_it', sample_url_parsed)
other_dummy_it = pattern_tree.StoredTreeItem(
- sample_url_parsed,
- 'other_dummy_it'
+ item = 'other_dummy_it',
+ pattern = sample_url_parsed
)
class MockedTreeBranch:
diff --git a/tests/test_server.py b/tests/test_server.py
index fda8490..db7ca31 100644
--- a/tests/test_server.py
+++ b/tests/test_server.py
@@ -123,7 +123,7 @@ def index_json_modification(modify_index_json):
def handle_index_json(setup):
"""Modify index.json before build."""
index_path = setup.source_dir / 'index.json'
- index_json, _ = json_instances.read_instance(index_path)
+ index_json = json_instances.read_instance(index_path)
index_json = modify_index_json(index_json) or index_json
diff --git a/tests/test_url_patterns.py b/tests/test_url_patterns.py
index c308f18..f01c493 100644
--- a/tests/test_url_patterns.py
+++ b/tests/test_url_patterns.py
@@ -15,38 +15,34 @@ from hydrilla.exceptions import HaketiloException
from .url_patterns_common import *
-# @pytest.mark.parametrize('_in, out', [
-# ({}, sample_url_str),
-# ({'path_segments': ()}, 'http://example.com'),
-# ({'has_trailing_slash': True}, 'http://example.com/aa/bb/'),
-# ({'orig_scheme': 'http*'}, 'http*://example.com/aa/bb'),
-# ({'scheme': 'http_sth'}, 'http://example.com/aa/bb'),
-# ({'port': 443}, 'http://example.com:443/aa/bb'),
-
-# ({'path_segments': (),
-# 'has_trailing_slash': True},
-# 'http://example.com/'),
-
-# ({'orig_scheme': 'https',
-# 'scheme': 'https',
-# 'port': 443},
-# 'https://example.com/aa/bb'),
-
-# ({'orig_scheme': 'ftp',
-# 'scheme': 'ftp',
-# 'port': 21},
-# 'ftp://example.com/aa/bb'),
-
-# ({'orig_scheme': 'file',
-# 'scheme': 'file',
-# 'port': None,
-# 'domain_labels': ()},
-# 'file:///aa/bb')
-# ])
-# def test_reconstruct_parsed_url(_in, out, sample_url_parsed):
-# """Test the reconstruct_url() method of ParsedUrl class."""
-# parsed_url = dc.replace(sample_url_parsed, **_in)
-# assert parsed_url.reconstruct_url() == out
+@pytest.mark.parametrize('_in, out', [
+ ({}, sample_url_str),
+ ({'path_segments': ()}, 'http://example.com'),
+ ({'has_trailing_slash': True}, 'http://example.com/aa/bb/'),
+ ({'scheme': 'http_sth'}, 'http_sth://example.com:80/aa/bb'),
+ ({'port': 443}, 'http://example.com:443/aa/bb'),
+
+ ({'path_segments': (),
+ 'has_trailing_slash': True},
+ 'http://example.com/'),
+
+ ({'scheme': 'https',
+ 'port': 443},
+ 'https://example.com/aa/bb'),
+
+ ({'scheme': 'ftp',
+ 'port': 21},
+ 'ftp://example.com/aa/bb'),
+
+ ({'scheme': 'file',
+ 'port': None,
+ 'domain_labels': ()},
+ 'file:///aa/bb')
+])
+def test_reconstruct_parsed_url(_in, out, sample_url_parsed):
+ """Test the reconstruct_url() method of ParsedUrl class."""
+ parsed_url = dc.replace(sample_url_parsed, **_in)
+ assert parsed_url.reconstruct_url() == out
@pytest.mark.parametrize('_in, out', [
({'url': sample_url_str}, {}),
@@ -169,7 +165,7 @@ def test_parse_pattern(monkeypatch, _in, out):
monkeypatch.setattr(url_patterns, '_parse_pattern_or_url',
mocked_parse_pattern_or_url)
- assert url_patterns.parse_pattern(_in) == out
+ assert tuple(url_patterns.parse_pattern(_in)) == out
def test_parse_url(monkeypatch):
"""...."""
diff --git a/tests/test_versions.py b/tests/test_versions.py
index 43a3f33..00150ce 100644
--- a/tests/test_versions.py
+++ b/tests/test_versions.py
@@ -14,21 +14,21 @@ sample_version_strings = ['4.5.3', '1.0.5', '3']
sample_versions = [*zip(sample_version_tuples, sample_version_strings)]
@pytest.mark.parametrize('version_tuple', sample_version_tuples)
-def test_normalize_version(version_tuple):
- """Verify that normalize_version() produces proper results."""
- assert versions.normalize_version([*version_tuple]) == version_tuple
- assert versions.normalize_version([*version_tuple, 0]) == version_tuple
+def test_normalize(version_tuple):
+ """Verify that normalize() produces proper results."""
+ assert versions.normalize([*version_tuple]) == version_tuple
+ assert versions.normalize([*version_tuple, 0]) == version_tuple
@pytest.mark.parametrize('version_tuple, string', sample_versions)
-def test_parse_version(version_tuple, string):
- """Verify that parse_version() produces proper results."""
- assert versions.parse_version(string)
- assert versions.parse_version(string + '.0') == tuple([*version_tuple, 0])
+def test_parse(version_tuple, string):
+ """Verify that parse() produces proper results."""
+ assert versions.parse(string)
+ assert versions.parse(string + '.0') == tuple([*version_tuple, 0])
def test_parse_version_bad_string():
- """Verify that parse_version() raises when passed an invalid string."""
+ """Verify that parse() raises when passed an invalid string."""
with pytest.raises(ValueError):
- versions.parse_version('i am not a valid version')
+ versions.parse('i am not a valid version')
@pytest.mark.parametrize('version_tuple, string', sample_versions)
def test_version_string(version_tuple, string):
diff --git a/tests/url_patterns_common.py b/tests/url_patterns_common.py
index de6651d..04e8fd9 100644
--- a/tests/url_patterns_common.py
+++ b/tests/url_patterns_common.py
@@ -18,6 +18,7 @@ def sample_url_parsed():
scheme = 'http',
domain_labels = ('com', 'example'),
path_segments = ('aa', 'bb'),
+ query = '',
has_trailing_slash = False,
port = 80
)