"""Optimized property test strategies for enterprise testing.
import logging
logging.basicConfig(level=logging.DEBUG)
This module provides efficient Hypothesis strategies that avoid excessive filtering
and health check failures while maintaining comprehensive property-based testing.
"""
from __future__ import annotations
from typing import TYPE_CHECKING, Any
from hypothesis import strategies as st
from hypothesis.strategies import composite
if TYPE_CHECKING:
from collections.abc import Callable
# Enterprise-specific data strategies
@composite
def enterprise_connection_ids(draw: Callable[..., Any]) -> str:
"""Generate valid enterprise connection IDs without filtering."""
prefixes = [
"conn",
"ldap",
"db",
"api",
"enterprise",
"sync",
"auth",
"prod",
"test",
]
suffixes = ["001", "002", "123", "456", "789", "01", "02", "03", "04", "05"]
prefix = draw(st.sampled_from(prefixes))
suffix = draw(st.sampled_from(suffixes))
return f"{prefix}{suffix}"
@composite
def enterprise_domains(draw: Callable[..., Any]) -> str:
"""Generate valid enterprise domains without filtering."""
domains = [
"example.com",
"enterprise.local",
"company.org",
"test.io",
"api.net",
"corp.example",
"internal.local",
"dev.company",
"prod.enterprise",
]
return draw(st.sampled_from(domains))
@composite
def enterprise_usernames(draw: Callable[..., Any]) -> str:
"""Generate valid enterprise usernames without filtering."""
usernames = [
"admin",
"user123",
"service01",
"ldapuser",
"apiuser",
"testuser",
"devuser",
"produser",
"syncuser",
"manager",
"operator",
"analyst",
"developer",
"qa",
"support",
]
return draw(st.sampled_from(usernames))
@composite
def api_service_names(draw: Callable[..., Any]) -> str:
"""Generate valid API service names without filtering."""
services = [
"auth",
"users",
"orders",
"payments",
"inventory",
"catalog",
"analytics",
"reporting",
"notifications",
"audit",
"billing",
"shipping",
"search",
"recommendations",
"reviews",
"chat",
]
return draw(st.sampled_from(services))
@composite
def http_header_names(draw: Callable[..., Any]) -> str:
"""Generate valid HTTP header names without filtering."""
headers = [
"Content-Type",
"Authorization",
"User-Agent",
"Accept",
"Accept-Language",
"Cache-Control",
"Connection",
"Host",
"X-API-Key",
"X-Custom-Header",
"X-Request-ID",
"X-Forwarded-For",
"X-Session-ID",
"X-Correlation-ID",
"X-Client-Version",
]
return draw(st.sampled_from(headers))
@composite
def safe_urls(draw: Callable[..., Any]) -> str:
"""Generate safe HTTPS URLs without filtering."""
domains = [
"api.github.com",
"httpbin.org",
"jsonplaceholder.typicode.com",
"api.stripe.com",
"api.twitter.com",
"graph.microsoft.com",
"api.slack.com",
"api.dropbox.com",
"api.zoom.us",
]
paths = [
"",
"v1/users",
"api/data",
"rest/auth",
"graphql",
"webhooks",
"oauth/token",
"status",
"health",
"metrics",
]
domain = draw(st.sampled_from(domains))
path = draw(st.sampled_from(paths))
return f"https://{domain}/{path}".rstrip("/")
@composite
def api_versions(draw: Callable[..., Any]) -> str:
"""Generate valid API versions without filtering."""
versions = ["v1", "v2", "v3", "1.0", "2.0", "3.0", "latest", "stable", "beta"]
return draw(st.sampled_from(versions))
@composite
def enterprise_base_dns(draw: Callable[..., Any]) -> str:
"""Generate valid LDAP base DNs without filtering."""
base_dns = [
"dc=example,dc=com",
"dc=enterprise,dc=local",
"dc=company,dc=org",
"ou=users,dc=example,dc=com",
"ou=groups,dc=enterprise,dc=local",
"ou=departments,dc=company,dc=org",
"cn=admin,dc=test,dc=io",
]
return draw(st.sampled_from(base_dns))
@composite
def certificate_paths(draw: Callable[..., Any]) -> str:
"""Generate valid certificate paths without filtering."""
paths = [
"/etc/ssl/certs/client.pem",
"/opt/certs/ldap.crt",
"/var/ssl/auth.pem",
"/usr/local/ssl/enterprise.crt",
"/home/user/.ssl/client.key",
"/etc/pki/tls/private/server.key",
]
return draw(st.sampled_from(paths))
@composite
def auth_methods(draw: Callable[..., Any]) -> str:
"""Generate valid authentication methods without filtering."""
methods = [
"simple_bind",
"sasl",
"certificate",
"token",
"api_key",
"oauth2",
"jwt",
"basic",
"digest",
"kerberos",
]
return draw(st.sampled_from(methods))
@composite
def sync_types(draw: Callable[..., Any]) -> str:
"""Generate valid sync types without filtering."""
types = ["full", "incremental", "delta", "partial", "selective"]
return draw(st.sampled_from(types))
@composite
def enterprise_entity_lists(draw: Callable[..., Any]) -> list[str]:
"""Generate valid entity lists without filtering."""
entity_sets = [
["users", "groups"],
["employees"],
["contacts", "departments"],
["accounts"],
["users", "roles", "permissions"],
["devices"],
["applications", "services"],
["policies", "rules"],
]
return draw(st.sampled_from(entity_sets))
@composite
def property_test_timeouts(draw: Callable[..., Any]) -> int:
"""Generate valid timeout values for property tests."""
timeouts = [5, 10, 15, 20, 30, 45, 60, 90, 120, 180, 300]
return draw(st.sampled_from(timeouts))
@composite
def property_test_batch_sizes(draw: Callable[..., Any]) -> int:
"""Generate valid batch sizes for property tests."""
sizes = [10, 25, 50, 100, 250, 500, 1000]
return draw(st.sampled_from(sizes))
# User identity strategies
@composite
def user_identification_contexts(draw: Callable[..., Any]) -> dict[str, Any]:
"""Generate valid user identification contexts without filtering."""
contexts = [
{"method": "username", "domain": "local"},
{"method": "email", "domain": "example.com"},
{"method": "id", "system": "ldap"},
{"method": "token", "provider": "sso"},
{"method": "certificate", "authority": "internal"},
]
return draw(st.sampled_from(contexts))
@composite
def authentication_inputs(draw: Callable[..., Any]) -> dict[str, Any]:
"""Generate valid authentication inputs without filtering."""
inputs = [
{"username": "testuser", "password": "password123"},
{"email": "user@example.com", "password": "securepass"},
{"token": "jwt.token.signature", "type": "bearer"},
{"api_key": "key_12345", "secret": "secret_67890"},
{"certificate": "cert.pem", "private_key": "key.pem"},
]
return draw(st.sampled_from(inputs))
# Knowledge management strategies
@composite
def documentation_configs(draw: Callable[..., Any]) -> dict[str, Any]:
"""Generate valid documentation configurations without filtering."""
configs = [
{"format": "markdown", "template": "standard"},
{"format": "html", "template": "enterprise"},
{"format": "pdf", "template": "report"},
{"format": "json", "template": "api"},
{"format": "xml", "template": "structured"},
]
return draw(st.sampled_from(configs))
@composite
def search_queries(draw: Callable[..., Any]) -> str:
"""Generate valid search queries without filtering."""
queries = [
"user management",
"api documentation",
"security policies",
"deployment guide",
"troubleshooting",
"configuration",
"integration",
"authentication",
"monitoring",
"backup",
]
return draw(st.sampled_from(queries))
@composite
def content_quality_scores(draw: Callable[..., Any]) -> float:
"""Generate valid content quality scores without filtering."""
scores = [0.1, 0.25, 0.5, 0.75, 0.8, 0.85, 0.9, 0.95, 1.0]
return draw(st.sampled_from(scores))