model.input_checks¶
- check_type(value: Any | None, cls: Any, key: str) Any | None [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: str | None, key: str | None = 'pk') str | None [source]¶
Validate the UUID input to be a correct UUID.
- check_url(url: str | None, key: str = 'url') str | None [source]¶
Validate text input to be a valid format URL.
- check_list_of_text(list_of_text: Iterable[str] | None, key: str, unique: bool = False) List[str] | None [source]¶
Validate iterable input to be a list/tuple/set of strings.
- check_list_of_dicts(list_of_dicts: Iterable[Dict] | None, key: str, fields: List[str] | None = None) List[Dict] | None [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: Any | None, enum: EnumMeta, key: str) Any | None [source]¶
Validate input to be an option from an enum class.
- check_datetime(dt: datetime | str | None, key: str) str | None [source]¶
Validate a datetime value to be a datetime and be timezone aware.
- check_date(dt: datetime | str | None, key: str) str | None [source]¶
Validate a date value to be a date.
- check_time(dt: datetime | str | None, key: str) str | None [source]¶
Validate a time value to be a time.
- check_base(obj: Any | None, cls: type | None = None, key: str | None = 'object', method: Callable | None = None) str | None [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: Any | None, cls: type | None = None, key: str | None = 'user', method: Callable | None = None) int | None [source]¶
Provide same functionality as check_base(), although users dont use UUID but integers.
- check_list_of_base(objects: List[Any] | None, cls: type | None = None, key: str | None = 'objects', method: Callable | None = None) List[str] | None [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: dict | list, schema: dict, key: str | None = 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.