예제 #1
0
def test_200_for_normal_response_validation():
    app = build_test_app(
        swagger_versions=['1.2'],
        **{'pyramid_swagger.enable_response_validation': True}
    )
    response = app.post_json('/sample', {'foo': 'test', 'bar': 'test'})
    assert response.status_code == 200
예제 #2
0
def test_error_handling_for_12():
    app = build_test_app(
        swagger_versions=['1.2'],
        **{'pyramid_swagger.enable_response_validation': True}
    )
    # Should throw 400 and not 500 (500 is thrown by pyramid_swagger when
    # response_validation is True and response format does not match the
    # type specified by the operation's swagger spec. But that match should
    # be done only when the response status is 200...203)
    assert app.get('/throw_400', expect_errors=True).status_code == 400
예제 #3
0
def test_app_error_if_path_not_in_spec_and_path_validation_disabled():
    """If path missing and validation is disabled we want to let something else
    handle the error. TestApp throws an AppError, but Pyramid would throw a
    HTTPNotFound exception.
    """
    with pytest.raises(AppError):
        assert build_test_app(
            swagger_versions=['2.0'],
            **{'pyramid_swagger.enable_path_validation': False}
        ).get('/this/path/doesnt/exist')
예제 #4
0
def test_app_error_if_path_not_in_spec_and_path_validation_disabled():
    """If path missing and validation is disabled we want to let something else
    handle the error. TestApp throws an AppError, but Pyramid would throw a
    HTTPNotFound exception.
    """
    with pytest.raises(AppError):
        app = build_test_app(
            swagger_versions=['1.2'],
            **{'pyramid_swagger.enable_path_validation': False}
        )
        assert app.get('/this/path/doesnt/exist')
예제 #5
0
def test_200_skip_validation_for_excluded_path():
    # FIXME(#64): This test is broken and doesn't check anything.
    app = build_test_app(
        swagger_versions=['1.2'],
        **{'pyramid_swagger.exclude_paths': [r'^/sample/?']}
    )
    response = app.get(
        '/sample/path_arg1/resource',
        params={'required_arg': 'test'}
    )
    assert response.status_code == 200