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