1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
|
"""
Description: Test validation for recursion
"""
from stac_validator import stac_validator
def test_recursive_lvl_4_local_v100():
stac_file = "tests/test_data/local_cat/open-science-catalog-testing/catalog.json"
stac = stac_validator.StacValidate(stac_file, recursive=True, max_depth=4)
stac.run()
assert stac.valid
assert stac.message == [
{
"version": "1.0.0",
"path": "tests/test_data/local_cat/open-science-catalog-testing/catalog.json",
"schema": [
"https://schemas.stacspec.org/v1.0.0/catalog-spec/json-schema/catalog.json"
],
"valid_stac": True,
"asset_type": "CATALOG",
"validation_method": "recursive",
"validator_engine": "jsonschema",
},
{
"version": "1.0.0",
"path": "tests/test_data/local_cat/open-science-catalog-testing/./projects/catalog.json",
"schema": [
"https://schemas.stacspec.org/v1.0.0/catalog-spec/json-schema/catalog.json"
],
"valid_stac": True,
"asset_type": "CATALOG",
"validation_method": "recursive",
"validator_engine": "jsonschema",
},
{
"version": "1.0.0",
"path": "tests/test_data/local_cat/open-science-catalog-testing/./projects/./3d-earth/collection.json",
"schema": [
"https://stac-extensions.github.io/osc/v1.0.0-rc.3/schema.json",
"https://stac-extensions.github.io/contacts/v0.1.1/schema.json",
"https://schemas.stacspec.org/v1.0.0/collection-spec/json-schema/collection.json",
],
"valid_stac": True,
"asset_type": "COLLECTION",
"validation_method": "recursive",
"validator_engine": "jsonschema",
},
{
"version": "1.0.0",
"path": "tests/test_data/local_cat/open-science-catalog-testing/./projects/./3dctrl/collection.json",
"schema": [
"https://stac-extensions.github.io/osc/v1.0.0-rc.3/schema.json",
"https://stac-extensions.github.io/contacts/v0.1.1/schema.json",
"https://schemas.stacspec.org/v1.0.0/collection-spec/json-schema/collection.json",
],
"valid_stac": True,
"asset_type": "COLLECTION",
"validation_method": "recursive",
"validator_engine": "jsonschema",
},
]
def test_recursive_local_v090():
stac_file = "tests/test_data/v090/catalog.json"
stac = stac_validator.StacValidate(stac_file, recursive=True, max_depth=1)
stac.run()
assert stac.message == [
{
"version": "0.9.0",
"path": "tests/test_data/v090/catalog.json",
"schema": ["https://cdn.staclint.com/v0.9.0/catalog.json"],
"asset_type": "CATALOG",
"validation_method": "recursive",
"valid_stac": True,
"validator_engine": "jsonschema",
},
{
"version": "0.9.0",
"path": "tests/test_data/v090/items/sample.json",
"schema": ["https://cdn.staclint.com/v0.9.0/item.json"],
"asset_type": "ITEM",
"validation_method": "recursive",
"valid_stac": True,
"validator_engine": "jsonschema",
},
{
"version": "0.9.0",
"path": "tests/test_data/v090/items/good_item_v090.json",
"schema": [
"https://cdn.staclint.com/v0.9.0/extension/eo.json",
"https://cdn.staclint.com/v0.9.0/extension/view.json",
"https://cdn.staclint.com/v0.9.0/item.json",
],
"asset_type": "ITEM",
"validation_method": "recursive",
"valid_stac": True,
"validator_engine": "jsonschema",
},
]
def test_recursive_v1beta1():
stac_file = "tests/test_data/1beta1/sentinel2.json"
stac = stac_validator.StacValidate(stac_file, recursive=True, max_depth=0)
stac.run()
assert stac.message == [
{
"version": "1.0.0-beta.1",
"path": "tests/test_data/1beta1/sentinel2.json",
"schema": ["https://cdn.staclint.com/v1.0.0-beta.1/collection.json"],
"asset_type": "COLLECTION",
"validation_method": "recursive",
"valid_stac": True,
"validator_engine": "jsonschema",
}
]
def test_recursive_v1beta2():
stac_file = "https://raw.githubusercontent.com/stac-utils/pystac/main/tests/data-files/examples/1.0.0-beta.2/collection-spec/examples/sentinel2.json"
stac = stac_validator.StacValidate(stac_file, recursive=True, max_depth=0)
stac.run()
assert stac.message == [
{
"version": "1.0.0-beta.2",
"path": "https://raw.githubusercontent.com/stac-utils/pystac/main/tests/data-files/examples/1.0.0-beta.2/collection-spec/examples/sentinel2.json",
"schema": [
"https://schemas.stacspec.org/v1.0.0-beta.2/collection-spec/json-schema/collection.json"
],
"asset_type": "COLLECTION",
"validation_method": "recursive",
"valid_stac": True,
"validator_engine": "jsonschema",
}
]
def test_recursion_collection_local_v1rc1():
stac_file = "tests/test_data/1rc1/collection.json"
stac = stac_validator.StacValidate(stac_file, recursive=True, max_depth=1)
stac.run()
assert stac.message == [
{
"version": "1.0.0-rc.1",
"path": "tests/test_data/1rc1/collection.json",
"schema": [
"https://schemas.stacspec.org/v1.0.0-rc.1/collection-spec/json-schema/collection.json"
],
"asset_type": "COLLECTION",
"validation_method": "recursive",
"valid_stac": True,
"validator_engine": "jsonschema",
},
{
"version": "1.0.0-rc.1",
"path": "tests/test_data/1rc1/./simple-item.json",
"schema": [
"https://schemas.stacspec.org/v1.0.0-rc.1/item-spec/json-schema/item.json"
],
"asset_type": "ITEM",
"validation_method": "recursive",
"valid_stac": True,
"validator_engine": "jsonschema",
},
{
"version": "1.0.0-rc.1",
"path": "tests/test_data/1rc1/./core-item.json",
"schema": [
"https://schemas.stacspec.org/v1.0.0-rc.1/item-spec/json-schema/item.json"
],
"asset_type": "ITEM",
"validation_method": "recursive",
"valid_stac": True,
"validator_engine": "jsonschema",
},
{
"version": "1.0.0-rc.1",
"path": "tests/test_data/1rc1/./extended-item.json",
"schema": [
"https://cdn.staclint.com/v1.0.0-rc.1/extension/eo.json",
"https://cdn.staclint.com/v1.0.0-rc.1/extension/projection.json",
"https://cdn.staclint.com/v1.0.0-rc.1/extension/scientific.json",
"https://cdn.staclint.com/v1.0.0-rc.1/extension/view.json",
"https://schemas.stacspec.org/v1.0.0-rc.1/item-spec/json-schema/item.json",
],
"asset_type": "ITEM",
"validation_method": "recursive",
"valid_stac": True,
"validator_engine": "jsonschema",
},
]
def test_recursion_collection_local_v1rc2():
stac_file = "tests/test_data/1rc2/collection.json"
stac = stac_validator.StacValidate(stac_file, recursive=True, max_depth=1)
stac.run()
assert stac.message == [
{
"version": "1.0.0-rc.2",
"path": "tests/test_data/1rc2/collection.json",
"schema": [
"https://schemas.stacspec.org/v1.0.0-rc.2/collection-spec/json-schema/collection.json"
],
"asset_type": "COLLECTION",
"validation_method": "recursive",
"valid_stac": True,
"validator_engine": "jsonschema",
},
{
"version": "1.0.0-rc.2",
"path": "tests/test_data/1rc2/./simple-item.json",
"schema": [
"https://schemas.stacspec.org/v1.0.0-rc.2/item-spec/json-schema/item.json"
],
"asset_type": "ITEM",
"validation_method": "recursive",
"valid_stac": True,
"validator_engine": "jsonschema",
},
{
"version": "1.0.0-rc.2",
"path": "tests/test_data/1rc2/./core-item.json",
"schema": [
"https://schemas.stacspec.org/v1.0.0-rc.2/item-spec/json-schema/item.json"
],
"asset_type": "ITEM",
"validation_method": "recursive",
"valid_stac": True,
"validator_engine": "jsonschema",
},
{
"version": "1.0.0-rc.2",
"path": "tests/test_data/1rc2/./extended-item.json",
"schema": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/remote-data/v1.0.0/schema.json",
"https://schemas.stacspec.org/v1.0.0-rc.2/item-spec/json-schema/item.json",
],
"asset_type": "ITEM",
"validation_method": "recursive",
"valid_stac": True,
"validator_engine": "jsonschema",
},
]
def test_recursion_collection_local_2_v1rc2():
stac_file = "tests/test_data/1rc2/extensions-collection/collection.json"
stac = stac_validator.StacValidate(stac_file, recursive=True, max_depth=1)
stac.run()
assert stac.message == [
{
"version": "1.0.0-rc.2",
"path": "tests/test_data/1rc2/extensions-collection/collection.json",
"schema": [
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
"https://schemas.stacspec.org/v1.0.0-rc.2/collection-spec/json-schema/collection.json",
],
"asset_type": "COLLECTION",
"validation_method": "recursive",
"valid_stac": True,
"validator_engine": "jsonschema",
},
{
"version": "1.0.0-rc.2",
"path": "tests/test_data/1rc2/extensions-collection/./proj-example/proj-example.json",
"schema": [
"https://schemas.stacspec.org/v1.0.0-rc.2/item-spec/json-schema/item.json"
],
"asset_type": "ITEM",
"validation_method": "recursive",
"valid_stac": True,
"validator_engine": "jsonschema",
},
]
def test_recursion_without_max_depth():
stac_file = "tests/test_data/v100/catalog.json"
stac = stac_validator.StacValidate(stac_file, recursive=True)
stac.run()
assert len(stac.message) == 6
def test_recursion_with_bad_item():
stac_file = "tests/test_data/v100/catalog-with-bad-item.json"
stac = stac_validator.StacValidate(stac_file, recursive=True)
stac.run()
assert not stac.valid
assert len(stac.message) == 1
assert stac.message == [
{
"version": "1.0.0",
"path": "tests/test_data/v100/./bad-item.json",
"schema": [
"https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json"
],
"valid_stac": False,
"error_type": "JSONSchemaValidationError",
"failed_schema": "https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json",
"error_message": "'id' is a required property",
"recommendation": "For more accurate error information, rerun with --verbose.",
},
]
def test_recursion_with_bad_item_trace_recursion():
stac_file = "tests/test_data/v100/catalog-with-bad-item.json"
stac = stac_validator.StacValidate(stac_file, recursive=True, trace_recursion=True)
stac.run()
assert not stac.valid
assert len(stac.message) == 2
assert stac.message == [
{
"version": "1.0.0",
"path": "tests/test_data/v100/catalog-with-bad-item.json",
"schema": [
"https://schemas.stacspec.org/v1.0.0/catalog-spec/json-schema/catalog.json"
],
"valid_stac": True,
"asset_type": "CATALOG",
"validation_method": "recursive",
"validator_engine": "jsonschema",
},
{
"version": "1.0.0",
"path": "tests/test_data/v100/./bad-item.json",
"schema": [
"https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json"
],
"valid_stac": False,
"error_type": "JSONSchemaValidationError",
"failed_schema": "https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json",
"error_message": "'id' is a required property",
"recommendation": "For more accurate error information, rerun with --verbose.",
},
]
def test_recursion_with_bad_child_collection():
# It is important here that there is a second good child in the collection
# since a previous bug did not correctly set the valid variable if the last
# child passed validation
stac_file = "tests/test_data/v100/catalog-with-bad-child-collection.json"
stac = stac_validator.StacValidate(stac_file, recursive=True)
stac.run()
assert not stac.valid
assert len(stac.message) == 1
assert stac.message == [
{
"version": "1.0.0",
"path": "tests/test_data/v100/./collection-only/bad-collection.json",
"schema": [
"https://schemas.stacspec.org/v1.0.0/collection-spec/json-schema/collection.json"
],
"valid_stac": False,
"asset_type": "COLLECTION",
"validation_method": "recursive",
"validator_engine": "jsonschema",
"error_type": "JSONSchemaValidationError",
"failed_schema": "https://schemas.stacspec.org/v1.0.0/collection-spec/json-schema/collection.json",
"error_message": "'id' is a required property",
"recommendation": "For more accurate error information, rerun with --verbose.",
}
]
def test_recursion_with_missing_collection_link():
stac_file = "tests/test_data/v100/item-without-collection-link.json"
stac = stac_validator.StacValidate(stac_file, recursive=True)
assert not stac.run()
assert not stac.valid
assert len(stac.message) == 1
assert stac.message == [
{
"asset_type": "ITEM",
"version": "1.0.0",
"path": "tests/test_data/v100/item-without-collection-link.json",
"schema": [
"https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json"
],
"valid_stac": False,
"validation_method": "recursive",
"validator_engine": "jsonschema",
"error_type": "JSONSchemaValidationError",
"failed_schema": "https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json",
"error_message": "'simple-collection' should not be valid under {}. Error is in collection ",
"recommendation": "For more accurate error information, rerun with --verbose.",
},
]
|