Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for urls/network documents #39

Merged
merged 2 commits into from
Sep 24, 2024
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ N.B. Make sure to install requirements via `pip`, not `conda` (at the time of wr
python -m tools.validator my.covjson
```

To test a server/api response, specify that the file source is an URL using the `--source` flag. Its default value is `file`

```sh
python -m tools.validator --source=url "https://mydomain.com/collections/cov"
```

## Testing the validator
```sh
python -m pytest
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
jsonschema
exhaust
pytest
pytest
requests
14 changes: 12 additions & 2 deletions tools/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,22 @@ def create_custom_validator(schema_id, schema_store=None):
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--source', type=str, choices=['url', 'file'], default='file', help='Source of the CoverageJSON document')
parser.add_argument('covjson_path', type=str,
help='Path to CoverageJSON document')

args = parser.parse_args()

with open(args.covjson_path, encoding="utf-8") as f:
obj = json.load(f)
if args.source == 'url':
import requests
# Get the file from the URL
response = requests.get(args.covjson_path)
response.raise_for_status() # Raise an exception if the request was unsuccessful
obj = response.json()
else:
# Assume the covjson_path is a local file
with open(args.covjson_path, encoding="utf-8") as f:
obj = json.load(f)

validator = create_custom_validator("/schemas/coveragejson")
validator.validate(obj)
Expand Down
Loading