Validators
SmarterValidator is a utiility helper class that extends Django’s built-in validators to provide enhanced validation capabilities tailored for the Smarter platform. All methods are static, allowing for easy access without instantiating the class.
- class smarter.lib.django.validators.SmarterValidator[source]
Bases:
objectClass for validating various data types. Before adding anything to this class, please first check if there is a built-in Python function or a Django utility that can do the validation.
Todo
add import validators and study this library to see what can be removed and/or refactored here see https://python-validators.github.io/validators/
- LOCAL_HOSTS = ['localhost', '127.0.0.1', 'localhost:9357', '127.0.0.1:9357', 'testserver']
List of local hosts used for validation purposes.
- LOCAL_URLS = ['http://localhost', 'http://127.0.0.1', 'http://localhost:9357', 'http://127.0.0.1:9357', 'http://testserver', 'https://localhost', 'https://127.0.0.1', 'https://localhost:9357', 'https://127.0.0.1:9357', 'https://testserver']
List of local URLs used for validation purposes.
- SMARTER_ACCOUNT_NUMBER_REGEX = '\\b\\d{4}-\\d{4}-\\d{4}\\b'
Regex for matching Smarter account numbers in text.
- VALID_ACCOUNT_NUMBER_PATTERN = '^\\d{4}-\\d{4}-\\d{4}$'
Pattern for validating Smarter account numbers.
- VALID_ALPHNUMERIC_NO_SPACES_PATTERN = '^[a-zA-Z0-9]+$'
Pattern for validating alphanumeric strings with no spaces.
- VALID_CAMEL_CASE = '^[a-zA-Z0-9]+(?:[A-Z][a-z0-9]+)*$'
Pattern for validating camel case strings.
- VALID_CLEAN_STRING = '^(?!-)[A-Za-z0-9_-]{1,63}(?<!-)(\\.[A-Za-z0-9_-]{1,63})*$'
Pattern for validating clean strings.
- VALID_CLEAN_STRING_WITH_SPACES = "^[\\w\\-\\.~:\\/\\?#\\[\\]@!$&'()*+,;= %]+$"
Pattern for validating clean strings that may include spaces.
- VALID_EMAIL_PATTERN = '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$'
Pattern for validating email addresses.
- VALID_HOSTNAME_PATTERN = '^(?!-)[A-Za-z0-9_-]{1,63}(?<!-)$'
Pattern for validating hostnames.
- VALID_PASCAL_CASE = '^[A-Z][a-z0-9]+(?:[A-Z][a-z0-9]+)*$'
Pattern for validating pascal case strings.
- VALID_PORT_PATTERN = '^[0-9]{1,5}$'
Pattern for validating port numbers.
- VALID_SEMANTIC_VERSION = '^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(-(0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(\\.(0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(\\+[0-9a-zA-Z-]+(\\.[0-9a-zA-Z-]+)*)?$'
Pattern for validating semantic version strings.
- VALID_SESSION_KEY = '^[a-fA-F0-9]{64}$'
Pattern for validating Smarter session keys.
- VALID_SNAKE_CASE = '^[a-z0-9]+(?:_[a-z0-9]+)*$'
Pattern for validating snake case strings.
- VALID_URL_ENDPOINT = '^/[a-zA-Z0-9/_\\-\\{\\}]+/$'
Pattern for validating URL endpoints.
- VALID_URL_FRIENDLY_STRING = '^[a-zA-Z0-9._/-]+$'
Pattern for validating URL slugs (alphanumeric, hyphens, underscores).
- VALID_URL_PATTERN = '^(http|https)://[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}(:[0-9]{1,5})?$'
Pattern for validating URLs.
- VALID_UUID_PATTERN = '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'
Pattern for validating UUIDs.
- static base_domain(url)[source]
Get the base domain from a URL.
Extracts the base domain from the provided URL string.
- Parameters:
url (
str) – The URL string to extract the base domain from.- Returns:
The base domain as a string, or None if not found.
- Return type:
Example:
SmarterValidator.base_domain("https://example.com/path/") # returns "example.com" SmarterValidator.base_domain("") # returns None
- static base_url(url)[source]
Get the base URL from a URL.
Extracts the base URL from the provided URL string.
- Parameters:
url (
str) – The URL string to extract the base URL from.- Returns:
The base URL as a string, or None if not found.
- Return type:
Example:
SmarterValidator.base_url("https://example.com/path/") # returns "https://example.com" SmarterValidator.base_url("") # returns None
- static is_api_endpoint(url)[source]
Check if the URL is an API endpoint.
Checks whether the provided URL contains ‘/api/’.
- Parameters:
url (
str) – The URL to check.- Returns:
True if the URL is an API endpoint, otherwise False.
- Return type:
Example:
SmarterValidator.is_api_endpoint("/api/v1/tests/unauthenticated/list/") # returns True SmarterValidator.is_api_endpoint("/v1/tests/unauthenticated/list/") # returns False
- static is_not_none(value)[source]
Check if the value is not None
Checks whether the provided value is not None and not empty.
- Parameters:
value (
str) – The value to check.- Returns:
True if the value is not None and not empty, otherwise False.
- Return type:
Example:
SmarterValidator.is_not_none("something") # returns True SmarterValidator.is_not_none(None) # returns False
- static is_valid_account_number(account_number)[source]
Check if account number is valid
Checks whether the provided account number is valid.
- Parameters:
account_number (
str) – The account number to check.- Returns:
True if the account number is valid, otherwise False.
- Return type:
Example:
SmarterValidator.is_valid_account_number("1234-5678-9012") # returns True SmarterValidator.is_valid_account_number("invalid") # returns False
- static is_valid_camel_case(value)[source]
Check if the value is valid camel case
Checks whether the provided string is in camel case format.
- Parameters:
value (
str) – The string to check.- Returns:
True if the value is valid camel case, otherwise False.
- Return type:
Example:
SmarterValidator.is_valid_camel_case("myCamelCase") # returns True SmarterValidator.is_valid_camel_case("NotCamelCase") # returns False
- static is_valid_chatbot_slug(slug)[source]
Check if chatbot slug is valid
Checks whether the provided chatbot slug is valid.
- Parameters:
slug (
str) – The chatbot slug to check.- Returns:
True if the chatbot slug is valid, otherwise False.
- Return type:
Example:
SmarterValidator.is_valid_chatbot_slug("example-slug") # returns True SmarterValidator.is_valid_chatbot_slug("invalid slug") # returns False
- static is_valid_cleanstring(v)[source]
Check if hostname is valid
Checks whether the provided hostname is valid.
- Parameters:
hostname (str) – The hostname to check.
- Returns:
True if the hostname is valid, otherwise False.
- Return type:
Example:
SmarterValidator.is_valid_hostname("example.com") # returns True SmarterValidator.is_valid_hostname("invalid_hostname!") # returns False
- static is_valid_domain(domain)[source]
Check if domain is valid
Checks whether the provided domain is valid.
- Parameters:
domain (
str) – The domain to check.- Returns:
True if the domain is valid, otherwise False.
- Return type:
Example:
SmarterValidator.is_valid_domain("example.com") # returns True SmarterValidator.is_valid_domain("invalid_domain") # returns False
- static is_valid_email(email)[source]
Check if email is valid
Checks whether the provided email address is valid.
- Parameters:
email (
str) – The email address to check.- Returns:
True if the email address is valid, otherwise False.
- Return type:
Example:
SmarterValidator.is_valid_email("user@example.com") # returns True SmarterValidator.is_valid_email("invalid") # returns False
- static is_valid_hostname(hostname)[source]
Check if URL is valid
Checks whether the provided URL is valid.
- Parameters:
url (str) – The URL to check.
- Returns:
True if the URL is valid, otherwise False.
- Return type:
Example:
SmarterValidator.is_valid_url("https://example.com") # returns True SmarterValidator.is_valid_url("invalid_url") # returns False
- static is_valid_http_request_header_key(key)[source]
Check if HTTP request header key is valid
Checks whether the provided HTTP request header key is valid.
- Parameters:
key (
str) – The HTTP header key to check.- Returns:
True if the header key is valid, otherwise False.
- Return type:
Example:
SmarterValidator.is_valid_http_request_header_key("X-Custom-Header") # returns True SmarterValidator.is_valid_http_request_header_key("Invalid Header!") # returns False
- static is_valid_http_request_header_value(value)[source]
Check if HTTP request header value is valid
Checks whether the provided HTTP request header value is valid.
- static is_valid_ip(ip)[source]
Check if IP address is valid
Checks whether the provided IP address is valid.
- Parameters:
ip (
str) – The IP address to check.- Returns:
True if the IP address is valid, otherwise False.
- Return type:
Example:
SmarterValidator.is_valid_ip("192.168.1.1") # returns True SmarterValidator.is_valid_ip("invalid") # returns False
- static is_valid_json(value)[source]
Check if the value is valid JSON
Checks whether the provided string is valid JSON.
- Parameters:
value (
str) – The string to check.- Returns:
True if the value is valid JSON, otherwise False.
- Return type:
Example:
SmarterValidator.is_valid_json('{"key": "value"}') # returns True SmarterValidator.is_valid_json('not json') # returns False
- static is_valid_pascal_case(value)[source]
Check if the value is valid pascal case
Checks whether the provided string is in pascal case format.
- Parameters:
value (
str) – The string to check.- Returns:
True if the value is valid pascal case, otherwise False.
- Return type:
Example:
SmarterValidator.is_valid_pascal_case("MyPascalCase") # returns True SmarterValidator.is_valid_pascal_case("notPascalCase") # returns False
- static is_valid_port(port)[source]
Check if port is valid
Checks whether the provided port is valid.
- Parameters:
port (
str) – The port to check.- Returns:
True if the port is valid, otherwise False.
- Return type:
Example:
SmarterValidator.is_valid_port("8080") # returns True SmarterValidator.is_valid_port("invalid") # returns False
- static is_valid_semantic_version(version)[source]
Check if the semantic version is valid
Checks whether the provided string is a valid semantic version.
- Parameters:
version (
str) – The version string to check.- Returns:
True if the version is valid semantic version, otherwise False.
- Return type:
Example:
SmarterValidator.is_valid_semantic_version("1.2.3") # returns True SmarterValidator.is_valid_semantic_version("1.2") # returns False
- static is_valid_session_key(session_key)[source]
Check if session key is valid
Checks whether the provided session key is valid.
- Parameters:
session_key (
str) – The session key to check.- Returns:
True if the session key is valid, otherwise False.
- Return type:
Example:
SmarterValidator.is_valid_session_key("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef") # returns True SmarterValidator.is_valid_session_key("invalid") # returns False
- static is_valid_snake_case(value)[source]
Check if the value is valid snake case
Checks whether the provided string is in snake case format.
- Parameters:
value (
str) – The string to check.- Returns:
True if the value is valid snake case, otherwise False.
- Return type:
Example:
SmarterValidator.is_valid_snake_case("my_snake_case") # returns True SmarterValidator.is_valid_snake_case("NotSnakeCase") # returns False
- static is_valid_url(url)[source]
Check if URL is valid
Checks whether the provided URL is valid.
- Parameters:
url (
str) – The URL to check.- Returns:
True if the URL is valid, otherwise False.
- Return type:
Example:
SmarterValidator.is_valid_url("https://example.com") # returns True SmarterValidator.is_valid_url("invalid_url") # returns False
- static is_valid_url_endpoint(url)[source]
Check if the URL is valid and ends with a trailing slash.
Checks whether the provided URL is valid and ends with a trailing slash.
- Parameters:
url (
str) – The URL to check.- Returns:
True if the URL is valid and ends with a trailing slash, otherwise False.
- Return type:
Example:
SmarterValidator.is_valid_url_endpoint("/api/v1/tests/unauthenticated/list/") # returns True SmarterValidator.is_valid_url_endpoint("/api/v1/tests/unauthenticated/list") # returns False
- static is_valid_url_path(url_path)[source]
Check if URL path is valid
Checks whether the provided URL path is valid.
- Parameters:
url_path (
str) – The URL path to check.- Returns:
True if the URL path is valid, otherwise False.
- Return type:
Example:
SmarterValidator.is_valid_url_path("/api/v1/tests/unauthenticated/list/") # returns True SmarterValidator.is_valid_url_path("invalid_url_path") # returns False
- static is_valid_username(username)[source]
Check if username is valid
Checks whether the provided username is valid.
- Parameters:
username (
str) – The username to check.- Returns:
True if the username is valid, otherwise False.
- Return type:
Example:
SmarterValidator.is_valid_username("valid_username") # returns True SmarterValidator.is_valid_username("invalid username") # returns False
- static is_valid_uuid(uuid)[source]
Check if UUID is valid
Checks whether the provided UUID is valid.
- Parameters:
uuid (
str) – The UUID string to check.- Returns:
True if the UUID is valid, otherwise False.
- Return type:
Example:
SmarterValidator.is_valid_uuid("123e4567-e89b-12d3-a456-426614174000") # returns True SmarterValidator.is_valid_uuid("invalid") # returns False
- static leading_slash(path)[source]
ensure that URL path starts with a leading slash
Appends a leading slash to the URL path if it does not already have one.
- Parameters:
path (
str) – The URL path to process.- Returns:
The URL path with a leading slash, or None if the input is empty.
- Return type:
Example:
SmarterValidator.leading_slash("api/v1/resource/") # returns "/api/v1/resource/" SmarterValidator.leading_slash("/api/v1/resource/") # returns "/api/v1/resource/" SmarterValidator.leading_slash("") # returns None
- static trailing_slash(url)[source]
ensure that URL ends with a trailing slash
Appends a trailing slash to the URL if it does not already have one.
- Parameters:
url (
str) – The URL to process.- Returns:
The URL with a trailing slash, or None if the input is empty.
- Return type:
Example:
SmarterValidator.trailing_slash("https://example.com") # returns "https://example.com/" SmarterValidator.trailing_slash("https://example.com/") # returns "https://example.com/" SmarterValidator.trailing_slash("") # returns None
- static urlify(url, scheme=None, environment='local')[source]
ensure that URL starts with http:// or https:// and ends with a trailing slash
Ensures the provided URL starts with a valid scheme (http or https) and ends with a trailing slash.
- Parameters:
- Returns:
The normalized URL with scheme and trailing slash.
- Return type:
Example:
SmarterValidator.urlify("example.com") # returns "https://example.com/" SmarterValidator.urlify("example.com", scheme="http") # returns "http://example.com/" SmarterValidator.urlify("https://example.com") # returns "https://example.com/"
- static validate_account_number(account_number)[source]
Validate account number format
Checks if the provided string is a valid account number in the format XXXX-XXXX-XXXX.
- Parameters:
account_number (
str) – The account number to validate.- Raises:
SmarterValueError – If the account number is not valid.
- Returns:
The validated account number.
- Return type:
Example:
SmarterValidator.validate_account_number("1234-5678-9012") # returns "1234-5678-9012" SmarterValidator.validate_account_number("invalid") # raises SmarterValueError
- static validate_camel_case(value)[source]
Validate camel case format
Checks if the provided string is in camel case format.
- Parameters:
value (
str) – The string to validate.- Raises:
SmarterValueError – If the value is not in camel case format.
- Returns:
The validated camel case string.
- Return type:
Example:
SmarterValidator.validate_camel_case("myCamelCase") # returns "myCamelCase" SmarterValidator.validate_camel_case("NotCamelCase") # raises SmarterValueError
- static validate_chatbot_slug(slug)[source]
Validate chatbot slug format
Checks if the provided string is a valid chatbot slug.
- Parameters:
slug (
str) – The chatbot slug to validate.- Raises:
SmarterValueError – If the chatbot slug is not valid.
- Returns:
The validated chatbot slug.
- Return type:
Example:
SmarterValidator.validate_chatbot_slug("example-slug") # returns "example-slug" SmarterValidator.validate_chatbot_slug("invalid slug") # raises SmarterValueError
- static validate_clean_string(v)[source]
Validate clean string format
Checks if the provided string is a valid “clean” string (alphanumeric, underscores, or hyphens, and may include dots).
- Parameters:
v (
str) – The string to validate.- Raises:
SmarterValueError – If the string is not a valid clean string.
- Returns:
The validated clean string.
- Return type:
Example:
SmarterValidator.validate_clean_string("valid_string-123") # returns "valid_string-123" SmarterValidator.validate_clean_string("invalid string!") # raises SmarterValueError
- static validate_domain(domain)[source]
Validate domain format
Checks if the provided string is a valid domain.
- Parameters:
- Raises:
SmarterValueError – If the domain is not valid.
- Returns:
The validated domain or None.
- Return type:
Example:
SmarterValidator.validate_domain("example.com") # returns "example.com" SmarterValidator.validate_domain("invalid_domain") # raises SmarterValueError
- static validate_email(email)[source]
Validate email format
Checks if the provided string is a valid email address.
- Parameters:
email (
str) – The email address to validate.- Raises:
SmarterValueError – If the email address is not valid.
- Returns:
The validated email address.
- Return type:
Example:
SmarterValidator.validate_email("user@example.com") # returns "user@example.com" SmarterValidator.validate_email("invalid") # raises SmarterValueError
- static validate_hostname(hostname)[source]
Validate hostname format
Checks if the provided string is a valid hostname.
- Parameters:
hostname (
str) – The hostname to validate.- Raises:
SmarterValueError – If the hostname is not valid.
- Returns:
The validated hostname.
- Return type:
Example:
SmarterValidator.validate_hostname("example.com") # returns "example.com" SmarterValidator.validate_hostname("invalid_hostname!") # raises SmarterValueError
- static validate_http_request_header_key(key)[source]
Validate HTTP request header key format
HTTP header name must be ASCII and cannot contain special characters like ()<>@,;:”/[]?={}
- Parameters:
key (
str) – The HTTP header key to validate.- Raises:
SmarterValueError – If the header key contains invalid characters or is not ASCII.
- Returns:
The validated header key.
- Return type:
Example:
SmarterValidator.validate_http_request_header_key("X-Custom-Header") # returns "X-Custom-Header" SmarterValidator.validate_http_request_header_key("Invalid Header!") # raises SmarterValueError
- static validate_http_request_header_value(value)[source]
Validate HTTP request header value format HTTP header value must not contain control characters like escaped nor special characters.
- static validate_ip(ip)[source]
Validate IP address format
Checks if the provided string is a valid IP address.
- Parameters:
ip (
str) – The IP address to validate.- Raises:
SmarterValueError – If the IP address is not valid.
- Returns:
The validated IP address.
- Return type:
Example:
SmarterValidator.validate_ip("192.168.1.1") # returns "192.168.1.1" SmarterValidator.validate_ip("invalid") # raises SmarterValueError
- static validate_is_not_none(value)[source]
Validate that the value is not None
Checks if the provided value is not None and not empty.
- Parameters:
value (
str) – The value to validate.- Raises:
SmarterValueError – If the value is None or empty.
- Returns:
The validated value.
- Return type:
Example:
SmarterValidator.validate_is_not_none("something") # returns "something" SmarterValidator.validate_is_not_none(None) # raises SmarterValueError
- static validate_json(value)[source]
Validate JSON format
Checks if the provided string is valid JSON.
- Parameters:
value (
str) – The string to validate.- Raises:
SmarterValueError – If the value is not valid JSON.
- Returns:
The validated JSON string.
- Return type:
Example:
SmarterValidator.validate_json('{"key": "value"}') # returns '{"key": "value"}' SmarterValidator.validate_json('not json') # raises SmarterValueError
- static validate_list_of_account_numbers(account_numbers)[source]
Validate list of account numbers
Checks if each item in the provided list is a valid account number.
- Parameters:
account_numbers (
list) – The list of account numbers to validate.- Raises:
SmarterValueError – If any account number in the list is not valid.
- Returns:
None if all account numbers are valid.
- Return type:
Example:
SmarterValidator.validate_list_of_account_numbers(["1234-5678-9012", "2345-6789-0123"]) # returns None SmarterValidator.validate_list_of_account_numbers(["invalid", "2345-6789-0123"]) # raises SmarterValueError
- static validate_list_of_domains(domains)[source]
Validate list of domains
Checks if each item in the provided list is a valid domain.
- Parameters:
domains (
list) – The list of domains to validate.- Raises:
SmarterValueError – If any domain in the list is not valid.
- Returns:
None if all domains are valid.
- Return type:
Example:
SmarterValidator.validate_list_of_domains(["example.com", "test.com"]) # returns None SmarterValidator.validate_list_of_domains(["invalid_domain", "test.com"]) # raises SmarterValueError
- static validate_list_of_emails(emails)[source]
Validate list of emails
Checks if each item in the provided list is a valid email address.
- Parameters:
emails (
list) – The list of email addresses to validate.- Raises:
SmarterValueError – If any email address in the list is not valid.
- Returns:
None if all email addresses are valid.
- Return type:
Example:
SmarterValidator.validate_list_of_emails(["user@example.com", "admin@test.com"]) # returns None SmarterValidator.validate_list_of_emails(["invalid", "admin@test.com"]) # raises SmarterValueError
- static validate_list_of_ips(ips)[source]
Validate list of IP addresses
Checks if each item in the provided list is a valid IP address.
- Parameters:
ips (
list) – The list of IP addresses to validate.- Raises:
SmarterValueError – If any IP address in the list is not valid.
- Returns:
None if all IP addresses are valid.
- Return type:
Example:
SmarterValidator.validate_list_of_ips(["192.168.1.1", "10.0.0.1"]) # returns None SmarterValidator.validate_list_of_ips(["invalid", "10.0.0.1"]) # raises SmarterValueError
- static validate_list_of_ports(ports)[source]
Validate list of ports
Checks if each item in the provided list is a valid port.
- Parameters:
ports (
list) – The list of ports to validate.- Raises:
SmarterValueError – If any port in the list is not valid.
- Returns:
None if all ports are valid.
- Return type:
Example:
SmarterValidator.validate_list_of_ports(["8080", "443"]) # returns None SmarterValidator.validate_list_of_ports(["invalid", "443"]) # raises SmarterValueError
- static validate_list_of_urls(urls)[source]
Validate list of URLs
Checks if each item in the provided list is a valid URL.
- Parameters:
urls (
list) – The list of URLs to validate.- Raises:
SmarterValueError – If any URL in the list is not valid.
- Returns:
None if all URLs are valid.
- Return type:
Example:
SmarterValidator.validate_list_of_urls(["https://example.com", "https://test.com"]) # returns None SmarterValidator.validate_list_of_urls(["invalid_url", "https://test.com"]) # raises SmarterValueError
- static validate_list_of_uuids(uuids)[source]
Validate list of UUIDs
Checks if each item in the provided list is a valid UUID.
- Parameters:
uuids (
list) – The list of UUIDs to validate.- Raises:
SmarterValueError – If any UUID in the list is not valid.
- Returns:
None if all UUIDs are valid.
- Return type:
Example:
SmarterValidator.validate_list_of_uuids([ "123e4567-e89b-12d3-a456-426614174000", "987e6543-e21b-12d3-a456-426614174111" ]) # returns None SmarterValidator.validate_list_of_uuids([ "invalid", "987e6543-e21b-12d3-a456-426614174111" ]) # raises SmarterValueError
- static validate_no_spaces(value)[source]
Validate that the string does not contain spaces.
- Return type:
- static validate_pascal_case(value)[source]
Validate pascal case format
Checks if the provided string is in pascal case format.
- Parameters:
value (
str) – The string to validate.- Raises:
SmarterValueError – If the value is not in pascal case format.
- Returns:
The validated pascal case string.
- Return type:
Example:
SmarterValidator.validate_pascal_case("MyPascalCase") # returns "MyPascalCase" SmarterValidator.validate_pascal_case("notPascalCase") # raises SmarterValueError
- static validate_port(port)[source]
Validate port format
Checks if the provided string is a valid port number.
- Parameters:
port (
str) – The port to validate.- Raises:
SmarterValueError – If the port is not valid.
- Returns:
The validated port.
- Return type:
Example:
SmarterValidator.validate_port("8080") # returns "8080" SmarterValidator.validate_port("99999") # raises SmarterValueError
- static validate_semantic_version(version)[source]
Validate semantic version format (e.g., 1.12.1)
Checks if the provided string is a valid semantic version.
- Parameters:
version (
str) – The version string to validate.- Raises:
SmarterValueError – If the version is not a valid semantic version.
- Returns:
The validated semantic version string.
- Return type:
Example:
SmarterValidator.validate_semantic_version("1.2.3") # returns "1.2.3" SmarterValidator.validate_semantic_version("1.2") # raises SmarterValueError
- static validate_session_key(session_key)[source]
Validate session key format
Checks if the provided string is a valid session key.
- Parameters:
session_key (
str) – The session key to validate.- Raises:
SmarterValueError – If the session key is not valid.
- Returns:
The validated session key.
- Return type:
Example:
SmarterValidator.validate_session_key("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef") # returns the session key SmarterValidator.validate_session_key("invalid") # raises SmarterValueError
- static validate_snake_case(value)[source]
Validate snake case format
Checks if the provided string is in snake case format.
- Parameters:
value (
str) – The string to validate.- Raises:
SmarterValueError – If the value is not in snake case format.
- Returns:
None if the value is valid.
- Return type:
Example:
SmarterValidator.validate_snake_case("my_snake_case") # returns None SmarterValidator.validate_snake_case("NotSnakeCase") # raises SmarterValueError
- static validate_url(url)[source]
Validate URL format
Checks if the provided string is a valid URL.
- Parameters:
url (
str) – The URL to validate.- Raises:
SmarterValueError – If the URL is not valid.
- Returns:
The validated URL.
- Return type:
Example:
SmarterValidator.validate_url("https://example.com") # returns "https://example.com" SmarterValidator.validate_url("invalid_url") # raises SmarterValueError
- static validate_url_endpoint(url)[source]
Validate URL endpoint format
Checks if the provided string is a valid URL endpoint (must start and end with a slash).
- Parameters:
url (
str) – The URL endpoint to validate.- Raises:
SmarterValueError – If the URL endpoint is not valid.
- Returns:
None if the URL endpoint is valid.
- Return type:
Example:
SmarterValidator.validate_url_endpoint("/api/v1/tests/unauthenticated/list/") # returns None SmarterValidator.validate_url_endpoint("/api/v1/tests/unauthenticated/list") # raises SmarterValueError
- static validate_url_path(path)[source]
Validate URL path format
Checks if the provided string is a valid URL path.
- Parameters:
path (
str) – The URL path to validate.- Raises:
SmarterValueError – If the URL path is not valid.
- Returns:
The validated URL path.
- Return type:
Example:
SmarterValidator.validate_url_path("/api/v1/resource/") # returns "/api/v1/resource/" SmarterValidator.validate_url_path("invalid_path") # raises SmarterValueError
- static validate_username(username)[source]
Validate username format
Checks if the provided string is a valid username.
- Parameters:
username (
str) – The username to validate.- Raises:
SmarterValueError – If the username is not valid.
- Returns:
The validated username.
- Return type:
Example:
SmarterValidator.validate_username("valid_username") # returns "valid_username" SmarterValidator.validate_username("invalid username") # raises SmarterValueError
- static validate_uuid(uuid)[source]
Validate UUID format
Checks if the provided string is a valid UUID.
- Parameters:
uuid (
str) – The UUID string to validate.- Raises:
SmarterValueError – If the UUID is not valid.
- Returns:
The validated UUID.
- Return type:
Example:
SmarterValidator.validate_uuid("123e4567-e89b-12d3-a456-426614174000") # returns the UUID SmarterValidator.validate_uuid("invalid") # raises SmarterValueError