class CeleryConfigMixin: _CELERY_BACKENDS = ["ampq", "redis"] CELERY_BROKER_BACKEND = props.Choice(default="ampq", choices=_CELERY_BACKENDS) CELERY_RESULTS_BACKEND = props.Choice(default="ampq", choices=_CELERY_BACKENDS) CELERY_REDIS_DATABASE_ID = props.String(default="0")
class PostgresConfigMixin: TEST_DB_URL = props.String(default="sqlite:///:memory:") DB_DRIVER = props.String(default="postgres") DB_HOST = props.String(default="localhost") DB_PORT = props.Int(default=5432) DB_USER = props.String(default="postgres") DB_PASS = props.String(default="postgres") DB_NAME = props.String(default="postgres")
class CreateItemSchema: name = props.String(min_length=3, max_length=32)
def test_fields(): config = make_config(thing=props.Int(), other=props.String()) assert hasattr(config, "THING") assert hasattr(config, "OTHER")
class RedisConfigMixin: REDIS_DRIVER = props.String(default="redis") REDIS_HOST = props.String(default="localhost") REDIS_PORT = props.Int(default=6379) REDIS_PASS = props.String(nullable=True)
class RabbitConfigMixin: RABBIT_DRIVER = props.String(default="ampq") RABBIT_HOST = props.String(default="localhost") RABBIT_PORT = props.Int(default=5672) RABBIT_USER = props.String(default="guest") RABBIT_PASS = props.String(default="guest")
def test_nullable(): props.String(nullable=True).load(None)
def test_not_nullable(): with pytest.raises(props.PropertyValidationError): props.String().load(None)
class ModelB(props.Model): x = props.String()
def test_too_long(): with pytest.raises(props.PropertyValidationError): props.String(max_length=2).load("123")
def test_too_short(): with pytest.raises(props.PropertyValidationError): props.String(min_length=10).load("123")
def test_default(): assert props.String(default="12345").load(None) == "12345"
def test_wrong_type(): with pytest.raises(props.PropertyValidationError): props.String().load(12345)