|
| 1 | +import json |
| 2 | + |
1 | 3 | import pytest
|
| 4 | +import requests_mock |
2 | 5 |
|
3 | 6 | from stac_check.lint import Linter
|
4 | 7 |
|
@@ -498,3 +501,65 @@ def test_lint_dict_item():
|
498 | 501 | assert linter.create_best_practices_dict()["datetime_null"] == [
|
499 | 502 | "Please avoid setting the datetime field to null, many clients search on this field"
|
500 | 503 | ]
|
| 504 | + |
| 505 | + |
| 506 | +def test_lint_header(): |
| 507 | + file = "sample_files/1.0.0/core-item.json" |
| 508 | + url = "https://localhost/" + file |
| 509 | + |
| 510 | + no_headers = {} |
| 511 | + valid_headers = {"x-api-key": "a-valid-api-key"} |
| 512 | + |
| 513 | + with requests_mock.Mocker(real_http=True) as mock, open(file) as json_data: |
| 514 | + mock.get(url, request_headers=no_headers, status_code=403, json={}) |
| 515 | + mock.get(url, request_headers=valid_headers, json=json.load(json_data)) |
| 516 | + |
| 517 | + linter = Linter(url, assets=False, headers=valid_headers) |
| 518 | + assert linter.message == { |
| 519 | + "version": "1.0.0", |
| 520 | + "path": "https://localhost/sample_files/1.0.0/core-item.json", |
| 521 | + "schema": [ |
| 522 | + "https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json" |
| 523 | + ], |
| 524 | + "valid_stac": True, |
| 525 | + "asset_type": "ITEM", |
| 526 | + "validation_method": "default", |
| 527 | + } |
| 528 | + |
| 529 | + linter = Linter(url, assets=False, headers=no_headers) |
| 530 | + assert linter.message == { |
| 531 | + "version": "", |
| 532 | + "path": "https://localhost/sample_files/1.0.0/core-item.json", |
| 533 | + "schema": [""], |
| 534 | + "valid_stac": False, |
| 535 | + "error_type": "HTTPError", |
| 536 | + "error_message": "403 Client Error: None for url: https://localhost/sample_files/1.0.0/core-item.json", |
| 537 | + } |
| 538 | + |
| 539 | + |
| 540 | +def test_lint_assets_no_links(): |
| 541 | + file = "sample_files/1.0.0/core-item.json" |
| 542 | + linter = Linter(file, assets=True, assets_open_urls=False) |
| 543 | + assert linter.message == { |
| 544 | + "version": "1.0.0", |
| 545 | + "path": file, |
| 546 | + "schema": [ |
| 547 | + "https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json" |
| 548 | + ], |
| 549 | + "valid_stac": True, |
| 550 | + "asset_type": "ITEM", |
| 551 | + "validation_method": "default", |
| 552 | + "assets_validated": { |
| 553 | + "format_valid": [ |
| 554 | + "https://storage.googleapis.com/open-cogs/stac-examples/20201211_223832_CS2_analytic.tif", |
| 555 | + "https://storage.googleapis.com/open-cogs/stac-examples/20201211_223832_CS2.jpg", |
| 556 | + "https://storage.googleapis.com/open-cogs/stac-examples/20201211_223832_CS2.tif", |
| 557 | + "https://storage.googleapis.com/open-cogs/stac-examples/20201211_223832_CS2_analytic_udm.tif", |
| 558 | + "http://remotedata.io/catalog/20201211_223832_CS2/extended-metadata.json", |
| 559 | + "http://cool-sat.com/catalog/20201211_223832_CS2/20201211_223832_CS2.EPH", |
| 560 | + ], |
| 561 | + "format_invalid": [], |
| 562 | + "request_valid": [], |
| 563 | + "request_invalid": [], |
| 564 | + }, |
| 565 | + } |
0 commit comments