-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add schema validator with reference resolution and update tests…
… for extensions - Added JSON Schema validator (Draft202012Validator) with reference resolution for SCDEX core schema - Updated test cases to use the new validator from the test module - Added test case for new extensions (location-extensions.json, esponsible-recruiting.json)
- Loading branch information
Showing
3 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{ | ||
"$schema": "../../../schema/core-schema.json", | ||
"locations": [ | ||
{ | ||
"guid": "82d39ac8-1a12-4801-835a-85d319927548", | ||
"location-type": "factory", | ||
"language": "en", | ||
"products": [ | ||
"Accessories", | ||
"Hats" | ||
], | ||
"processing-types": [ | ||
"Final Product Assembly", | ||
"Cutting", | ||
"Embroidery", | ||
"Finishing", | ||
"Ironing", | ||
"Knitting" | ||
], | ||
"location-identifier": "osid:CN2021250D1DTN7", | ||
"name": "Huai An Yuan Tong Headwear Mfg. Co., Ltd.", | ||
"coordinates": { | ||
"latitude": 33.7862099, | ||
"longitude": 119.2787399 | ||
}, | ||
"address": { | ||
"street-name": "Yan Huang Avenue", | ||
"building-number": "No.30 & 32 & 99", | ||
"town-name": "Huaian", | ||
"country-sub-division": "Jiangsu", | ||
"country": "CN", | ||
"address-line": [ | ||
"No.30 & 32 & 99 Yan Huang Avenue", | ||
"Lian Shui Economic Developmental District", | ||
"Huaian, Jiangsu - China" | ||
] | ||
}, | ||
"responsible-recruiting": { | ||
"recruitment-fee": 200, | ||
"employer-coverage": 150, | ||
"initial-contact-date": "2024-01-15", | ||
"contract-signing-date": "2024-02-01", | ||
"first-paycheck-date": "2024-03-01" | ||
} | ||
} | ||
], | ||
"organizations": [ | ||
{ | ||
"guid": "91582fdd-6f72-47cf-a113-f68fe4e74865", | ||
"organization-type": "retailer", | ||
"language": "en", | ||
"organizational-identifier": "lei:3538002LJMRZ83SU0B85" | ||
}, | ||
{ | ||
"guid": "91582fdd-6f72-47cf-a113-f68fe4e74866", | ||
"organization-type": "retailer", | ||
"language": "en", | ||
"organizational-identifier": "lei:353800ZCXKHDPY0N5218" | ||
}, | ||
{ | ||
"guid": "91582fdd-6f72-47cf-a113-f68fe4e74867", | ||
"organization-type": "retailer", | ||
"language": "en", | ||
"organizational-identifier": "lei:549300D9GZ4BMLDW5T40" | ||
} | ||
], | ||
"affiliations": [ | ||
{ | ||
"from-guid": "82d39ac8-1a12-4801-835a-85d319927548", | ||
"to-guid": "91582fdd-6f72-47cf-a113-f68fe4e74865", | ||
"affiliation-type": "is supplier of" | ||
}, | ||
{ | ||
"from-guid": "82d39ac8-1a12-4801-835a-85d319927548", | ||
"to-guid": "91582fdd-6f72-47cf-a113-f68fe4e74866", | ||
"affiliation-type": "is supplier of" | ||
}, | ||
{ | ||
"from-guid": "82d39ac8-1a12-4801-835a-85d319927548", | ||
"to-guid": "91582fdd-6f72-47cf-a113-f68fe4e74867", | ||
"affiliation-type": "is supplier of" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
""" | ||
This module simply exposes the SCDEX JSON schema as a Python constant for use in testing. | ||
It also provides a JSON schema validator with reference resolution, configured to work with the SCDEX core schema and its dependencies. | ||
""" | ||
from pathlib import Path | ||
import json | ||
|
||
from jsonschema import Draft202012Validator, RefResolver | ||
|
||
SCDEX_SCHEMA_REPO_ROOT = Path(__file__).parent.parent.parent | ||
|
||
with open(SCDEX_SCHEMA_REPO_ROOT.joinpath("schema", "core-schema.json"), 'r') as f: | ||
_schema_content = f.read() | ||
|
||
SCDEX_JSON_SCHEMA = json.loads(_schema_content) | ||
|
||
resolver = RefResolver( | ||
base_uri=f'{SCDEX_SCHEMA_REPO_ROOT.joinpath("schema").resolve().as_uri()}/', # base directory for schema files | ||
referrer=SCDEX_JSON_SCHEMA | ||
) | ||
|
||
validator = Draft202012Validator(schema=SCDEX_JSON_SCHEMA, resolver=resolver) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters