Esempio n. 1
0
async def test_error_on_missing_type_in_model(swagger_dict, sample_model,
                                              http_client):
    register_spec(swagger_dict)
    sample_model["schools"][0] = {}  # Omit 'name'
    register_get("http://localhost/test_http", body=json.dumps(sample_model))
    client = await swagger_client(http_client)
    with pytest.raises(ValidationError) as excinfo:
        await client.api_test.testHTTP().result()
    assert "'name' is a required property" in str(excinfo.value)
Esempio n. 2
0
async def test_additionalProperty_in_model_in_response(swagger_dict,
                                                       sample_model,
                                                       http_client):
    register_spec(swagger_dict)
    sample_model["extra"] = 42
    register_get("http://localhost/test_http", body=json.dumps(sample_model))
    client = await swagger_client(http_client)
    result = await client.api_test.testHTTP().result()
    assert result.extra == 42
Esempio n. 3
0
async def test_model_missing_required_property_in_response_raises_ValidationError(
        swagger_dict, sample_model, http_client):
    register_spec(swagger_dict)
    sample_model.pop("id")
    register_get("http://localhost/test_http", body=json.dumps(sample_model))
    client = await swagger_client(http_client)
    with pytest.raises(ValidationError) as excinfo:
        await client.api_test.testHTTP().result()
    assert "'id' is a required property" in str(excinfo.value)
Esempio n. 4
0
async def test_error_on_wrong_type_inside_complex_type(swagger_dict,
                                                       sample_model,
                                                       http_client):
    register_spec(swagger_dict)
    sample_model["id"] = "Not Integer"
    register_get("http://localhost/test_http", body=json.dumps(sample_model))
    client = await swagger_client(http_client)
    with pytest.raises(ValidationError) as excinfo:
        await client.api_test.testHTTP().result()
    assert "'Not Integer' is not of type" in str(excinfo.value)
Esempio n. 5
0
async def test_array_in_response(swagger_dict, http_client):
    response_spec = {
        'type': 'array',
        'items': {
            'type': 'string',
        },
    }
    register_spec(swagger_dict, response_spec)
    expected_array = ['inky', 'dinky', 'doo']
    register_test_http(body=json.dumps(expected_array))
    await assert_result(expected_array, http_client)
Esempio n. 6
0
async def test_model_in_response(swagger_dict, sample_model, spec_type,
                                 http_client):
    register_spec(swagger_dict, spec_type=spec_type)
    register_get("http://localhost/test_http", body=json.dumps(sample_model))
    client = await swagger_client(http_client)
    result = await client.api_test.testHTTP().result()
    User = client.get_model('User')
    School = client.get_model('School')
    assert isinstance(result, User)
    for school in result.schools:
        assert isinstance(school, School)
    assert User(id=42,
                schools=[School(name="School1"),
                         School(name="School2")]) == result
Esempio n. 7
0
async def test_date_format_in_reponse(swagger_dict, http_client):
    response_spec = {'type': 'string', 'format': 'date'}
    register_spec(swagger_dict, response_spec)
    register_test_http(body=json.dumps("2014-06-10"))
    await assert_result(datetime.date(2014, 6, 10), http_client)
Esempio n. 8
0
async def test_invalid_primitive_types_in_response_raises_ValidationError(
        rtype, rvalue, swagger_dict, http_client):
    register_spec(swagger_dict, {'type': rtype})
    register_test_http(body=json.dumps(rvalue))
    await assert_raises_and_matches(ValidationError, "is not of type '{}'".format(rtype), http_client)
Esempio n. 9
0
async def test_primitive_types_returned_in_response(rtype, rvalue, swagger_dict, http_client):
    register_spec(swagger_dict, {'type': rtype})
    register_test_http(body=json.dumps(rvalue))
    await assert_result(rvalue, http_client)