Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: 2
jobs:
build:
branches:
only:
- dev
- master
- ci
working_directory: ~/circleci/stac-validator
docker:
- image: circleci/python:3.6.4
steps:
- checkout
- run: sudo chown -R circleci:circleci /usr/local/bin
- run: sudo chown -R circleci:circleci /usr/local/lib/python3.6/site-packages
- restore_cache:
key: v1-python-requirements-{{ checksum "requirements.txt" }}
- run:
command: |
pip install -r requirements.txt
- save_cache:
key: v1-python-requirements-{{ checksum "requirements.txt" }}
paths:
- "~/.cache/pip"
- "/usr/local/lib/python3.6/site-packages"
- run:
command: |
python -m pytest
24 changes: 17 additions & 7 deletions stac_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,9 @@ async def _validate_child(self, child_url, messages):

messages.append(stac.message)

if "valid_json" in stac.message and not stac.message["valid_json"]:
stac.message.pop("valid_json", None)
stac.status.pop("valid_json", None)
pass
if "error_type" in stac.message:
stac.message.pop("error_type", None)
stac.status.pop("error_type", None)
else:
self.status["catalogs"]["valid"] += stac.status["catalogs"]["valid"]
self.status["catalogs"]["invalid"] += stac.status["catalogs"]["invalid"]
Expand Down Expand Up @@ -221,10 +220,15 @@ async def run(self):
self.stac_file = data
except JSONDecodeError as e:
self.message["valid_stac"] = False
self.message["valid_json"] = False
self.message["error_type"] = "InvalidJSON"
self.message["error"] = f"{self.stac_file} is not Valid JSON"
self.status = self.message
return json.dumps(self.message)
# return json.dumps(self.message)
except FileNotFoundError as e:
self.message["valid_stac"] = False
self.message["error_type"] = "FileNotFoundError"
self.message["error"] = f"{self.stac_file} cannot be found"
self.status = self.message

# Check STAC Type
if "catalog" in self.fpath.stem:
Expand All @@ -239,7 +243,9 @@ async def run(self):
else:
self.status["catalogs"]["invalid"] += 1
self.message["children"] = await self.validate_catalog_contents()
elif any(field in Collections_Fields for field in self.stac_file.keys()):
elif (self.stac_file) is dict and (
field in Collections_Fields for field in self.stac_file.keys()
):
# Congratulations, It's a Collection!
# Collections will validate as catalog.
self.message["asset_type"] = "collection"
Expand All @@ -252,6 +258,10 @@ async def run(self):
else:
self.status["collections"]["invalid"] += 1
self.message["children"] = await self.validate_catalog_contents()
elif "error_type" in self.message:
self.message.pop("error_type", None)
self.status.pop("error_type", None)

else:
# Congratulations, It's an Item!
self.message["asset_type"] = "item"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_stac_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ def test_bad_url():
)
assert stac.status == {
"valid_stac": False,
"valid_json": False,
"error": "https://s3.amazonaws.com/spacenet-stac/spacenet-dataset/AOI_4_Shanghai_MUL-PanSharpen_Cloud is not Valid JSON",
"path": "https:/s3.amazonaws.com/spacenet-stac/spacenet-dataset/AOI_4_Shanghai_MUL-PanSharpen_Cloud"
}
assert stac.message == {
"valid_stac": False,
"valid_json": False,
"error": "https://s3.amazonaws.com/spacenet-stac/spacenet-dataset/AOI_4_Shanghai_MUL-PanSharpen_Cloud is not Valid JSON",
"path": "https:/s3.amazonaws.com/spacenet-stac/spacenet-dataset/AOI_4_Shanghai_MUL-PanSharpen_Cloud"
}