From b5d9578b6ec9467c7bf436f1fa7fe13430d2371c Mon Sep 17 00:00:00 2001 From: Rijnder Wever Date: Mon, 16 Dec 2024 19:37:40 +0100 Subject: [PATCH] oops: really add .validate() tests --- tests/test_custom_validate.py | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/test_custom_validate.py diff --git a/tests/test_custom_validate.py b/tests/test_custom_validate.py new file mode 100644 index 0000000..cb587e7 --- /dev/null +++ b/tests/test_custom_validate.py @@ -0,0 +1,43 @@ +import pytest + +from mdto.gegevensgroepen import * +from mdto import ValidationError + + +def test_validate_recursive(shared_informatieobject): + """Test validation in deeply nested structure.""" + shared_informatieobject.bewaartermijn = TermijnGegevens( + termijnTriggerStartLooptijd=BegripGegevens( + "V", + # IdentificatieGegevens is the incorrect child + IdentificatieGegevens("nvt", "nvt"), + ) + ) + + with pytest.raises( + ValidationError, match=r"\w+(\.\w+)+:\s+expected type \w+, got \w+" + ): + shared_informatieobject.validate() + + +def test_validate_url(shared_informatieobject): + """Test URL validation.""" + shared_informatieobject.raadpleeglocatie = RaadpleeglocatieGegevens( + raadpleeglocatieOnline="hppts://www.example.com" # misspelling + ) + + with pytest.raises( + ValidationError, + match=r"\w+(\.\w+)+:\s+url .* is malformed", + ): + shared_informatieobject.validate() + + +# def test_validate_nonrepeatable_fields(shared_informatieobject): +# """Test cardinality check during validation""" +# shared_informatieobject.raadpleeglocatie = RaadpleeglocatieGegevens( +# VerwijzingGegevens(["Regionaal Archief Rivierenland", "RAR"]) +# ) + +# with pytest.raises(ValidationError, match=r".+but field does not accept sequences"): +# shared_informatieobject.validate()