Skip to content
Open
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ clean:
clean-import: clean import
@echo "✓ Clean import complete!"

test: setup
test: setup fetch-schemas
@echo "Running unit tests..."
@$(PYTHON) -m unittest discover tests -v

Expand Down
7 changes: 7 additions & 0 deletions data/wash-media/generic/water.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
slug: water
uuid: 78c9e93b-94dc-4c63-af42-4bce6304142f
brand:
slug: generic
name: Water
density: 1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

density ma jednotku kg/m^3 pokud vim. Tzn voda -> 1000

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, moje chyba kotroloval jsem s exportem https://specs.prusa3d.tech/architecture/#/auxiliary_media?id=slawashmedium, kde posledni upravy nejsou propsane.

wash_capacity: 10000
2 changes: 1 addition & 1 deletion schema_version.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# OpenPrintTag Schema Configuration
SCHEMA_REPO_URL="https://github.com/OpenPrintTag/openprinttag-architecture.git"
SCHEMA_COMMIT="438a81fb5ae1c3c21a1c23ba00c309db0a337da0"
SCHEMA_COMMIT="328e859465f9a3c499e69f141a7bc3c16273e911"
SCHEMA_SPARSE_PATH="schema/generated/opt_db_schema"
SCHEMA_TARGET_DIR="./openprinttag"
4 changes: 4 additions & 0 deletions scripts/validate_json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class JsonSchemaValidator:
'materials': 'material.schema.json',
'material-packages': 'material_package.schema.json',
'material-containers': 'material_container.schema.json',
'wash-media': 'wash_medium.schema.json',
}

# Foreign key definitions: entity -> [(field_path, target_entity, target_field, is_array, condition)]
Expand All @@ -68,6 +69,9 @@ class JsonSchemaValidator:
'brands': [
(['countries_of_origin'], 'countries', 'code', True, None),
],
'wash-media': [
(['brand', 'slug'], 'brands', 'slug', False, None),
],
}

def __init__(self, base_path: Path):
Expand Down
64 changes: 64 additions & 0 deletions tests/test_validate_wash_media.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""
Tests that wash-media entities are actually validated by validate_json_schema.py.
"""

import shutil
import sys
import tempfile
import unittest
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parent.parent))
sys.path.insert(0, str(Path(__file__).parent.parent / "scripts"))

from scripts.validate_json_schema import JsonSchemaValidator

REPO_ROOT = Path(__file__).parent.parent


class TestWashMediaValidation(unittest.TestCase):
"""Confirm the wash-media data directory is wired into the validator."""

def test_generic_water_is_validated_without_errors(self):
"""The real data/wash-media tree should be picked up and pass validation."""
validator = JsonSchemaValidator(REPO_ROOT)
count = validator.validate_entity_directory('wash-media', validator.ENTITY_SCHEMA_MAPPING['wash-media'])

self.assertGreaterEqual(count, 1, "no wash-media files were found/validated")
wash_media_errors = [e for e in validator.errors if e.entity == 'wash-media']
self.assertEqual(
[str(e) for e in wash_media_errors], [],
"wash-media data failed schema validation"
)

def test_invalid_wash_medium_is_rejected(self):
"""A wash medium with a non-numeric density must be caught by the validator."""
temp_dir = Path(tempfile.mkdtemp())
self.addCleanup(shutil.rmtree, temp_dir, ignore_errors=True)

wash_media_dir = temp_dir / "wash-media" / "generic"
wash_media_dir.mkdir(parents=True)
(wash_media_dir / "bad-water.yaml").write_text(
"slug: bad-water\n"
"uuid: 78c9e93b-94dc-4c63-af42-4bce6304142f\n"
"brand:\n"
" slug: generic\n"
"name: Bad Water\n"
"density: not-a-number\n"
"wash_capacity: 10000\n"
)

validator = JsonSchemaValidator(REPO_ROOT)
validator.data_dir = temp_dir # schema_dir stays pointed at the real, current schema

validator.validate_entity_directory('wash-media', validator.ENTITY_SCHEMA_MAPPING['wash-media'])

schema_errors = [e for e in validator.errors if e.rule == 'schema_validation']
self.assertTrue(
schema_errors,
"validator did not flag a wash medium with a non-numeric density"
)


if __name__ == '__main__':
unittest.main()
Loading