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