Skip to content

Commit 8eb4213

Browse files
committed
Create test_py_go_diff.py
1 parent 1bde2c2 commit 8eb4213

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

openapiart/tests/test_py_go_diff.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,78 @@ def test_iter_set_method(default_config):
2020
pass
2121

2222
assert isinstance(default_config.j[0], module.EObject)
23+
24+
25+
def test_validation_errors():
26+
p = module.Api().prefix_config()
27+
p.e
28+
try:
29+
p.validate()
30+
pytest.fail
31+
except Exception as e:
32+
assert "required field `prefix_config.a` must not be empty" in str(e)
33+
assert "required field `prefix_config.b` must not be empty" in str(e)
34+
assert "required field `prefix_config.c` must not be empty" in str(e)
35+
assert (
36+
"required field `prefix_config.required_object` must not be empty"
37+
in str(e)
38+
)
39+
assert "required field `prefix_config.e.e_a` must not be empty" in str(
40+
e
41+
)
42+
assert "required field `prefix_config.e.e_b` must not be empty" in str(
43+
e
44+
)
45+
46+
p.e.e_a = "abc"
47+
try:
48+
p.validate()
49+
except Exception as e:
50+
print(e)
51+
assert (
52+
"value of `prefix_config.e.e_a` must be a valid float type, instead of `abc`"
53+
in str(e)
54+
)
55+
p.a = "abc"
56+
p.b = 10.1
57+
p.c = 20
58+
p.required_object.e_a = 10.1
59+
p.required_object.e_b = 20
60+
p.j.add().j_a
61+
p.mac_pattern.mac.values = ["1", "20"]
62+
p.ipv4_pattern.ipv4.value = "1.1"
63+
errors = p._validate(p._JSON_NAME, True)
64+
assert len([True for e in errors if ".e_b` must not be empty" in e]) == 2
65+
assert (
66+
"required field `prefix_config.j[0].e_a` must not be empty" in errors
67+
)
68+
assert "required field `prefix_config.e.e_b` must not be empty" in errors
69+
assert (
70+
"value of `prefix_config.e.e_a` must be a valid float type, instead of `abc`"
71+
in errors
72+
)
73+
assert (
74+
"required field `prefix_config.j[0].e_a` must not be empty" in errors
75+
)
76+
assert (
77+
"required field `prefix_config.j[0].e_b` must not be empty" in errors
78+
)
79+
assert (
80+
"value of `prefix_config.mac_pattern.mac.values[0]` must be a valid mac string, instead of `1`"
81+
in errors
82+
)
83+
assert (
84+
"value of `prefix_config.mac_pattern.mac.values[1]` must be a valid mac string, instead of `20`"
85+
in errors
86+
)
87+
assert (
88+
"value of `prefix_config.ipv4_pattern.ipv4.value` must be a valid ipv4 string, instead of `1.1`"
89+
in errors
90+
)
91+
92+
93+
def test_enum_setter():
94+
p = module.Api().prefix_config()
95+
p.response = "abc"
96+
errors = p._validate(p._JSON_NAME, True)
97+
assert "abc is not a valid enum for property response" in errors

0 commit comments

Comments
 (0)