Пример #1
0
async def test_validator(aiohttp_client):
    """Test the validator."""
    client = await get_client(
        aiohttp_client,
        RequestDataValidator(vol.Schema({vol.Required("test"): str})))

    resp = await client.post("/", json={"test": "bla"})
    assert resp.status == 200

    resp = await client.post("/", json={"test": 100})
    assert resp.status == 400

    resp = await client.post("/")
    assert resp.status == 400
Пример #2
0
async def test_validator(test_client):
    """Test the validator."""
    client = await get_client(
        test_client,
        RequestDataValidator(vol.Schema({vol.Required('test'): str})))

    resp = await client.post('/', json={'test': 'bla'})
    assert resp.status == 200

    resp = await client.post('/', json={'test': 100})
    assert resp.status == 400

    resp = await client.post('/')
    assert resp.status == 400
Пример #3
0
async def test_validator_allow_empty(test_client):
    """Test the validator with empty data."""
    client = await get_client(
        test_client,
        RequestDataValidator(
            vol.Schema({
                # Although we allow empty, our schema should still be able
                # to validate an empty dict.
                vol.Optional('test'):
                str
            }),
            allow_empty=True))

    resp = await client.post('/', json={'test': 'bla'})
    assert resp.status == 200

    resp = await client.post('/', json={'test': 100})
    assert resp.status == 400

    resp = await client.post('/')
    assert resp.status == 200
Пример #4
0
async def test_validator_allow_empty(aiohttp_client):
    """Test the validator with empty data."""
    client = await get_client(
        aiohttp_client,
        RequestDataValidator(
            vol.Schema({
                # Although we allow empty, our schema should still be able
                # to validate an empty dict.
                vol.Optional("test"):
                str
            }),
            allow_empty=True,
        ),
    )

    resp = await client.post("/", json={"test": "bla"})
    assert resp.status == 200

    resp = await client.post("/", json={"test": 100})
    assert resp.status == 400

    resp = await client.post("/")
    assert resp.status == 200