Revision 9bee4afa
Added by koszko over 1 year ago
test/haketilo_test/world_wide_library.py | ||
---|---|---|
33 | 33 |
from threading import Lock |
34 | 34 |
from uuid import uuid4 |
35 | 35 |
import json |
36 |
import functools as ft |
|
37 |
import operator as op |
|
36 | 38 |
|
37 | 39 |
from .misc_constants import here |
38 | 40 |
from .unit.utils import * # sample repo data |
... | ... | |
114 | 116 |
for i in range(9)] |
115 | 117 |
sample_hashes = [sha256(c.encode()).digest().hex() for c in sample_contents] |
116 | 118 |
|
117 |
file_url = lambda hashed: f'https://hydril.la/file/sha256/{hashed}'
|
|
119 |
file_url = ft.partial(op.concat, 'https://hydril.la/file/sha256/')
|
|
118 | 120 |
|
119 | 121 |
sample_files_catalog = dict([(file_url(h), make_handler(c)) |
120 | 122 |
for h, c in zip(sample_hashes, sample_contents)]) |
... | ... | |
144 | 146 |
'dependencies': [] |
145 | 147 |
}) |
146 | 148 |
|
149 |
# The one below will generate items with schema still at version 1, so required |
|
150 |
# mappings will be ignored. |
|
151 |
sample_resource_templates.append({ |
|
152 |
'id_suffix': 'a-w-required-mapping-v1', |
|
153 |
'files_count': 1, |
|
154 |
'dependencies': [], |
|
155 |
'required_mappings': [{'identifier': 'mapping-a'}] |
|
156 |
}) |
|
157 |
|
|
158 |
sample_resource_templates.append({ |
|
159 |
'id_suffix': 'a-w-required-mapping-v2', |
|
160 |
'files_count': 1, |
|
161 |
'dependencies': [], |
|
162 |
'required_mappings': [{'identifier': 'mapping-a'}], |
|
163 |
'schema_ver': '2' |
|
164 |
}) |
|
165 |
|
|
147 | 166 |
sample_resources_catalog = {} |
148 | 167 |
sample_mappings_catalog = {} |
149 | 168 |
sample_queries = {} |
150 | 169 |
|
151 | 170 |
for srt in sample_resource_templates: |
152 | 171 |
resource = make_sample_resource() |
153 |
resource['identifier'] = f'resource-{srt["id_suffix"]}'
|
|
154 |
resource['long_name'] = resource['identifier'].upper()
|
|
155 |
resource['uuid'] = str(uuid4())
|
|
156 |
resource['dependencies'] = srt['dependencies']
|
|
157 |
resource['source_copyright'] = []
|
|
158 |
resource['scripts'] = []
|
|
172 |
resource['identifier'] = f'resource-{srt["id_suffix"]}' |
|
173 |
resource['long_name'] = resource['identifier'].upper() |
|
174 |
resource['uuid'] = str(uuid4()) |
|
175 |
resource['dependencies'] = srt['dependencies'] |
|
176 |
resource['source_copyright'] = [] |
|
177 |
resource['scripts'] = [] |
|
159 | 178 |
for i in range(srt['files_count']): |
160 | 179 |
file_ref = {'file': f'file_{i}', 'sha256': sample_hashes[i]} |
161 | 180 |
resource[('source_copyright', 'scripts')[i & 1]].append(file_ref) |
... | ... | |
191 | 210 |
|
192 | 211 |
mapping['payloads'] = payloads |
193 | 212 |
|
213 |
for item in resource, mapping: |
|
214 |
if 'required_mappings' in srt: |
|
215 |
item['required_mappings'] = srt['required_mappings'] |
|
216 |
if 'schema_ver' in srt: |
|
217 |
item['$schema'] = item['$schema'].replace('1', srt['schema_ver']) |
|
218 |
|
|
194 | 219 |
for item, versions, catalog in [ |
195 | 220 |
(resource, resource_versions, sample_resources_catalog), |
196 | 221 |
(mapping, mapping_versions, sample_mappings_catalog) |
Also available in: Unified diff
support schema v2 and dependencies on mappings