Validators

A simple set of validation classes that are used to check entities in veritranspay.request, to give us some assurance they have provided the required data, in the required format, for Veritrans to accept the request.

(Although Veritrans will validate this data as well, this is done so we don’t waste time submitting data we can already know will be rejected).

When any of the Validators defined in this module fail, they raise a veritranspay.validators.ValidationError.

See the following for more details:

class veritranspay.validators.AddressValidator(*args, **kwargs)[source]

Bases: veritranspay.validators.RequiredValidator, veritranspay.validators.LengthValidator

Tests that a provided string is a valid length for address. If not required is_required should be set to false in the constructor.

class veritranspay.validators.CityValidator(*args, **kwargs)[source]

Bases: veritranspay.validators.NameValidator

Acts as an Alias for NameValidator, since their defined validation behavior is the same.

class veritranspay.validators.CountrycodeValidator(*args, **kwargs)[source]

Bases: veritranspay.validators.RequiredValidator, veritranspay.validators.LengthValidator

Validates that a country code is in a format that Veritrans accepts – which is any string less than 10 characters (note: their API documentation states this should be ISO 3166-1 Alpha 3)

class veritranspay.validators.DummyValidator(*args, **kwargs)[source]

Bases: veritranspay.validators.ValidatorBase

This is a special case validator that never fails validation and accepts and parameters passed to it’s constructor.

class veritranspay.validators.EmailValidator(*args, **kwargs)[source]

Bases: veritranspay.validators.RequiredValidator, veritranspay.validators.RegexValidator, veritranspay.validators.LengthValidator

Tests that a given string is less than 45 characters in length and vaguely appears to be in the proper format for an e-mail address.

class veritranspay.validators.LengthValidator(min_length=None, max_length=None, *args, **kwargs)[source]

Bases: veritranspay.validators.ValidatorBase

Asserts that a string’s length is between a given minimum and/or maximum length.

Creates a new instance of LengthValidator.

Parameters:
  • min_length (int) – Minimum required length for a string.
  • max_length – Maximum allowed length for a string.
class veritranspay.validators.NameValidator(*args, **kwargs)[source]

Bases: veritranspay.validators.RequiredValidator, veritranspay.validators.LengthValidator

Tests that a human name (eg, given or sirname) are at most 20 characters in length.

class veritranspay.validators.NumericValidator(is_required=True, *args, **kwargs)[source]

Bases: veritranspay.validators.RequiredValidator

Tests that the provided value is a python numeric type.

Creates a new instance of RequiredValidator.

Parameters:is_required (bool) – When True (or not provided), validate() will fail on None values.
class veritranspay.validators.PassthroughValidator(is_required=True, *args, **kwargs)[source]

Bases: veritranspay.validators.RequiredValidator

Allows validation of a subentity type that implements validators on it’s own properties. See request.ChargeRequest() for more information. If Value is an iterable, validate_all() will be called on each of it’s elements.

Creates a new instance of RequiredValidator.

Parameters:is_required (bool) – When True (or not provided), validate() will fail on None values.
class veritranspay.validators.PhoneValidator(*args, **kwargs)[source]

Bases: veritranspay.validators.RequiredValidator, veritranspay.validators.RegexValidator, veritranspay.validators.LengthValidator

Tests that a string looks like a phone number (between 5 and 19 characters) and only contains the characters 0-9, +, -, (, and ).

class veritranspay.validators.PostalcodeValidator(*args, **kwargs)[source]

Bases: veritranspay.validators.RequiredValidator, veritranspay.validators.RegexValidator, veritranspay.validators.LengthValidator

Tests that a string is a valid length and format for a Postal Code. It can be a maximum of 10 digits and may also contain spaces and hyphens (-).

class veritranspay.validators.RegexValidator(pattern, *args, **kwargs)[source]

Bases: veritranspay.validators.ValidatorBase

Tests a given string value against a regular expression.

Parameters:pattern (str) – A regular expression pattern.
class veritranspay.validators.RequiredValidator(is_required=True, *args, **kwargs)[source]

Bases: veritranspay.validators.ValidatorBase

Asserts that a value is not null when it’s is_required attribute is set to ‘True’

Creates a new instance of RequiredValidator.

Parameters:is_required (bool) – When True (or not provided), validate() will fail on None values.
class veritranspay.validators.StringValidator(is_required=True, *args, **kwargs)[source]

Bases: veritranspay.validators.RequiredValidator, veritranspay.validators.LengthValidator

Takes a string value. Can optionally required the string to not be null by setting is_required to True (it’s default), greater-than-or-equal to a min_length or less-than-or-equal-to a max_length.

Creates a new instance of RequiredValidator.

Parameters:is_required (bool) – When True (or not provided), validate() will fail on None values.
exception veritranspay.validators.ValidationError(message=None)[source]

Bases: exceptions.Exception

Raised whenever a validator in this module determines the value passed to .validate() fails validation.

class veritranspay.validators.ValidatorBase(*args, **kwargs)[source]

Bases: object

This should be the absolute base class for all validators. It doesn’t nothing special, but allows derrived classes to call .validate() on super() with reckless abandon!

validate(value)[source]

Given a value, raises a ValueError if validation fails, otherwise returns None.

Parameters:value – The object to test for Validation.