Fix for #3712 - invalid enum array validation in Python client mustache model (#3713)

* Fixed invalid enum array validation in Python client mustache model

* Updated the Petstore Python client tests

* Removed superfluous array enum test

* Added test cases for Python client array and map enums

* Improved map enum error message
This commit is contained in:
Bartek Kryza
2016-09-12 05:00:49 +02:00
committed by wing328
parent 72e051ab47
commit 6d6832e7a6
5 changed files with 298 additions and 6 deletions

View File

@@ -61,11 +61,31 @@ class {{classname}}(object):
"""
{{#isEnum}}
allowed_values = [{{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]
{{#isContainer}}
{{#isListContainer}}
if not set({{{name}}}).issubset(set(allowed_values)):
raise ValueError(
"Invalid values for `{{{name}}}` [{0}], must be a subset of [{1}]"
.format(", ".join(map(str, set({{{name}}})-set(allowed_values))),
", ".join(map(str, allowed_values)))
)
{{/isListContainer}}
{{#isMapContainer}}
if not set({{{name}}}.keys()).issubset(set(allowed_values)):
raise ValueError(
"Invalid keys in `{{{name}}}` [{0}], must be a subset of [{1}]"
.format(", ".join(map(str, set({{{name}}}.keys())-set(allowed_values))),
", ".join(map(str, allowed_values)))
)
{{/isMapContainer}}
{{/isContainer}}
{{^isContainer}}
if {{{name}}} not in allowed_values:
raise ValueError(
"Invalid value for `{{{name}}}` ({0}), must be one of {1}"
.format({{{name}}}, allowed_values)
)
{{/isContainer}}
{{/isEnum}}
{{^isEnum}}
{{#hasValidation}}