From 8eb4213ed01a17f0c954bc5b1f58a83cfd1107a3 Mon Sep 17 00:00:00 2001 From: Rangababu-R Date: Tue, 7 Jun 2022 15:52:35 +0530 Subject: [PATCH] Create test_py_go_diff.py --- openapiart/tests/test_py_go_diff.py | 75 +++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/openapiart/tests/test_py_go_diff.py b/openapiart/tests/test_py_go_diff.py index 86e78b79..ec37cb81 100644 --- a/openapiart/tests/test_py_go_diff.py +++ b/openapiart/tests/test_py_go_diff.py @@ -20,3 +20,78 @@ def test_iter_set_method(default_config): pass assert isinstance(default_config.j[0], module.EObject) + + +def test_validation_errors(): + p = module.Api().prefix_config() + p.e + try: + p.validate() + pytest.fail + except Exception as e: + assert "required field `prefix_config.a` must not be empty" in str(e) + assert "required field `prefix_config.b` must not be empty" in str(e) + assert "required field `prefix_config.c` must not be empty" in str(e) + assert ( + "required field `prefix_config.required_object` must not be empty" + in str(e) + ) + assert "required field `prefix_config.e.e_a` must not be empty" in str( + e + ) + assert "required field `prefix_config.e.e_b` must not be empty" in str( + e + ) + + p.e.e_a = "abc" + try: + p.validate() + except Exception as e: + print(e) + assert ( + "value of `prefix_config.e.e_a` must be a valid float type, instead of `abc`" + in str(e) + ) + p.a = "abc" + p.b = 10.1 + p.c = 20 + p.required_object.e_a = 10.1 + p.required_object.e_b = 20 + p.j.add().j_a + p.mac_pattern.mac.values = ["1", "20"] + p.ipv4_pattern.ipv4.value = "1.1" + errors = p._validate(p._JSON_NAME, True) + assert len([True for e in errors if ".e_b` must not be empty" in e]) == 2 + assert ( + "required field `prefix_config.j[0].e_a` must not be empty" in errors + ) + assert "required field `prefix_config.e.e_b` must not be empty" in errors + assert ( + "value of `prefix_config.e.e_a` must be a valid float type, instead of `abc`" + in errors + ) + assert ( + "required field `prefix_config.j[0].e_a` must not be empty" in errors + ) + assert ( + "required field `prefix_config.j[0].e_b` must not be empty" in errors + ) + assert ( + "value of `prefix_config.mac_pattern.mac.values[0]` must be a valid mac string, instead of `1`" + in errors + ) + assert ( + "value of `prefix_config.mac_pattern.mac.values[1]` must be a valid mac string, instead of `20`" + in errors + ) + assert ( + "value of `prefix_config.ipv4_pattern.ipv4.value` must be a valid ipv4 string, instead of `1.1`" + in errors + ) + + +def test_enum_setter(): + p = module.Api().prefix_config() + p.response = "abc" + errors = p._validate(p._JSON_NAME, True) + assert "abc is not a valid enum for property response" in errors