Example #1
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")
Example #2
0
def test_validates_request_json():
    @request_schema(
        json=props.Inline(props=dict(q=props.String, i=props.Int(nullable=True)))
    )
    def mock_route(json):
        return json

    with patch_request(json=dict(q="hello")):
        parsed_json = mock_route()

    assert parsed_json == {"i": None, "q": "hello"}
Example #3
0
def test_validates_request_query():
    @request_schema(
        query=props.Inline(props=dict(q=props.String, i=props.Int(nullable=True)))
    )
    def mock_route(query):
        return query

    with patch_request(query=dict(q="hello")):
        parsed_query = mock_route()

    assert parsed_query == {"i": None, "q": "hello"}
Example #4
0
def test_validates_request_form():
    @request_schema(
        form=props.Inline(props=dict(q=props.String, i=props.Int(nullable=True)))
    )
    def mock_route(form):
        return form

    with patch_request(form=dict(q="hello")):
        parsed_form = mock_route()

    assert parsed_form == {"i": None, "q": "hello"}
Example #5
0
def test_nullable():
    props.Int(nullable=True).load(None)
Example #6
0
def test_loads_int_from_string():
    assert props.Int().load("5") == 5
Example #7
0
 class ModelA(props.Model):
     x = props.Int()
Example #8
0
def test_default():
    assert props.Int(default=123).load(None) == 123
Example #9
0
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)
Example #10
0
def test_fields():
    config = make_config(thing=props.Int(), other=props.String())
    assert hasattr(config, "THING")
    assert hasattr(config, "OTHER")
Example #11
0
def test_too_high():
    with pytest.raises(props.PropertyValidationError):
        props.Int(max_value=10).load(20)
Example #12
0
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")
Example #13
0
def test_too_low():
    with pytest.raises(props.PropertyValidationError):
        props.Int(min_value=10).load(5)
Example #14
0
def test_rejects_float():
    with pytest.raises(props.PropertyValidationError):
        assert props.Int().load(5.5)
Example #15
0
def test_accepts_int():
    assert props.Int().load(5) == 5
Example #16
0
def test_not_allow_strings():
    with pytest.raises(props.PropertyValidationError):
        assert props.Int(allow_strings=False).load("5") == 5
Example #17
0
def test_rejects_float_from_string():
    with pytest.raises(props.PropertyValidationError):
        props.Int().load("5.5")
Example #18
0
def test_not_nullable():
    with pytest.raises(props.PropertyValidationError):
        props.Int().load(None)
Example #19
0
def test_validate():
    props.Int().load(5)
Example #20
0
 class MyConfig(ServiceConfig):
     SOME_THING = props.Int()
Example #21
0
def test_wrong_type():
    with pytest.raises(props.PropertyValidationError):
        props.Int().load("nope")
Example #22
0
 class MyModel(props.Model):
     x = props.Int()
     _y = props.Int()
Example #23
0
 class ModelB(props.Model):
     x = props.Int(min_value=5, max_value=11)