MCPcopy Create free account
hub / github.com/bundesAPI/smard-api / check_allowed_values

Function check_allowed_values

python-client/deutschland/smard/model_utils.py:823–868  ·  view source on GitHub ↗

Raises an exception if the input_values are not allowed Args: allowed_values (dict): the allowed_values dict input_variable_path (tuple): the path to the input variable input_values (list/str/int/float/date/datetime): the values that we are checking to see if

(allowed_values, input_variable_path, input_values)

Source from the content-addressed store, hash-verified

821
822
823def check_allowed_values(allowed_values, input_variable_path, input_values):
824 """Raises an exception if the input_values are not allowed
825
826 Args:
827 allowed_values (dict): the allowed_values dict
828 input_variable_path (tuple): the path to the input variable
829 input_values (list/str/int/float/date/datetime): the values that we
830 are checking to see if they are in allowed_values
831 """
832 these_allowed_values = list(allowed_values[input_variable_path].values())
833 if isinstance(input_values, list) and not set(input_values).issubset(
834 set(these_allowed_values)
835 ):
836 invalid_values = (
837 ", ".join(map(str, set(input_values) - set(these_allowed_values))),
838 )
839 raise ApiValueError(
840 "Invalid values for `%s` [%s], must be a subset of [%s]"
841 % (
842 input_variable_path[0],
843 invalid_values,
844 ", ".join(map(str, these_allowed_values)),
845 )
846 )
847 elif isinstance(input_values, dict) and not set(input_values.keys()).issubset(
848 set(these_allowed_values)
849 ):
850 invalid_values = ", ".join(
851 map(str, set(input_values.keys()) - set(these_allowed_values))
852 )
853 raise ApiValueError(
854 "Invalid keys in `%s` [%s], must be a subset of [%s]"
855 % (
856 input_variable_path[0],
857 invalid_values,
858 ", ".join(map(str, these_allowed_values)),
859 )
860 )
861 elif (
862 not isinstance(input_values, (list, dict))
863 and input_values not in these_allowed_values
864 ):
865 raise ApiValueError(
866 "Invalid value for `%s` (%s), must be one of %s"
867 % (input_variable_path[0], input_values, these_allowed_values)
868 )
869
870
871def is_json_validation_enabled(schema_keyword, configuration=None):

Callers 2

__validate_inputsMethod · 0.90
set_attributeMethod · 0.85

Calls 1

ApiValueErrorClass · 0.90

Tested by

no test coverage detected