|
| 1 | +import json |
| 2 | +import os |
| 3 | +import unittest |
| 4 | + |
| 5 | + |
| 6 | +SCHEMA_PATH = os.path.join( |
| 7 | + os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), |
| 8 | + "src", |
| 9 | + "python_osw_validation", |
| 10 | + "schema", |
| 11 | + "opensidewalks.schema-0.3.json", |
| 12 | +) |
| 13 | + |
| 14 | + |
| 15 | +class TestSchemaDefinitionsExist(unittest.TestCase): |
| 16 | + @classmethod |
| 17 | + def setUpClass(cls): |
| 18 | + with open(SCHEMA_PATH, encoding="utf-8") as f: |
| 19 | + cls.schema = json.load(f) |
| 20 | + |
| 21 | + def test_definitions_present_with_required_fields(self): |
| 22 | + feature_requirements = { |
| 23 | + "Tree": ["geometry", "properties", "type"], |
| 24 | + "TreeFields": ["_id", "natural"], |
| 25 | + "TreeRow": ["geometry", "properties", "type"], |
| 26 | + "TreeRowFields": ["_id", "natural"], |
| 27 | + "CustomPoint": ["geometry", "properties", "type"], |
| 28 | + "CustomPointFields": ["_id"], |
| 29 | + "CustomLine": ["geometry", "properties", "type"], |
| 30 | + "CustomLineFields": ["_id"], |
| 31 | + "CustomPolygon": ["geometry", "properties", "type"], |
| 32 | + "CustomPolygonFields": ["_id"], |
| 33 | + "Wood": ["geometry", "properties", "type"], |
| 34 | + "WoodFields": ["_id", "natural"], |
| 35 | + } |
| 36 | + |
| 37 | + definitions = self.schema.get("definitions", {}) |
| 38 | + for name, required_fields in feature_requirements.items(): |
| 39 | + with self.subTest(definition=name): |
| 40 | + self.assertIn(name, definitions, f"{name} definition missing from schema") |
| 41 | + required = definitions[name].get("required", []) |
| 42 | + for field in required_fields: |
| 43 | + self.assertIn(field, required, f"{name} should require '{field}'") |
| 44 | + |
| 45 | + |
| 46 | +if __name__ == "__main__": |
| 47 | + unittest.main() |
0 commit comments