model.input_checks¶
- check_type(value: Optional[Any], cls: Any, key: str) Optional[Any] [source]¶
Validate any input to be an instance a specific class.
- Parameters
value – value to check against
cls – check to see if the value is of type class
key – name of the object to display in the error message
- check_client(value: Client) Client [source]¶
Validate the input being a KE-chain Client.
- Parameters
value – the client to test
- check_uuid(uuid: Optional[str], key: Optional[str] = 'pk') Optional[str] [source]¶
Validate the UUID input to be a correct UUID.
- check_text(text: Optional[str], key: str) Optional[str] [source]¶
Validate text input to be a string.
- check_url(url: Optional[str], key: str = 'url') Optional[str] [source]¶
Validate text input to be a valid format URL.
- check_list_of_text(list_of_text: Optional[Iterable[str]], key: str, unique: bool = False) Optional[List[str]] [source]¶
Validate iterable input to be a list/tuple/set of strings.
- check_list_of_dicts(list_of_dicts: Optional[Iterable[Dict]], key: str, fields: Optional[List[str]] = None) Optional[List[Dict]] [source]¶
Validate iterable input to be a list/tuple/set of dicts.
Optionally checking for required field names.
- Parameters
list_of_dicts – list of dicts
key – name of the object to display in the error message
fields – list of fields that are required in each dict
- Raises
IllegalArgumentError – if the list_of_dicts does not conform
- Returns
the list of dicts
- check_enum(value: Optional[Any], enum: EnumMeta, key: str) Optional[Any] [source]¶
Validate input to be an option from an enum class.
- check_datetime(dt: Optional[Union[datetime, str]], key: str) Optional[str] [source]¶
Validate a datetime value to be a datetime and be timezone aware.
- check_base(obj: Optional[Any], cls: Optional[type] = None, key: Optional[str] = 'object', method: Optional[Callable] = None) Optional[str] [source]¶
Validate whether the object provided is instance of Base (or subclass) and return its ID.
When the obj is None, it returns None. Otherwise it will check if the object is a pykechain class and will extract the UUID from it.
It will NOT check if the uuid (if a UUID is provided) is an actual class. It won’t lookup the UUID in KE-chain and check that against the corresponding pykechain class.
- Parameters
obj – Object that needs the checking.
cls – (optional) See if the object is of a certain pykechain Class (subclass of Base)
key – (optional) a key that may be provided to improve the legability of the provided Error
method – (optional) a method or function that is used to convert the object into an instance that has the attribute ‘id’.
- Returns
None or UUID
- Raises
IllegalArgumentError – When the object is not of type of the class or not a UUID.
- check_user(obj: Optional[Any], cls: Optional[type] = None, key: Optional[str] = 'user', method: Optional[Callable] = None) Optional[int] [source]¶
Provide same functionality as check_base(), although users dont use UUID but integers.
- check_list_of_base(objects: Optional[List[Any]], cls: Optional[type] = None, key: Optional[str] = 'objects', method: Optional[Callable] = None) Optional[List[str]] [source]¶
Validate the iterable of objects are instance of Base (or subclass) and return a list of IDs.
- Parameters
objects – list of objects to check
cls – (optional) class to check objects against
key – (optional) key to check
method – (optional) method or function used to extract the id of the object (defaults id)
- Returns
list of UUID’s in Text.
- check_json(value: Union[dict, list], schema: dict, key: Optional[str] = None) bool [source]¶
Validate value against a jsonschema.
- Parameters
value – a dictionary or list that is to be validated against a jsonschema
schema – the jsonschema in a jsonschema format
key – the key to name inside the exception
- Returns
The value when passing, when not passing it raises a jsonschema.ValidationError
- Raises
jsonschema.ValidationError – When the json is not conforming the jsonschame
jsonschema.SchemaError – When the schema is incorrect.